57 : PacketHeaderClass(
"PacketHeader/UWUDP", sizeof(
hdr_uwudp))
71 : TclClass(
"Module/UW/UDP")
84 , drop_duplicated_packets_(0)
98 Tcl &tcl = Tcl::instance();
100 if (strcasecmp(argv[1],
"getudpheadersize") == 0) {
103 }
else if (strcasecmp(argv[1],
"printidspkts") == 0) {
109 if (strcasecmp(argv[1],
"assignPort") == 0) {
110 Module *m =
dynamic_cast<Module *
>(tcl.lookup(argv[2]));
114 tcl.resultf(
"%d", port);
118 return Module::command(argc, argv);
125 cerr <<
"PortMap::recv() a Packet is sent without source module!"
133 hdr_cmn *ch = HDR_CMN(p);
138 if (ch->direction() == hdr_cmn::UP) {
140 map<int, int>::const_iterator iter =
id_map.find(uwudp->
dport());
142 if (iter ==
id_map.end()) {
144 std::cout <<
"UwUdp::recv() (dir:UP) "
145 <<
" dport=" << uwudp->
dport()
151 int id = iter->second;
154 map<uint16_t, map_packets_el>::iterator it =
157 std::cout << ch->uid() <<
":"
158 <<
static_cast<uint16_t
>(iph->
saddr()) <<
":"
159 << iter->first << std::endl;
162 std::cout <<
"--> new port" << std::endl;
163 std::set<int> tmp_set_;
164 tmp_set_.insert(ch->uid());
166 tmp_map_el_.insert(pair<uint8_t, std::set<int> >(
167 iph->
saddr(), tmp_set_));
169 iter->first, tmp_map_el_));
172 std::cout <<
"--> old port" << std::endl;
173 std::map<uint8_t, std::set<int> >::iterator it2 =
174 it->second.find(iph->
saddr());
175 if (it2 == it->second.end()) {
178 std::cout <<
" --> new source" << std::endl;
179 std::set<int> tmp_set_;
180 tmp_set_.insert(ch->uid());
181 it->second.insert(pair<uint8_t, std::set<int> >(
182 iph->
saddr(), tmp_set_));
185 std::cout <<
" --> old source" << std::endl;
186 if (it2->second.count(ch->uid()) < 1) {
188 std::cout <<
" --> new packet" << std::endl;
189 it2->second.insert(ch->uid());
192 std::cout <<
" --> duplicated packet"
194 std::cout <<
" --> dropped" << std::endl;
206 map<int, int>::const_iterator iter =
port_map.find(idSrc);
210 cerr <<
"UwUdp::recv() (dir:DOWN) no port assigned to id "
211 << idSrc <<
", dropping packet!" << std::endl;
216 int sport = iter->second;
218 uwudp->
sport() = sport;
243 std::cerr <<
"UwUdp::assignPort() "
244 <<
" id=" <<
id <<
" port=" << newport
Adds the module for UwUdpClass in ns2.
TclObject * create(int, const char *const *)
Adds the header for hdr_uwudp packets in ns2.
UwUdp class is used to manage UWUDP packets, and flows to and from upper modules.
virtual int command(int, const char *const *)
TCL command interpreter.
map< int, int > port_map
Map: value = port; key = id.
virtual int assignPort(Module *)
Associates a module with a port.
map< int, int > id_map
Map: value = id; key = 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.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
std::map< uint8_t, std::set< int > > map_packets_el
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_
Flat to enable or disable the drop of duplicated packets.
int debug_
Flag to enable or disable dirrefent levels of debug.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWUDP.
virtual ~UwUdp()
Destructor of UwUdp class.
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.
#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.