|
INET Framework for OMNeT++/OMNEST
|
Parses a routing table file into a routing table.
More...
#include <RoutingTableParser.h>
|
| static int | streq (const char *str1, const char *str2) |
| |
| static void | skipBlanks (char *str, int &charptr) |
| |
| static int | strcpyword (char *dest, const char *src) |
| |
Parses a routing table file into a routing table.
◆ RoutingTableParser()
◆ ~RoutingTableParser()
| virtual inet::RoutingTableParser::~RoutingTableParser |
( |
| ) |
|
|
inlinevirtual |
◆ createFilteredFile()
| char * inet::RoutingTableParser::createFilteredFile |
( |
char * |
file, |
|
|
int & |
charpointer, |
|
|
const char * |
endtoken |
|
) |
| |
|
protectedvirtual |
120 filterFile[0] =
'\0';
124 while (!isalnum(file[charpointer]) && !isspace(file[charpointer])) {
125 while (file[charpointer++] !=
'\n')
130 if (
streq(file + charpointer, endtoken)) {
131 filterFile[i] =
'\0';
136 while ((filterFile[i++] = file[charpointer++]) !=
'\n')
Referenced by readRoutingTableFromFile().
◆ parseEntry()
| char * inet::RoutingTableParser::parseEntry |
( |
char * |
ifconfigFile, |
|
|
const char * |
tokenStr, |
|
|
int & |
charpointer, |
|
|
char * |
destStr |
|
) |
| |
|
protectedvirtual |
◆ parseInterfaces()
| void inet::RoutingTableParser::parseInterfaces |
( |
char * |
ifconfigFile | ) |
|
|
protectedvirtual |
147 NetworkInterface *ie =
nullptr;
150 while (ifconfigFile[charpointer] !=
'\0') {
152 if (
streq(ifconfigFile + charpointer,
"name:")) {
154 char *name =
parseEntry(ifconfigFile,
"name:", charpointer, buf);
157 throw cRuntimeError(
"Error in routing file: interface name `%s' not registered by any L2 module", name);
158 if (!ie->findProtocolData<Ipv4InterfaceData>())
159 throw cRuntimeError(
"Error in routing file: interface name `%s' doesn't have Ipv4 data fields", name);
165 if (
streq(ifconfigFile + charpointer,
"encap:")) {
167 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
169 parseEntry(ifconfigFile,
"encap:", charpointer, buf);
174 if (
streq(ifconfigFile + charpointer,
"HWaddr:")) {
176 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
178 parseEntry(ifconfigFile,
"HWaddr:", charpointer, buf);
183 if (
streq(ifconfigFile + charpointer,
"inet_addr:")) {
185 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
186 ie->getProtocolDataForUpdate<Ipv4InterfaceData>()->setIPAddress(Ipv4Address(
parseEntry(ifconfigFile,
"inet_addr:", charpointer, buf)));
191 if (
streq(ifconfigFile + charpointer,
"Bcast:")) {
193 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
195 parseEntry(ifconfigFile,
"Bcast:", charpointer, buf);
200 if (
streq(ifconfigFile + charpointer,
"Mask:")) {
202 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
203 ie->getProtocolDataForUpdate<Ipv4InterfaceData>()->setNetmask(Ipv4Address(
parseEntry(ifconfigFile,
"Mask:", charpointer, buf)));
208 if (
streq(ifconfigFile + charpointer,
"Groups:")) {
210 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
211 char *grStr =
parseEntry(ifconfigFile,
"Groups:", charpointer, buf);
217 if (
streq(ifconfigFile + charpointer,
"MTU:")) {
219 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
220 ie->setMtu(atoi(
parseEntry(ifconfigFile,
"MTU:", charpointer, buf)));
225 if (
streq(ifconfigFile + charpointer,
"Metric:")) {
227 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
228 ie->getProtocolDataForUpdate<Ipv4InterfaceData>()->setMetric(atoi(
parseEntry(ifconfigFile,
"Metric:", charpointer, buf)));
233 if (
streq(ifconfigFile + charpointer,
"BROADCAST")) {
235 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
236 ie->setBroadcast(
true);
237 charpointer += strlen(
"BROADCAST");
243 if (
streq(ifconfigFile + charpointer,
"MULTICAST")) {
245 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
246 ie->setMulticast(
true);
247 charpointer += strlen(
"MULTICAST");
253 if (
streq(ifconfigFile + charpointer,
"POINTTOPOINT")) {
255 throw cRuntimeError(
"Error in routing file: missing the `name:' entry");
256 ie->setPointToPoint(
true);
257 charpointer += strlen(
"POINTTOPOINT");
Referenced by readRoutingTableFromFile().
◆ parseMulticastGroups()
| void inet::RoutingTableParser::parseMulticastGroups |
( |
char * |
groupStr, |
|
|
NetworkInterface * |
itf |
|
) |
| |
|
protectedvirtual |
285 cStringTokenizer tokenizer(groupStr,
":");
287 while ((token = tokenizer.nextToken()) !=
nullptr)
288 itf->getProtocolDataForUpdate<Ipv4InterfaceData>()->joinMulticastGroup(Ipv4Address(token));
Referenced by parseInterfaces().
◆ parseRouting()
| void inet::RoutingTableParser::parseRouting |
( |
char * |
routeFile | ) |
|
|
protectedvirtual |
297 while (routeFile[pos] !=
'\0') {
301 Ipv4Route *
e =
new Ipv4Route();
302 if (strcmp(str,
"default:")) {
305 throw cRuntimeError(
"Syntax error in routing file: `%s' on 1st column should be `default:' or a valid Ipv4 address", str);
307 e->setDestination(Ipv4Address(str));
313 if (!strcmp(str,
"*") || !strcmp(str,
"0.0.0.0")) {
318 throw cRuntimeError(
"Syntax error in routing file: `%s' on 2nd column should be `*' or a valid Ipv4 address", str);
320 e->setGateway(Ipv4Address(str));
327 throw cRuntimeError(
"Syntax error in routing file: `%s' on 3rd column should be a valid Ipv4 address", str);
329 e->setNetmask(Ipv4Address(str));
335 for (
int i = 0; str[i]; i++) {
339 else if (str[i] ==
'G') {
343 throw cRuntimeError(
"Syntax error in routing file: 4th column should be `G' or `H' not `%s'", str);
350 int metric = atoi(str);
351 if (metric == 0 && str[0] !=
'0')
352 throw cRuntimeError(
"Syntax error in routing file: 5th column should be numeric not `%s'", str);
354 e->setMetric(metric);
357 opp_string interfaceName;
359 pos +=
strcpyword(interfaceName.buffer(), routeFile + pos);
363 throw cRuntimeError(
"Syntax error in routing file: 6th column: `%s' is not an existing interface", interfaceName.c_str());
Referenced by readRoutingTableFromFile().
◆ readRoutingTableFromFile()
| int inet::RoutingTableParser::readRoutingTableFromFile |
( |
const char * |
filename | ) |
|
|
virtual |
Read Routing Table file; return 0 on success, -1 on error.
58 FILE *fp = fopen(filename,
"r");
60 throw cRuntimeError(
"Error opening routing table file `%s'", filename);
64 char *ifconfigFile =
nullptr;
65 char *routeFile =
nullptr;
69 for (charpointer = 0; (
c = getc(fp)) != EOF; charpointer++)
70 file[charpointer] =
c;
73 file[charpointer] =
'\0';
79 (charpointer <
MAX_FILESIZE) && (file[charpointer] !=
'\0');
83 if (charpointer == 0 || file[charpointer - 1] ==
'\n') {
110 delete[] ifconfigFile;
Referenced by inet::Ipv4RoutingTable::handleOperationStage(), and inet::Ipv4RoutingTable::initialize().
◆ skipBlanks()
| void inet::RoutingTableParser::skipBlanks |
( |
char * |
str, |
|
|
int & |
charptr |
|
) |
| |
|
staticprotected |
◆ strcpyword()
| int inet::RoutingTableParser::strcpyword |
( |
char * |
dest, |
|
|
const char * |
src |
|
) |
| |
|
staticprotected |
◆ streq()
| int inet::RoutingTableParser::streq |
( |
const char * |
str1, |
|
|
const char * |
str2 |
|
) |
| |
|
staticprotected |
◆ ift
◆ rt
The documentation for this class was generated from the following files:
virtual void parseInterfaces(char *ifconfigFile)
Definition: RoutingTableParser.cc:143
IInterfaceTable * ift
Definition: RoutingTableParser.h:30
const value< double, compose< units::m, pow< units::s, -1 > > > c(299792458)
const char * IFCONFIG_START_TOKEN
Definition: RoutingTableParser.cc:31
@ MANUAL
manually added static route
Definition: IRoute.h:29
const int MAX_ENTRY_STRING_SIZE
Definition: RoutingTableParser.cc:26
static int streq(const char *str1, const char *str2)
Definition: RoutingTableParser.cc:36
const value< double, units::C > e(1.602176487e-19)
const char * ROUTE_START_TOKEN
Definition: RoutingTableParser.cc:33
IIpv4RoutingTable * rt
Definition: RoutingTableParser.h:31
virtual NetworkInterface * findInterfaceByName(const char *name) const =0
Returns an interface given by its name.
virtual void parseMulticastGroups(char *groupStr, NetworkInterface *)
Definition: RoutingTableParser.cc:282
const int MAX_FILESIZE
Definition: RoutingTableParser.cc:25
static int strcpyword(char *dest, const char *src)
Definition: RoutingTableParser.cc:41
virtual void addRoute(Ipv4Route *entry)=0
Adds a route to the routing table.
virtual char * parseEntry(char *ifconfigFile, const char *tokenStr, int &charpointer, char *destStr)
Definition: RoutingTableParser.cc:267
static const Ipv4Address UNSPECIFIED_ADDRESS
0.0.0.0
Definition: Ipv4Address.h:91
const char * IFCONFIG_END_TOKEN
Definition: RoutingTableParser.cc:32
const char * ROUTE_END_TOKEN
Definition: RoutingTableParser.cc:34
virtual char * createFilteredFile(char *file, int &charpointer, const char *endtoken)
Definition: RoutingTableParser.cc:116
static bool isWellFormed(const char *text)
Returns true if the format of the string corresponds to an Ipv4 address with the dotted notation ("19...
Definition: Ipv4Address.cc:258
virtual void parseRouting(char *routeFile)
Definition: RoutingTableParser.cc:291
static void skipBlanks(char *str, int &charptr)
Definition: RoutingTableParser.cc:50