diffserv_mfclassifier_1.test 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. %description: Tests for MultiFieldClassifier.
  2. %file: TestApp.ned
  3. simple TestApp
  4. {
  5. gates:
  6. input in[];
  7. input defaultIn;
  8. output out;
  9. }
  10. %file: TestApp.cc
  11. #include <fstream>
  12. #include "inet/common/INETDefs.h"
  13. #include "inet/networklayer/ipv4/IPv4Datagram.h"
  14. #include "inet/networklayer/ipv6/IPv6Datagram.h"
  15. #include "inet/transportlayer/udp/UDPPacket.h"
  16. using namespace inet;
  17. namespace diffserv_mfclassifier_1
  18. {
  19. class INET_API TestApp : public cSimpleModule
  20. {
  21. std::ofstream out;
  22. protected:
  23. void initialize();
  24. void finalize();
  25. void handleMessage(cMessage *msg);
  26. };
  27. Define_Module(TestApp);
  28. void TestApp::initialize()
  29. {
  30. out.open("result.txt");
  31. if (out.fail())
  32. throw cRuntimeError("Can not open output file.");
  33. IPv4Datagram *ipv4Datagram;
  34. IPv6Datagram *ipv6Datagram;
  35. UDPPacket *udpPacket;
  36. ipv4Datagram = new IPv4Datagram("ipv4-1");
  37. ipv4Datagram->setSrcAddress(IPv4Address("192.168.1.1"));
  38. send(ipv4Datagram, "out");
  39. ipv6Datagram = new IPv6Datagram("ipv6-2");
  40. ipv6Datagram->setSrcAddress(IPv6Address("fe80::1122:3344:5566"));
  41. send(ipv6Datagram, "out");
  42. ipv4Datagram = new IPv4Datagram("ipv4-3");
  43. ipv4Datagram->setDestAddress(IPv4Address("192.168.1.1"));
  44. send(ipv4Datagram, "out");
  45. ipv6Datagram = new IPv6Datagram("ipv6-4");
  46. ipv6Datagram->setDestAddress(IPv6Address("fe80::1122:3344:5566"));
  47. send(ipv6Datagram, "out");
  48. ipv4Datagram = new IPv4Datagram("ipv4-5");
  49. udpPacket = new UDPPacket();
  50. udpPacket->setSourcePort(1000);
  51. ipv4Datagram->encapsulate(udpPacket);
  52. send(ipv4Datagram, "out");
  53. ipv4Datagram = new IPv4Datagram("ipv4-6");
  54. udpPacket = new UDPPacket();
  55. udpPacket->setDestinationPort(1000);
  56. ipv4Datagram->encapsulate(udpPacket);
  57. send(ipv4Datagram, "out");
  58. ipv4Datagram = new IPv4Datagram("ipv4-7");
  59. ipv4Datagram->setTransportProtocol(17);
  60. send(ipv4Datagram, "out");
  61. ipv4Datagram = new IPv4Datagram("ipv4-8");
  62. ipv4Datagram->setTypeOfService(0x2e);
  63. send(ipv4Datagram, "out");
  64. ipv6Datagram = new IPv6Datagram("ipv6-9");
  65. ipv6Datagram->setTrafficClass(0x2e);
  66. send(ipv6Datagram, "out");
  67. ipv4Datagram = new IPv4Datagram("ipv4-10");
  68. ipv4Datagram->setSrcAddress(IPv4Address("192.168.2.1"));
  69. send(ipv4Datagram, "out");
  70. ipv6Datagram = new IPv6Datagram("ipv6-11");
  71. ipv6Datagram->setSrcAddress(IPv6Address("fe80::1"));
  72. send(ipv6Datagram, "out");
  73. ipv4Datagram = new IPv4Datagram("ipv4-12");
  74. ipv4Datagram->setDestAddress(IPv4Address("192.168.2.1"));
  75. send(ipv4Datagram, "out");
  76. ipv6Datagram = new IPv6Datagram("ipv6-13");
  77. ipv6Datagram->setDestAddress(IPv6Address("fe80::1"));
  78. send(ipv6Datagram, "out");
  79. ipv4Datagram = new IPv4Datagram("ipv4-14");
  80. udpPacket = new UDPPacket();
  81. udpPacket->setSourcePort(2100);
  82. ipv4Datagram->encapsulate(udpPacket);
  83. send(ipv4Datagram, "out");
  84. ipv6Datagram = new IPv6Datagram("ipv6-15");
  85. udpPacket = new UDPPacket();
  86. udpPacket->setSourcePort(2200);
  87. ipv6Datagram->encapsulate(udpPacket);
  88. send(ipv6Datagram, "out");
  89. ipv4Datagram = new IPv4Datagram("ipv4-16");
  90. udpPacket = new UDPPacket();
  91. udpPacket->setDestinationPort(2300);
  92. ipv4Datagram->encapsulate(udpPacket);
  93. send(ipv4Datagram, "out");
  94. ipv6Datagram = new IPv6Datagram("ipv6-17");
  95. udpPacket = new UDPPacket();
  96. udpPacket->setDestinationPort(2400);
  97. ipv6Datagram->encapsulate(udpPacket);
  98. send(ipv6Datagram, "out");
  99. ipv4Datagram = new IPv4Datagram("ipv4-18");
  100. send(ipv4Datagram, "out");
  101. }
  102. void TestApp::finalize()
  103. {
  104. out.close();
  105. }
  106. void TestApp::handleMessage(cMessage *msg)
  107. {
  108. cGate *gate = msg->getArrivalGate();
  109. out << msg->getName() << ": " << gate->getName() << "[" << gate->getIndex() << "]\n";
  110. delete msg;
  111. }
  112. }
  113. %file: TestNetwork.ned
  114. import inet.networklayer.diffserv.MultiFieldClassifier;
  115. network TestNetwork
  116. {
  117. parameters:
  118. *.interfaceTableModule = "";
  119. submodules:
  120. app: TestApp;
  121. classifier: MultiFieldClassifier { filters = xmldoc("filters.xml"); }
  122. connections:
  123. app.out --> classifier.in;
  124. for i=0..13 {
  125. classifier.outs++ --> app.in++;
  126. }
  127. classifier.defaultOut --> app.defaultIn;
  128. }
  129. %file: filters.xml
  130. <filters>
  131. <filter gate="0" srcAddress="192.168.1.1"/>
  132. <filter gate="1" srcAddress="fe80::1122:3344:5566"/>
  133. <filter gate="2" destAddress="192.168.1.1"/>
  134. <filter gate="3" destAddress="fe80::1122:3344:5566"/>
  135. <filter gate="4" srcPort="1000"/>
  136. <filter gate="5" destPort="1000"/>
  137. <filter gate="6" protocol="17"/>
  138. <filter gate="7" tos="0x2e" tosMask="0x3f"/>
  139. <filter gate="8" srcAddress="192.168.0.0" srcPrefixLength="16"/>
  140. <filter gate="9" srcAddress="fe80::" srcPrefixLength="10"/>
  141. <filter gate="10" destAddress="192.168.0.0" destPrefixLength="16"/>
  142. <filter gate="11" destAddress="fe80::" destPrefixLength="10"/>
  143. <filter gate="12" srcPortMin="2000" srcPortMax="2999"/>
  144. <filter gate="13" destPortMin="2000" destPortMax="2999"/>
  145. </filters>
  146. %inifile: omnetpp.ini
  147. [General]
  148. ned-path = .;../../../../src;../../lib
  149. sim-time-limit=100s
  150. cmdenv-express-mode = true
  151. network = TestNetwork
  152. #omnetpp 5.0 - 5.1 compatibility:
  153. eventlog-file = "${resultdir}/${configname}-${runnumber}.elog"
  154. output-scalar-file = "${resultdir}/${configname}-${runnumber}.sca"
  155. output-vector-file = "${resultdir}/${configname}-${runnumber}.vec"
  156. snapshot-file = "${resultdir}/${configname}-${runnumber}.sna"
  157. %contains: result.txt
  158. ipv4-1: in[0]
  159. ipv6-2: in[1]
  160. ipv4-3: in[2]
  161. ipv6-4: in[3]
  162. ipv4-5: in[4]
  163. ipv4-6: in[5]
  164. ipv4-7: in[6]
  165. ipv4-8: in[7]
  166. ipv6-9: in[7]
  167. ipv4-10: in[8]
  168. ipv6-11: in[9]
  169. ipv4-12: in[10]
  170. ipv6-13: in[11]
  171. ipv4-14: in[12]
  172. ipv6-15: in[12]
  173. ipv4-16: in[13]
  174. ipv6-17: in[13]
  175. ipv4-18: defaultIn[0]
  176. %#--------------------------------------------------------------------------------------------------------------
  177. %not-contains: stdout
  178. undisposed object:
  179. %not-contains: stdout
  180. -- check module destructor
  181. %#--------------------------------------------------------------------------------------------------------------