55 : PacketHeaderClass(
"PacketHeader/UWUDP", sizeof(
hdr_uwudp))
66 : TclClass(
"Module/UW/UDP")
79 , drop_duplicated_packets_(0)
89 Tcl &tcl = Tcl::instance();
91 if (strcasecmp(argv[1],
"getudpheadersize") == 0) {
94 }
else if (strcasecmp(argv[1],
"printidspkts") == 0) {
100 if (strcasecmp(argv[1],
"assignPort") == 0) {
101 Module *m =
dynamic_cast<Module *
>(tcl.lookup(argv[2]));
105 tcl.resultf(
"%d", port);
109 return Module::command(argc, argv);
115 printOnLog(Logger::LogLevel::ERROR,
117 "recv(Packet *)::packet sent without source module");
124 hdr_cmn *ch = HDR_CMN(p);
129 if (ch->direction() == hdr_cmn::UP) {
131 map<int, int>::const_iterator iter =
id_map.find(uwudp->
dport());
133 if (iter ==
id_map.end()) {
134 printOnLog(Logger::LogLevel::ERROR,
136 "recv(Packet *, int)::unknown port number, dport = " +
137 to_string(uwudp->
dport()));
143 int module_id = iter->second;
145 printOnLog(Logger::LogLevel::DEBUG,
147 "recv(Packet *, int)::new packet with id " +
148 to_string(ch->uid()) +
" from ip " +
149 to_string(
static_cast<uint16_t
>(iph->
saddr())) +
150 " : " + to_string(iter->first));
153 map<uint16_t, map_packets_el>::iterator it =
157 printOnLog(Logger::LogLevel::DEBUG,
159 "recv(Packet *, int)::packet to a new port");
161 std::set<int> tmp_set_;
162 tmp_set_.insert(ch->uid());
164 tmp_map_el_.insert(pair<uint8_t, std::set<int>>(
165 iph->
saddr(), tmp_set_));
167 iter->first, tmp_map_el_));
169 printOnLog(Logger::LogLevel::DEBUG,
171 "recv(Packet *, int)::packet to a known port");
173 std::map<uint8_t, std::set<int>>::iterator it2 =
174 it->second.find(iph->
saddr());
175 if (it2 == it->second.end()) {
176 printOnLog(Logger::LogLevel::DEBUG,
178 "recv(Packet *, int)::packet from a new "
181 std::set<int> tmp_set_;
182 tmp_set_.insert(ch->uid());
183 it->second.insert(pair<uint8_t, std::set<int>>(
184 iph->
saddr(), tmp_set_));
186 printOnLog(Logger::LogLevel::DEBUG,
188 "recv(Packet *, int)::packet from a known "
191 if (it2->second.count(ch->uid()) < 1) {
192 printOnLog(Logger::LogLevel::DEBUG,
194 "recv(Packet *, int)::new packet received");
196 it2->second.insert(ch->uid());
198 printOnLog(Logger::LogLevel::DEBUG,
200 "recv(Packet *, int)::duplicate packet "
211 sendUp(module_id, p);
213 map<int, int>::const_iterator iter =
port_map.find(idSrc);
216 printOnLog(Logger::LogLevel::ERROR,
218 "recv(Packet *, int)::no port assigned to id " +
219 to_string(idSrc) +
", dropping packet");
225 int sport = iter->second;
227 uwudp->
sport() = sport;
251 std::stringstream msg;
252 msg <<
"assignPort(Module *)::"
253 <<
"id = " <<
id <<
" port = " << newport
255 printOnLog(Logger::LogLevel::INFO,
"UWUDP", msg.str());
TclObject * create(int, const char *const *)
UwUdp class is used to manage UWUDP packets, and flows to and from upper modules.
std::map< int, int > port_map
Map application module id to port number (id, port_number).
std::map< int, int > id_map
Map port number to application module id (port_number, id).
virtual int command(int, const char *const *) override
TCL command interpreter.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
virtual int assignPort(Module *)
Associates a module with a port.
uint16_t portcounter
Counter used to generate new port numbers.
UwUdp()
Constructor of UwUdp class.
static int getUdpHeaderSize()
Returns the size in byte of a hdr_uwudp packet header.
std::map< uint16_t, map_packets_el > map_packets
Map used to keep track of the packets received by each port.
int drop_duplicated_packets_
Flag to enable or disable the drop of duplicated packets.
int debug_
Flag to enable or disable debug.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWUDP.
hdr_uwip describes UWIP packets.
uint8_t & saddr()
Reference to the saddr_ variable.
hdr_uwudp describes UWUDP packets.
static int offset_
Required by the PacketHeaderManager.
uint8_t & sport()
Reference to the sport_ variable.
uint8_t & dport()
Reference to the dport_ variable.
UwUdpClass class_module_uwudp
UwUdpPktClass class_uwudp_pkt
Provides the UWUDP packets header description and the definition of the class UWUDP.
std::map< uint8_t, std::set< int > > map_packets_el
#define DROP_RECEIVED_DUPLICATED_PACKET
Reason for a drop in a UWUDP module.
#define DROP_UNKNOWN_PORT_NUMBER
Reason for a drop in a UWUDP module.