NetSim Source Code Help
Loading...
Searching...
No Matches
PIM_Config.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 "List.h"
17#include "IP.h"
18#include "PIM_SM.h"
19#include "NetSim_utility.h"
20
22{
23 NETSIM_ID i;
24 for (i = 0; i < NETWORK->nDeviceCount; i++)
25 {
26 if (isRouter(i + 1) &&
27 GET_IP_DEVVAR(i + 1)->isPIMConfigured)
28 {
29 create_group(i + 1, g, r);
30 }
31 }
32}
33
35{
36 FILE* fp;
37 char p[BUFSIZ];
38 sprintf(p, "%s%s%s", pszIOPath, pathSeperator, "PIM_Config.txt");
39 fp = fopen(p, "r");
40 if (!fp)
41 {
42 perror(p);
43 return;
44 }
45 char buf[BUFSIZ];
46 while (fgets(buf, BUFSIZ, fp))
47 {
48 char* s = buf;
49 s = lskip(s);
50
51 if (*s == '#')
52 continue; //Comment line
53 if (*s == 0 || *s == '\n')
54 continue; //Empty line
55
56 rstrip(s);
57
58 char* g = NULL;
59 char* r = NULL;
60 g = s;
61 while (s)
62 {
63 if (*s == ',')
64 {
65 *s = 0;
66 r = s + 1;
67 s++;
68 break;
69 }
70 s++;
71 }
72 r = s;
73 while (s)
74 {
75 if (*s == ',')
76 {
77 *s = 0;
78 //Ignore extra
79 break;
80 }
81 s++;
82 }
83 if (!g || !r)
84 {
85 fnNetSimError("Format of PIM_Config file is not correct. It must be \"GROUP_ADDR,RP_ADDR,\"");
86 continue;
87 }
88
91
93 }
94}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define GET_IP_DEVVAR(d)
Definition: IP.h:49
#define STR_TO_IP4(ipstr)
Definition: IP_Addressing.h:94
#define fnNetSimError(x,...)
Definition: Linux.h:56
static const char pathSeperator[5]
Definition: Linux.h:71
char * rstrip(char *s)
char * lskip(const char *s)
void configure_PIM()
Definition: PIM_Config.c:34
static void create_multicast_group_for_all(NETSIM_IPAddress g, NETSIM_IPAddress r)
Definition: PIM_Config.c:21
ptrPIM_GROUP create_group(NETSIM_ID d, NETSIM_IPAddress addr, NETSIM_IPAddress RP)
Definition: PIM_Group.c:32
EXPORTED char * pszIOPath
Definition: Stack.h:842
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
bool isRouter(NETSIM_ID d)