NetSim Source Code Help
Loading...
Searching...
No Matches
Ethernet.h
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24
25#ifndef _NETSIM_ETHERNET_H_
26#define _NETSIM_ETHERNET_H_
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#pragma comment(lib,"NetworkStack.lib")
32#pragma comment(lib,"Metrics.lib")
33
34#define isETHConfigured(d,i) (DEVICE_MACLAYER(d,i)->nMacProtocolId == MAC_PROTOCOL_IEEE802_3)
35 //Global variable
37
38#define ETH_IFG 0.960 //Micro sec
39
40 typedef enum enum_eth_packet
41 {
44
45 /** Enumeration for Switching Technique */
47 {
53
54 /** Enumeration for SWITCH Port state*/
55 typedef enum enum_PortState
56 {
63
64 typedef enum enum_port_type
65 {
70
71
72 //Typedefs
74
75#define ETH_HDR_CBPDU 1
76#define ETH_HDR_VID 2
77#define ETH_HDR_NW 3
78 typedef struct stru_eth_packet
79 {
81 void* var;
82 void* (*fncopy)(void*);
83 void(*fnfree)(void*);
85 void set_eth_hdr(NetSim_PACKET* packet, UINT type, void* var, void*(fncopy)(void*), void(*fnfree)(void*));
88
89 typedef struct stru_eth_bpdu
90 {
95 char* rootId;
97 char* bridgeId;
104#define ETH_BPDU_LEN 60 //Bytes (35 SPT+ 22 Ethernet + 3 LLC)
105
106 typedef struct ieee802_1q_tag
107 {
111 UINT VID : 12;
113#define IEEE801_1Q_TAG_LEN 4 //Bytes
114#define VLAN_TPID 0x8100
115 bool isVLANTagPresent(NetSim_PACKET* packet);
116
117 typedef struct stru_SwitchTable
118 {
124#define SWITCHTABLE_ALLOC() (ptrSWITCHTABLE)list_alloc(sizeof(SWITCHTABLE),offsetof(SWITCHTABLE,ele))
125#define SWITCHTABLE_ADD(l,m) LIST_ADD_LAST((void**)(l),m)
126#define SWITCHTABLE_NEXT(t) t=(ptrSWITCHTABLE)LIST_NEXT(t)
127#define SWITCHTABLE_GET(d,in) (GET_ETH_LAN(d,in,0)->switchTable)
128#define SWITCHTABLE_GET_LAN(lan) (lan->switchTable)
131 void switchtable_metrics_print(PMETRICSWRITER metricsWriter);
132
133 typedef enum
134 {
138 }VLANPORT;
140
142 {
150
151 typedef struct stru_ethernet_spt
152 {
156 char* switchId;
157
158 char* rootId;
161
163
165 {
169 NETSIM_IPAddress lanIP; // For layer 3 or above device
171
173
175
176 //Only for switch
178 double latency;
181
183 double speed;
184
186 };
188
189 typedef struct stru_ethernet_var
190 {
194
195 bool isSPT;
196
198
199 bool isVLAN;
202
208
209 typedef struct stru_eth_phy
210 {
212 double speed;
213 double BER;
217 double IFG;
218
221
224#define ETH_PHY_GET(d,i) ((ptrETH_PHY)DEVICE_PHYLAYER(d,i)->phyVar)
225
226 //Spanning Tree
229 void process_configbpdu();
230
231 //VLAN
234 NetSim_PACKET* packet,
235 ptrETH_LAN lan,
236 double time);
238 NETSIM_ID in,
239 UINT16 vlanId,
240 NETSIM_ID incoming,
241 NetSim_PACKET* packet,
242 double time);
244
245 // MAC
248 NETSIM_ID in,
249 ptrETH_LAN lan,
250 NetSim_PACKET* packet,
251 double time);
253 NETSIM_ID in,
254 ptrETH_LAN lan,
255 NetSim_PACKET* packet,
256 double time);
257 void send_to_phy(NETSIM_ID d, NETSIM_ID in, NetSim_PACKET* packet, double time);
258
259 //Ethernet utility function
261 void print_ethernet_log(char* format, ...);
262 void print_spanning_tree();
264 void store_eth_incoming(NetSim_PACKET* packet, NETSIM_ID devId, NETSIM_ID incomingPort, UINT16 vlanId);
268
269#ifdef __cplusplus
270}
271#endif
272#endif //_NETSIM_ETHERNET_H_
void send_to_phy()
Definition: CSMACDMac.c:31
unsigned int NETSIM_ID
Definition: Animation.h:45
struct stru_eth_packet * ptrETH_HDR
struct stru_ethernet_lan * ptrETH_LAN
Definition: Ethernet.h:73
void store_eth_param_macin(NetSim_PACKET *packet, NETSIM_ID devId, NETSIM_ID in, ptrETH_LAN lan)
void check_move_frame_up(NETSIM_ID d, NETSIM_ID in, ptrETH_LAN lan, NetSim_PACKET *packet, double time)
Definition: Ethernet_Mac.c:187
struct stru_ethernet_spt * ptrETH_SPT
void vlan_macout_forward_packet(NETSIM_ID d, NETSIM_ID in, UINT16 vlanId, NETSIM_ID incoming, NetSim_PACKET *packet, double time)
Definition: Vlan.c:252
void init_spanning_tree_protocol()
Definition: SpanningTree.c:266
UINT16 eth_get_incoming_vlanid(NetSim_PACKET *packet, NETSIM_ID devId)
bool isVLANTagPresent(NetSim_PACKET *packet)
Definition: Vlan.c:34
ptrETH_LAN GET_ETH_LAN(NETSIM_ID d, NETSIM_ID i, UINT16 vlanId)
struct stru_eth_packet ETH_HDR
enum enum_port_type SWITCH_PORTTYPE
ptrETH_VAR GET_ETH_VAR(NETSIM_ID d)
struct stru_ethernet_var * ptrETH_VAR
void set_eth_hdr(NetSim_PACKET *packet, UINT type, void *var, void *(fncopy)(void *), void(*fnfree)(void *))
struct stru_eth_phy ETH_PHY
struct stru_ethernet_var ETH_VAR
enum_SwitchingTechnique
Definition: Ethernet.h:47
@ SWITCHINGTECHNIQUE_CUT_THROUGH
Definition: Ethernet.h:50
@ SWITCHINGTECHNIQUE_NULL
Definition: Ethernet.h:48
@ SWITCHINGTECHNIQUE_STORE_FORWARD
Definition: Ethernet.h:49
@ SWITCHINGTECHNIQUE_FRAGMENT_FREE
Definition: Ethernet.h:51
struct stru_eth_bpdu ETH_BPDU
PNETSIM_MACADDRESS multicastSPTMAC
Definition: Ethernet.h:36
void free_eth_hdr(NetSim_PACKET *packet)
struct ieee802_1q_tag IEEE801_1Q_TAG
ptrETH_IF GET_ETH_IF(ptrETH_LAN lan, NETSIM_ID i)
void print_spanning_tree()
Definition: SpanningTree.c:539
ptrSWITCHTABLE SWITCHTABLE_FIND(ptrETH_LAN lan, PNETSIM_MACADDRESS dest)
Definition: SwitchTable.c:18
int multicast_config_bpdu()
Definition: SpanningTree.c:301
NETSIM_ID find_forward_interface(ptrETH_LAN lan, NetSim_PACKET *packet)
Definition: Ethernet_Mac.c:31
void SET_ETH_VAR(NETSIM_ID d, ptrETH_VAR var)
void print_ethernet_log(char *format,...)
struct stru_SwitchTable * ptrSWITCHTABLE
void vlan_add_trunk_port(ptrETH_VAR eth, NETSIM_ID in)
Definition: Vlan.c:53
struct stru_eth_phy * ptrETH_PHY
NETSIM_ID eth_get_incoming_port(NetSim_PACKET *packet, NETSIM_ID devId)
enum_port_type
Definition: Ethernet.h:65
@ PORTTYPE_NONDESIGNATED
Definition: Ethernet.h:67
@ PORTTYPE_ROOT
Definition: Ethernet.h:68
@ PORTTYPE_DESIGNATED
Definition: Ethernet.h:66
struct stru_SwitchTable SWITCHTABLE
void switchtable_metrics_print(PMETRICSWRITER metricsWriter)
Definition: SwitchTable.c:59
enum enum_eth_packet ETH_PACKET
struct stru_ethernet_spt ETH_SPT
enum enum_SwitchingTechnique SWITCHING_TECHNIQUE
struct stru_eth_interface_var * ptrETH_IF
void vlan_macin_forward_packet()
Definition: Vlan.c:179
enum_PortState
Definition: Ethernet.h:56
@ PORTSTATE_LEARNING
Definition: Ethernet.h:59
@ PORTSTATE_BLOCKING
Definition: Ethernet.h:61
@ PORTSTATE_LISTENING
Definition: Ethernet.h:58
@ PORTSTATE_DISABLED
Definition: Ethernet.h:57
@ PORTSTATE_FORWARDING
Definition: Ethernet.h:60
void SWITCHTABLE_NEW(ptrETH_LAN lan, PNETSIM_MACADDRESS dest, NETSIM_ID outport)
Definition: SwitchTable.c:30
struct stru_eth_interface_var ETH_IF
void process_configbpdu()
Definition: SpanningTree.c:484
VLANPORT vlan_port_type_from_str(char *val)
Definition: Vlan.c:43
void * get_eth_hdr_var(NetSim_PACKET *packet)
void clear_eth_incoming(NetSim_PACKET *packet)
void FREE_ETH_VAR(NETSIM_ID d)
void store_eth_incoming(NetSim_PACKET *packet, NETSIM_ID devId, NETSIM_ID incomingPort, UINT16 vlanId)
VLANPORT
Definition: Ethernet.h:134
@ VLANPORT_TRUNK
Definition: Ethernet.h:137
@ VLANPORT_NONE
Definition: Ethernet.h:135
@ VLANPORT_ACCESS
Definition: Ethernet.h:136
NETSIM_ID get_interface_id(NETSIM_ID d, NETSIM_ID c)
void forward_frame(NETSIM_ID d, NETSIM_ID in, ptrETH_LAN lan, NetSim_PACKET *packet, double time)
Definition: Ethernet_Mac.c:252
void vlan_forward_to_all_trunk(NETSIM_ID d, NetSim_PACKET *packet, ptrETH_LAN lan, double time)
Definition: Vlan.c:106
enum enum_PortState SWITCH_PORTSTATE
struct ieee802_1q_tag * ptrIEEE801_1Q_TAG
enum_eth_packet
Definition: Ethernet.h:41
@ ETH_CONFIGBPDU
Definition: Ethernet.h:42
struct stru_eth_bpdu * ptrETH_BPDU
#define c
#define UINT
Definition: Linux.h:38
#define UINT16
Definition: Linux.h:33
#define UINT8
Definition: Linux.h:31
void * PMETRICSWRITER
Definition: MetricsWriter.h:27
@ MAC_PROTOCOL_IEEE802_3
Definition: Stack.h:213
Definition: List.h:43
UINT16 TPId
Definition: Ethernet.h:108
NETSIM_ID vlanId
Definition: Ethernet.h:119
NETSIM_ID outPort
Definition: Ethernet.h:121
PNETSIM_MACADDRESS mac
Definition: Ethernet.h:120
UINT rootPathCost
Definition: Ethernet.h:96
char * rootId
Definition: Ethernet.h:95
UINT16 portId
Definition: Ethernet.h:98
UINT8 flags
Definition: Ethernet.h:94
UINT16 maxAge
Definition: Ethernet.h:100
UINT8 protocolVersionIdentifier
Definition: Ethernet.h:92
UINT16 protocolIdentifier
Definition: Ethernet.h:91
char * bridgeId
Definition: Ethernet.h:97
UINT16 msgAge
Definition: Ethernet.h:99
UINT8 bpduType
Definition: Ethernet.h:93
UINT16 forwardDelay
Definition: Ethernet.h:102
UINT16 helloTime
Definition: Ethernet.h:101
SWITCH_PORTTYPE portType
Definition: Ethernet.h:146
NETSIM_ID interfaceId
Definition: Ethernet.h:143
PNETSIM_MACADDRESS macAddress
Definition: Ethernet.h:144
SWITCH_PORTSTATE portState
Definition: Ethernet.h:145
void(* fnfree)(void *)
Definition: Ethernet.h:83
void * var
Definition: Ethernet.h:81
NETSIM_ID connectedDevice
Definition: Ethernet.h:215
double propagationDelay
Definition: Ethernet.h:214
double lastPacketEndTime
Definition: Ethernet.h:220
NETSIM_ID connectedInterface
Definition: Ethernet.h:216
bool isErrorChkReqd
Definition: Ethernet.h:222
NETSIM_ID interfaceId
Definition: Ethernet.h:211
double IFG
Definition: Ethernet.h:217
double BER
Definition: Ethernet.h:213
double speed
Definition: Ethernet.h:212
NetSim_BUFFER * packet
Definition: Ethernet.h:219
ptrETH_SPT spt
Definition: Ethernet.h:174
bool ispromiscuousMode
Definition: Ethernet.h:185
NETSIM_IPAddress lanIP
Definition: Ethernet.h:169
char * ethernetStandard
Definition: Ethernet.h:182
ptrSWITCHTABLE switchTable
Definition: Ethernet.h:180
NETSIM_ID lanId
Definition: Ethernet.h:166
ptrETH_IF * ethIfVar
Definition: Ethernet.h:172
NETSIM_ID * interfaceId
Definition: Ethernet.h:168
SWITCHING_TECHNIQUE switchingTechnique
Definition: Ethernet.h:177
char * STPProtocol
Definition: Ethernet.h:153
NETSIM_ID rootPort
Definition: Ethernet.h:160
NETSIM_ID devId
Definition: Ethernet.h:191
NETSIM_ID * trunkPortIds
Definition: Ethernet.h:201
ptrETH_LAN * lanVar
Definition: Ethernet.h:193
NetSim_BUFFER * buffer
Definition: Ethernet.h:197