INET Framework for OMNeT++/OMNEST
inet::NetworkInfo Class Reference

TODO documentation. More...

#include <NetworkInfo.h>

Inheritance diagram for inet::NetworkInfo:
inet::IScriptable

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void processCommand (const cXMLElement &node) override
 Called by ScenarioManager whenever a script command needs to be carried out by the module. More...
 
virtual void dumpRoutingInfo (cModule *target, const char *filename, bool append, bool compat)
 

Additional Inherited Members

- Public Member Functions inherited from inet::IScriptable
virtual ~IScriptable ()
 

Detailed Description

TODO documentation.

Member Function Documentation

void inet::NetworkInfo::dumpRoutingInfo ( cModule *  target,
const char *  filename,
bool  append,
bool  compat 
)
protectedvirtual

Referenced by processCommand().

58 {
59  std::ofstream s;
60  s.open(filename, append ? (std::ios::app) : (std::ios::out));
61  if (s.fail())
62  throw cRuntimeError("cannot open `%s' for write", filename);
63 
64  if (compat)
65  s << "Kernel IPv4 routing table" << endl;
66  s << "Destination Gateway Genmask ";
67  if (compat)
68  s << "Flags ";
69  s << "Metric ";
70  if (compat)
71  s << "Ref Use ";
72  s << "Iface" << endl;
73 
74  cModule *rtmod = target->getSubmodule("routingTable");
75  if (rtmod) {
76  std::vector<std::string> lines;
77 
78  IIPv4RoutingTable *rt = check_and_cast<IIPv4RoutingTable *>(rtmod);
79  for (int i = 0; i < rt->getNumRoutes(); i++) {
80  IPv4Address dest = rt->getRoute(i)->getDestination();
81 
82  if (dest.isMulticast())
83  continue;
84 
85  if (rt->getRoute(i)->getInterface()->isLoopback())
86  continue;
87 
88  IPv4Address netmask = rt->getRoute(i)->getNetmask();
89  IPv4Address gateway = rt->getRoute(i)->getGateway();
90  int metric = rt->getRoute(i)->getMetric();
91 
92  std::ostringstream line;
93 
94  line << std::left;
95  IPv4Address prefix = compat ? dest.doAnd(netmask) : dest; // typically dest in routes is already masked, so this is a no-op
96  line.width(16);
97  if (prefix.isUnspecified())
98  line << "0.0.0.0";
99  else
100  line << prefix;
101 
102  line.width(16);
103  if (gateway.isUnspecified())
104  line << "0.0.0.0";
105  else
106  line << gateway;
107 
108  line.width(16);
109  if (netmask.isUnspecified())
110  line << "0.0.0.0";
111  else
112  line << netmask;
113 
114  if (compat) {
115  int pad = 3;
116  line << "U"; // routes in INET are always up
117  if (!gateway.isUnspecified())
118  line << "G";
119  else
120  ++pad;
121  if (netmask.equals(IPv4Address::ALLONES_ADDRESS))
122  line << "H";
123  else
124  ++pad;
125  line.width(pad);
126  line << " ";
127  }
128 
129  line.width(7);
130  if (compat && rt->getRoute(i)->getSourceType() == IRoute::IFACENETMASK)
131  metric = 0;
132  line << metric;
133 
134  if (compat)
135  line << "0 0 ";
136 
137  line << rt->getRoute(i)->getInterfaceName() << endl;
138 
139  if (compat)
140  lines.push_back(line.str());
141  else
142  s << line.str();
143  }
144 
145  if (compat) {
146  // sort to avoid random order
147  // typically routing tables are sorted by netmask prefix length (descending)
148  // sorting by reversed natural order looks weired, but allows easy comparison
149  // with `route -n | sort -r` output by means of `diff` command...
150  std::stable_sort(lines.begin(), lines.end());
151  for (std::vector<std::string>::reverse_iterator it = lines.rbegin(); it != lines.rend(); it++)
152  s << *it;
153  }
154  }
155  s << endl;
156  s.close();
157 }
comes from an interface&#39;s netmask
Definition: IRoute.h:41
void append(std::vector< int > &dest, const std::vector< int > &src)
TODO documentation.
Definition: Utils.cc:114
value< double, units::s > s
Definition: Units.h:1049
static const IPv4Address ALLONES_ADDRESS
255.255.255.255
Definition: IPv4Address.h:105
void inet::NetworkInfo::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
37 {
38  ASSERT(false);
39 }
void inet::NetworkInfo::initialize ( )
overrideprotectedvirtual
32 {
33  // so far no initialization
34 }
void inet::NetworkInfo::processCommand ( const cXMLElement &  node)
overrideprotectedvirtual

Called by ScenarioManager whenever a script command needs to be carried out by the module.

The command is represented by the XML element or element tree. The command name can be obtained as:

const char *command = node->getTagName()

Parameters are XML attributes, e.g. a "neighbour" parameter can be retrieved as:

const char *attr = node->getAttribute("neighbour")

More complex input can be passed in child elements.

See also
cXMLElement

Implements inet::IScriptable.

42 {
43  cModule *target = getModuleByPath(node.getAttribute("target"));
44 
45  if (!strcmp(node.getTagName(), "routing")) {
46  const char *filename = node.getAttribute("file");
47  ASSERT(filename);
48  const char *mode = node.getAttribute("mode");
49  const char *compat = node.getAttribute("compat");
50 
51  dumpRoutingInfo(target, filename, (mode && !strcmp(mode, "a")), (compat && !strcmp(compat, "linux")));
52  }
53  else
54  ASSERT(false);
55 }
virtual void dumpRoutingInfo(cModule *target, const char *filename, bool append, bool compat)
Definition: NetworkInfo.cc:57

The documentation for this class was generated from the following files: