File: eth_switch.h

package info (click to toggle)
dynamips 0.2.7-0.2.8RC2-2
  • links: PTS
  • area: non-free
  • in suites: lenny
  • size: 3,840 kB
  • ctags: 9,893
  • sloc: ansic: 69,846; makefile: 239; sh: 124; perl: 20
file content (120 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Cisco router simulation platform.
 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
 *
 * Virtual Ethernet switch definitions.
 */

#ifndef __ETH_SWITCH_H__
#define __ETH_SWITCH_H__

#include <pthread.h>

#include "utils.h"
#include "net.h"
#include "net_io.h"

/* Hash entries for the MAC address table */
#define ETHSW_HASH_SIZE  4096

/* Maximum port number */
#define ETHSW_MAX_NIO    64

/* Maximum packet size */
#define ETHSW_MAX_PKT_SIZE  2048

/* Port types: access or 802.1Q */
enum {
   ETHSW_PORT_TYPE_ACCESS = 1,
   ETHSW_PORT_TYPE_DOT1Q,
   ETHSW_PORT_TYPE_ISL,
};

/* Received packet */
typedef struct ethsw_packet ethsw_packet_t;
struct ethsw_packet {
   u_char *pkt;
   ssize_t pkt_len;
   netio_desc_t *input_port;
   u_int input_vlan;
   int input_tag;
};

/* MAC address table entry */
typedef struct ethsw_mac_entry ethsw_mac_entry_t;
struct ethsw_mac_entry {
   netio_desc_t *nio;
   n_eth_addr_t mac_addr;
   m_uint16_t vlan_id;
};

/* Virtual Ethernet switch */
typedef struct ethsw_table ethsw_table_t;
struct ethsw_table {
   char *name;
   pthread_mutex_t lock;
   int debug;
   
   /* Virtual Ports */
   netio_desc_t *nio[ETHSW_MAX_NIO];

   /* MAC address table */
   ethsw_mac_entry_t mac_addr_table[ETHSW_HASH_SIZE];
};

/* Packet input vector */
typedef void (*ethsw_input_vector_t)(ethsw_table_t *t,ethsw_packet_t *sp,
                                     netio_desc_t *output_port);

/* "foreach" vector */
typedef void (*ethsw_foreach_entry_t)(ethsw_table_t *t,
                                      ethsw_mac_entry_t *entry,
                                      void *opt);

#define ETHSW_LOCK(t)   pthread_mutex_lock(&(t)->lock)
#define ETHSW_UNLOCK(t) pthread_mutex_unlock(&(t)->lock)

/* Acquire a reference to an Ethernet switch (increment reference count) */
ethsw_table_t *ethsw_acquire(char *name);

/* Release an Ethernet switch (decrement reference count) */
int ethsw_release(char *name);

/* Create a virtual ethernet switch */
ethsw_table_t *ethsw_create(char *name);

/* Add a NetIO descriptor to a virtual ethernet switch */
int ethsw_add_netio(ethsw_table_t *t,char *nio_name);

/* Remove a NetIO descriptor from a virtual ethernet switch */
int ethsw_remove_netio(ethsw_table_t *t,char *nio_name);

/* Clear the MAC address table */
int ethsw_clear_mac_addr_table(ethsw_table_t *t);

/* Iterate over all entries of the MAC address table */
int ethsw_iterate_mac_addr_table(ethsw_table_t *t,ethsw_foreach_entry_t cb,
                                 void *opt_arg);

/* Set port as an access port */
int ethsw_set_access_port(ethsw_table_t *t,char *nio_name,u_int vlan_id);

/* Set port as a 802.1q trunk port */
int ethsw_set_dot1q_port(ethsw_table_t *t,char *nio_name,u_int native_vlan);

/* Save the configuration of a switch */
void ethsw_save_config(ethsw_table_t *t,FILE *fd);

/* Save configurations of all Ethernet switches */
void ethsw_save_config_all(FILE *fd);

/* Delete a virtual ethernet switch */
int ethsw_delete(char *name);

/* Delete all virtual ethernet switches */
int ethsw_delete_all(void);

/* Start a virtual Ethernet switch */
int ethsw_start(char *filename);

#endif