23 #include <UDPAppBase.h>
24 #include <UDPControlInfo_m.h>
25 #include "UDPSocket.h"
26 #include "UDPControlInfo_m.h"
28 #include <IPAddressResolver.h>
53 I3TriggerSet::iterator it;
54 for (it = t.begin(); it != t.end(); it++) {
55 os << *it <<
" in " << it->getInsertionTime() <<
"(" <<
56 (simTime() - it->getInsertionTime()) <<
")" << endl;
65 int prevDist = 0, nextDist = 0;
68 if (triggerTable.size() == 0)
return 0;
72 I3TriggerTable::const_iterator it = triggerTable.lower_bound(t);
74 if (it == triggerTable.end()) {
78 if (it->first == t)
return &it->first;
80 if (it != triggerTable.begin()) {
88 prevDist = it->first.distanceTo(t);
91 if (nextDist < prevDist) {
97 return (it->first.isMatch(t)) ? &it->first : 0;
105 cout <<
"Warning: Got trigger " << t <<
" with size 0 in " << thisNode.getIp()<< endl;
117 updateTriggerTableString();
134 updateTriggerTableString();
143 sendMessageToUDP(address, imsg);
151 if (idStack.
size() == 0) {
155 byteDroppedPackets += msg->getBitLength();
169 sendQueryReply(
id.getIdentifier(), msg->
getSource());
172 const I3Identifier *i3id = findClosestMatch(
id.getIdentifier());
179 if (idStack.
size() == 0) {
182 byteDroppedPackets += msg->getBitLength();
183 cout <<
"Dropped packet at" << thisNode.getIp()<<
" to unknown id " <<
id.getIdentifier() << endl;
199 set<I3Trigger> &s = triggerTable[*i3id];
200 set<I3Trigger>::iterator it;
202 for (it = s.begin(); it != s.end(); it++) {
209 dupMsg = check_and_cast<cPacket*>(msg->getEncapsulatedPacket()->
dup());
211 newMsg->encapsulate(dupMsg);
220 callRoute(key, newMsg);
233 numForwardedPackets++;
234 numForwardedBytes += (*msg)->getByteLength();
253 msg->removeControlInfo();
260 callRoute(key, imsg);
272 callRoute(key, rmsg);
291 callRoute(key, smsg);
304 I3IPAddress myAddress(thisNode.getIp(), par(
"serverPort"));
307 pmsg->setSource(myAddress);
308 pmsg->setSendingTime(simTime());
309 pmsg->setIdentifier(
id);
311 sendMessageToUDP(add, pmsg);
320 cout <<
"Delivered non I3 Message!" << endl;
368 numDroppedPackets = 0;
369 WATCH(numDroppedPackets);
370 byteDroppedPackets = 0;
371 WATCH(byteDroppedPackets);
373 numForwardedPackets = 0;
374 numForwardedBytes = 0;
376 WATCH(numForwardedPackets);
377 WATCH(numForwardedBytes);
379 triggerTimeToLive = par(
"triggerTimeToLive");
380 WATCH(triggerTimeToLive);
382 expirationTimer =
new cMessage(
"expiration timer");
383 scheduleAt(simTime() + triggerTimeToLive, expirationTimer);
385 getDisplayString() =
"i=i3";
387 thisNode.setPort(par(
"serverPort"));
388 bindToPort(thisNode.getPort());
394 bool updateString =
false;
396 if (msg == expirationTimer) {
397 scheduleAt(simTime() + triggerTimeToLive, expirationTimer);
399 for (I3TriggerTable::iterator it = triggerTable.begin(); it != triggerTable.end(); it++) {
400 set<I3Trigger> &triggerSet = it->second;
401 for (set<I3Trigger>::const_iterator sit = triggerSet.begin(); sit != triggerSet.end(); sit++) {
403 if (simTime() - sit->getInsertionTime() > triggerTimeToLive) {
408 triggerSet.erase(sit);
412 if (it->second.size() == 0) {
413 triggerTable.erase(it);
416 if (updateString) updateTriggerTableString();
433 recordScalar(
"I3 Packets dropped", numDroppedPackets);
434 recordScalar(
"I3 Bytes dropped", byteDroppedPackets);