50 : TclClass(
"Module/UW/StaticRouting")
70 if (dst == 0 || next == 0) {
71 std::cerr <<
"You are trying to insert an invalid entry in the routing "
72 "table with destination: "
73 <<
static_cast<uint32_t
>(dst)
74 <<
" and next hop: " <<
static_cast<uint32_t
>(next)
79 std::map<uint8_t, uint8_t>::iterator it =
routing_table.find(dst);
87 std::cerr <<
"The routing table is full!" << std::endl;
95 Tcl &tcl = Tcl::instance();
97 if (strcasecmp(argv[1],
"numroutes") == 0) {
101 if (strcasecmp(argv[1],
"clearroutes") == 0) {
105 }
else if (argc == 3) {
106 if (strcasecmp(argv[1],
"defaultGateway") == 0) {
107 if (
static_cast<uint8_t
>(atoi(argv[2])) != 0) {
112 tcl.result(
"invalid address as default gateway. Exiting ...");
116 }
else if (argc == 4) {
117 if (strcasecmp(argv[1],
"addroute") == 0) {
118 int dst = std::atoi(argv[2]);
119 int next = std::atoi(argv[3]);
121 if (dst <= 0 || dst > 255 || next <= 0 || next > 255) {
122 tcl.result(
"invalid destination or next hop address");
126 addRoute(
static_cast<uint8_t
>(dst),
static_cast<uint8_t
>(next));
130 return Module::command(argc, argv);
136 hdr_cmn *ch = HDR_CMN(p);
139 printOnLog(Logger::LogLevel::DEBUG,
141 "recv(Packet *)::next hop " + to_string(ch->next_hop()) +
142 " destination ip = " + to_string((uint) uwiph->
daddr()));
144 if (ch->direction() == hdr_cmn::UP) {
145 if (uwiph->
daddr() == ch->next_hop() ||
151 ch->direction() = hdr_cmn::DOWN;
154 if (ch->next_hop() == 0)
161 if (ch->next_hop() == 0)
177 std::map<uint8_t, uint8_t>::const_iterator it =
routing_table.find(dst);
Adds the module for UwStaticRoutingModuleClass in ns2.
TclObject * create(int, const char *const *)
UwStaticRoutingModuleClass()
UwStaticRoutingModule class implements basic routing functionalities.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
virtual void clearRoutes()
Removes all the routing information.
virtual void addRoute(const uint8_t &, const uint8_t &)
Adds a new entry in the routing table.
std::map< uint8_t, uint8_t > routing_table
Routing table: destination - next hop.
UwStaticRoutingModule()
Constructor of UwStaticRoutingModule class.
virtual int command(int, const char *const *) override
TCL command interpreter.
virtual uint8_t getNextHop(const Packet *) const
Returns the next hop address of a packet passed as input.
uint8_t default_gateway
Default gateway.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
static const uint8_t UWIP_BROADCAST
Variable used to represent a broadcast UWIP.
UwStaticRoutingModuleClass class_uwstaticrouting_module
Provides basic routing functionalities.
static const uint16_t IP_ROUTING_MAX_ROUTES
Maximum number of entries in the routing table of a node.
#define DROP_DEST_NO_ROUTE
Reason for a drop in a UWVBR module.