NetSim Source Code Help
Loading...
Searching...
No Matches
SwitchTable.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
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* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14
15#include "main.h"
16#include "Ethernet.h"
17
19{
20 ptrSWITCHTABLE table = lan->switchTable;
21 while (table)
22 {
23 if (!MAC_COMPARE(dest, table->mac))
24 return table;
25 SWITCHTABLE_NEXT(table);
26 }
27 return NULL;
28}
29
31{
32 if (!dest)
33 {
34 fnNetSimError("Mac address is NULL in function %s\n", __FUNCTION__);
35 return;
36 }
37
38 ptrSWITCHTABLE table = SWITCHTABLE_FIND(lan, dest);
39 if (!table)
40 {
41 table = SWITCHTABLE_ALLOC();
42 table->mac = dest;
43 table->outPort = outport;
45 }
46}
47
49
50static PMETRICSNODE write_header(char* name)
51{
52 if(!menu)
53 menu = init_metrics_node(MetricsNode_Menu, "Switch Mac address table", NULL);
54 PMETRICSNODE submenu = init_metrics_node(MetricsNode_Menu, name, NULL);
55 add_node_to_menu(menu, submenu);
56 return submenu;
57}
58
60{
61 NETSIM_ID i;
62 for (i = 0; i < NETWORK->nDeviceCount; i++)
63 {
64 PMETRICSNODE submenu = NULL;
65 bool isStarted = false;
66 ptrETH_VAR eth = GET_ETH_VAR(i + 1);
67 if (!eth)
68 continue;
69
70 UINT j;
71 for (j = 0; j < eth->lanCount; j++)
72 {
73 ptrETH_LAN lan = eth->lanVar[j];
74 if(!lan->switchTable)
75 continue;
76
77 if (!isStarted)
78 {
79 submenu = write_header(DEVICE_NAME(i + 1));
80 isStarted = true;
81 }
82
83 char heading[BUFSIZ];
84 sprintf(heading, "%s_%d", DEVICE_NAME(i + 1), j);
85 PMETRICSNODE table = init_metrics_node(MetricsNode_Table, heading, NULL);
86 add_node_to_menu(submenu, table);
87
88 add_table_heading_special(table, "Mac Address#1,Type#1,OutPort#1,");
89
91 while (s)
92 {
93 if (s->mac) {
94 add_table_row_formatted(false, table, "%s,%s,%d,",
95 s->mac->szmacaddress,
96 "Dynamic",
97 s->outPort);
98 }
100 }
101 }
102 }
103 if (menu)
104 {
105 write_metrics_node(metricsWriter, WriterPosition_Current, NULL, menu);
107 }
108}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define SWITCHTABLE_NEXT(t)
Definition: Ethernet.h:126
#define SWITCHTABLE_ADD(l, m)
Definition: Ethernet.h:125
#define SWITCHTABLE_ALLOC()
Definition: Ethernet.h:124
ptrETH_VAR GET_ETH_VAR(NETSIM_ID d)
#define SWITCHTABLE_GET_LAN(lan)
Definition: Ethernet.h:128
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
@ WriterPosition_Current
Definition: MetricsWriter.h:15
void write_metrics_node(PMETRICSWRITER writer, WRITER_POSITION writerPosition, char *writer_name, PMETRICSNODE node)
void add_table_heading_special(PMETRICSNODE node, char *heading)
PMETRICSNODE init_metrics_node(METRICS_NODE type, char *name, char *secondarg)
void * PMETRICSNODE
Definition: MetricsWriter.h:21
void * PMETRICSWRITER
Definition: MetricsWriter.h:27
void delete_metrics_node(PMETRICSNODE node)
void add_node_to_menu(PMETRICSNODE menu, PMETRICSNODE node)
void add_table_row_formatted(bool issame, PMETRICSNODE node, char *format,...)
@ MetricsNode_Menu
Definition: MetricsWriter.h:5
@ MetricsNode_Table
Definition: MetricsWriter.h:6
#define DEVICE_NAME(DeviceId)
Definition: Stack.h:774
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
int MAC_COMPARE(PNETSIM_MACADDRESS mac1, PNETSIM_MACADDRESS mac2)
PMETRICSNODE menu
Definition: SwitchTable.c:48
ptrSWITCHTABLE SWITCHTABLE_FIND(ptrETH_LAN lan, PNETSIM_MACADDRESS dest)
Definition: SwitchTable.c:18
void switchtable_metrics_print(PMETRICSWRITER metricsWriter)
Definition: SwitchTable.c:59
static PMETRICSNODE write_header(char *name)
Definition: SwitchTable.c:50
void SWITCHTABLE_NEW(ptrETH_LAN lan, PNETSIM_MACADDRESS dest, NETSIM_ID outport)
Definition: SwitchTable.c:30
NETSIM_ID outPort
Definition: Ethernet.h:121
PNETSIM_MACADDRESS mac
Definition: Ethernet.h:120
ptrSWITCHTABLE switchTable
Definition: Ethernet.h:180
ptrETH_LAN * lanVar
Definition: Ethernet.h:193
char szmacaddress[13]
Definition: Stack.h:389