/[dynamips]/upstream/dynamips-0.2.6-RC3/eth_switch.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/dynamips-0.2.6-RC3/eth_switch.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Oct 6 16:06:49 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 3165 byte(s)
dynamips-0.2.6-RC3

1 dpavlin 1 /*
2     * Cisco 7200 (Predator) simulation platform.
3     * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4     *
5     * Virtual Ethernet switch definitions.
6     */
7    
8     #ifndef __ETH_SWITCH_H__
9     #define __ETH_SWITCH_H__
10    
11     #include <pthread.h>
12    
13     #include "utils.h"
14     #include "net.h"
15     #include "net_io.h"
16    
17     /* Hash entries for the MAC address table */
18     #define ETHSW_HASH_SIZE 4096
19    
20     /* Maximum port number */
21     #define ETHSW_MAX_NIO 64
22    
23     /* Maximum packet size */
24     #define ETHSW_MAX_PKT_SIZE 2048
25    
26     /* Port types: access or 802.1Q */
27     enum {
28     ETHSW_PORT_TYPE_ACCESS = 1,
29     ETHSW_PORT_TYPE_DOT1Q,
30     ETHSW_PORT_TYPE_ISL,
31     };
32    
33     /* Received packet */
34     typedef struct ethsw_packet ethsw_packet_t;
35     struct ethsw_packet {
36     u_char *pkt;
37     ssize_t pkt_len;
38     netio_desc_t *input_port;
39     u_int input_vlan;
40     int input_tag;
41     };
42    
43     /* MAC address table entry */
44     typedef struct ethsw_mac_entry ethsw_mac_entry_t;
45     struct ethsw_mac_entry {
46     netio_desc_t *nio;
47     n_eth_addr_t mac_addr;
48     m_uint16_t vlan_id;
49     };
50    
51     /* Virtual Ethernet switch */
52     typedef struct ethsw_table ethsw_table_t;
53     struct ethsw_table {
54     char *name;
55     pthread_mutex_t lock;
56     int debug;
57    
58     /* Virtual Ports */
59     netio_desc_t *nio[ETHSW_MAX_NIO];
60    
61     /* MAC address table */
62     ethsw_mac_entry_t mac_addr_table[ETHSW_HASH_SIZE];
63     };
64    
65     /* Packet input vector */
66     typedef void (*ethsw_input_vector_t)(ethsw_table_t *t,ethsw_packet_t *sp,
67     netio_desc_t *output_port);
68    
69     /* "foreach" vector */
70     typedef void (*ethsw_foreach_entry_t)(ethsw_table_t *t,
71     ethsw_mac_entry_t *entry,
72     void *opt);
73    
74     #define ETHSW_LOCK(t) pthread_mutex_lock(&(t)->lock)
75     #define ETHSW_UNLOCK(t) pthread_mutex_unlock(&(t)->lock)
76    
77     /* Acquire a reference to an Ethernet switch (increment reference count) */
78     ethsw_table_t *ethsw_acquire(char *name);
79    
80     /* Release an Ethernet switch (decrement reference count) */
81     int ethsw_release(char *name);
82    
83     /* Create a virtual ethernet switch */
84     ethsw_table_t *ethsw_create(char *name);
85    
86     /* Add a NetIO descriptor to a virtual ethernet switch */
87     int ethsw_add_netio(ethsw_table_t *t,char *nio_name);
88    
89     /* Remove a NetIO descriptor from a virtual ethernet switch */
90     int ethsw_remove_netio(ethsw_table_t *t,char *nio_name);
91    
92     /* Clear the MAC address table */
93     int ethsw_clear_mac_addr_table(ethsw_table_t *t);
94    
95     /* Iterate over all entries of the MAC address table */
96     int ethsw_iterate_mac_addr_table(ethsw_table_t *t,ethsw_foreach_entry_t cb,
97     void *opt_arg);
98    
99     /* Set port as an access port */
100     int ethsw_set_access_port(ethsw_table_t *t,char *nio_name,u_int vlan_id);
101    
102     /* Set port as a 802.1q trunk port */
103     int ethsw_set_dot1q_port(ethsw_table_t *t,char *nio_name,u_int native_vlan);
104    
105     /* Save the configuration of a switch */
106     void ethsw_save_config(ethsw_table_t *t,FILE *fd);
107    
108     /* Save configurations of all Ethernet switches */
109     void ethsw_save_config_all(FILE *fd);
110    
111     /* Delete a virtual ethernet switch */
112     int ethsw_delete(char *name);
113    
114     /* Delete all virtual ethernet switches */
115     int ethsw_delete_all(void);
116    
117     /* Start a virtual Ethernet switch */
118     int ethsw_start(char *filename);
119    
120     #endif

  ViewVC Help
Powered by ViewVC 1.1.26