| 1 |
/* |
| 2 |
* Cisco router simulation platform. |
| 3 |
* Copyright (c) 2005,2006 Christophe Fillot ([email protected]) |
| 4 |
* |
| 5 |
* ATM definitions. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef __ATM_H__ |
| 9 |
#define __ATM_H__ |
| 10 |
|
| 11 |
#include <pthread.h> |
| 12 |
|
| 13 |
#include "utils.h" |
| 14 |
#include "mempool.h" |
| 15 |
#include "net_io.h" |
| 16 |
|
| 17 |
/* ATM payload size */ |
| 18 |
#define ATM_HDR_SIZE 5 |
| 19 |
#define ATM_PAYLOAD_SIZE 48 |
| 20 |
#define ATM_CELL_SIZE (ATM_HDR_SIZE + ATM_PAYLOAD_SIZE) |
| 21 |
#define ATM_AAL5_TRAILER_SIZE 8 |
| 22 |
#define ATM_AAL5_TRAILER_POS (ATM_CELL_SIZE - ATM_AAL5_TRAILER_SIZE) |
| 23 |
|
| 24 |
/* ATM header structure */ |
| 25 |
#define ATM_HDR_VPI_MASK 0xFFF00000 |
| 26 |
#define ATM_HDR_VPI_SHIFT 20 |
| 27 |
#define ATM_HDR_VCI_MASK 0x000FFFF0 |
| 28 |
#define ATM_HDR_VCI_SHIFT 4 |
| 29 |
#define ATM_HDR_PTI_MASK 0x0000000E |
| 30 |
#define ATM_HDR_PTI_SHIFT 1 |
| 31 |
|
| 32 |
/* PTI bits */ |
| 33 |
#define ATM_PTI_EOP 0x00000002 /* End of packet */ |
| 34 |
#define ATM_PTI_CONGESTION 0x00000004 /* Congestion detected */ |
| 35 |
#define ATM_PTI_NETWORK 0x00000008 /* Network traffic */ |
| 36 |
|
| 37 |
/* VP-level switch table */ |
| 38 |
typedef struct atmsw_vp_conn atmsw_vp_conn_t; |
| 39 |
struct atmsw_vp_conn { |
| 40 |
atmsw_vp_conn_t *next; |
| 41 |
netio_desc_t *input,*output; |
| 42 |
u_int vpi_in,vpi_out; |
| 43 |
m_uint64_t cell_cnt; |
| 44 |
}; |
| 45 |
|
| 46 |
/* VC-level switch table */ |
| 47 |
typedef struct atmsw_vc_conn atmsw_vc_conn_t; |
| 48 |
struct atmsw_vc_conn { |
| 49 |
atmsw_vc_conn_t *next; |
| 50 |
netio_desc_t *input,*output; |
| 51 |
u_int vpi_in,vci_in; |
| 52 |
u_int vpi_out,vci_out; |
| 53 |
m_uint64_t cell_cnt; |
| 54 |
}; |
| 55 |
|
| 56 |
/* Virtual ATM switch table */ |
| 57 |
#define ATMSW_NIO_MAX 32 |
| 58 |
#define ATMSW_VP_HASH_SIZE 256 |
| 59 |
#define ATMSW_VC_HASH_SIZE 1024 |
| 60 |
|
| 61 |
typedef struct atmsw_table atmsw_table_t; |
| 62 |
struct atmsw_table { |
| 63 |
char *name; |
| 64 |
pthread_mutex_t lock; |
| 65 |
mempool_t mp; |
| 66 |
m_uint64_t cell_drop; |
| 67 |
atmsw_vp_conn_t *vp_table[ATMSW_VP_HASH_SIZE]; |
| 68 |
atmsw_vc_conn_t *vc_table[ATMSW_VC_HASH_SIZE]; |
| 69 |
}; |
| 70 |
|
| 71 |
#define ATMSW_LOCK(t) pthread_mutex_lock(&(t)->lock) |
| 72 |
#define ATMSW_UNLOCK(t) pthread_mutex_unlock(&(t)->lock) |
| 73 |
|
| 74 |
/* RFC1483 bridged mode header */ |
| 75 |
#define ATM_RFC1483B_HLEN 10 |
| 76 |
extern m_uint8_t atm_rfc1483b_header[ATM_RFC1483B_HLEN]; |
| 77 |
|
| 78 |
/* Compute HEC field for ATM header */ |
| 79 |
m_uint8_t atm_compute_hec(m_uint8_t *cell_header); |
| 80 |
|
| 81 |
/* Insert HEC field into an ATM header */ |
| 82 |
void atm_insert_hec(m_uint8_t *cell_header); |
| 83 |
|
| 84 |
/* Update the CRC on the data block one byte at a time */ |
| 85 |
m_uint32_t atm_update_crc(m_uint32_t crc_accum,m_uint8_t *ptr,int len); |
| 86 |
|
| 87 |
/* Initialize ATM code (for HEC checksums) */ |
| 88 |
void atm_init(void); |
| 89 |
|
| 90 |
/* Acquire a reference to an ATM switch (increment reference count) */ |
| 91 |
atmsw_table_t *atmsw_acquire(char *name); |
| 92 |
|
| 93 |
/* Release an ATM switch (decrement reference count) */ |
| 94 |
int atmsw_release(char *name); |
| 95 |
|
| 96 |
/* Create a virtual switch table */ |
| 97 |
atmsw_table_t *atmsw_create_table(char *name); |
| 98 |
|
| 99 |
/* Create a VP switch connection */ |
| 100 |
int atmsw_create_vpc(atmsw_table_t *t,char *nio_input,u_int vpi_in, |
| 101 |
char *nio_output,u_int vpi_out); |
| 102 |
|
| 103 |
/* Delete a VP switch connection */ |
| 104 |
int atmsw_delete_vpc(atmsw_table_t *t,char *nio_input,u_int vpi_in, |
| 105 |
char *nio_output,u_int vpi_out); |
| 106 |
|
| 107 |
/* Create a VC switch connection */ |
| 108 |
int atmsw_create_vcc(atmsw_table_t *t, |
| 109 |
char *input,u_int vpi_in,u_int vci_in, |
| 110 |
char *output,u_int vpi_out,u_int vci_out); |
| 111 |
|
| 112 |
/* Delete a VC switch connection */ |
| 113 |
int atmsw_delete_vcc(atmsw_table_t *t, |
| 114 |
char *nio_input,u_int vpi_in,u_int vci_in, |
| 115 |
char *nio_output,u_int vpi_out,u_int vci_out); |
| 116 |
|
| 117 |
/* Save the configuration of an ATM switch */ |
| 118 |
void atmsw_save_config(atmsw_table_t *t,FILE *fd); |
| 119 |
|
| 120 |
/* Save configurations of all ATM switches */ |
| 121 |
void atmsw_save_config_all(FILE *fd); |
| 122 |
|
| 123 |
/* Delete an ATM switch */ |
| 124 |
int atmsw_delete(char *name); |
| 125 |
|
| 126 |
/* Delete all ATM switches */ |
| 127 |
int atmsw_delete_all(void); |
| 128 |
|
| 129 |
/* Start a virtual ATM switch */ |
| 130 |
int atmsw_start(char *filename); |
| 131 |
|
| 132 |
#endif |