A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test-epc-tft-classifier.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2018 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Nicola Baldo <nbaldo@cttc.es>
18 * Manuel Requena <manuel.requena@cttc.es>
19 */
20
21#include "ns3/epc-tft-classifier.h"
22#include "ns3/ipv4-header.h"
23#include "ns3/ipv4-l3-protocol.h"
24#include "ns3/ipv6-header.h"
25#include "ns3/ipv6-l3-protocol.h"
26#include "ns3/log.h"
27#include "ns3/packet.h"
28#include "ns3/tcp-header.h"
29#include "ns3/tcp-l4-protocol.h"
30#include "ns3/test.h"
31#include "ns3/udp-header.h"
32#include "ns3/udp-l4-protocol.h"
33
34#include <iomanip>
35
36using namespace ns3;
37
38NS_LOG_COMPONENT_DEFINE("TestEpcTftClassifier");
39
49{
50 public:
67 std::string sa,
68 std::string da,
69 uint16_t sp,
70 uint16_t dp,
71 uint8_t tos,
72 uint32_t tftId,
73 bool useIpv6);
74
76
77 private:
80 uint8_t m_tftId;
81 bool m_useIpv6;
86
101 static std::string BuildNameString(Ptr<EpcTftClassifier> c,
103 std::string sa,
104 std::string da,
105 uint16_t sp,
106 uint16_t dp,
107 uint8_t tos,
108 uint32_t tftId,
109 bool useIpv6);
110
111 void DoRun() override;
112};
113
116 std::string sa,
117 std::string da,
118 uint16_t sp,
119 uint16_t dp,
120 uint8_t tos,
121 uint32_t tftId,
122 bool useIpv6)
123 : TestCase(BuildNameString(c, d, sa, da, sp, dp, tos, tftId, useIpv6)),
124 m_c(c),
125 m_d(d),
126 m_tftId(tftId),
127 m_useIpv6(useIpv6)
128{
129 NS_LOG_FUNCTION(this << c << d << sa << da << sp << dp << tos << tftId << useIpv6);
130
131 if (m_useIpv6)
132 {
136 m_ipv6Header.SetPayloadLength(8); // Full UDP header
138 }
139 else
140 {
141 m_ipHeader.SetSource(Ipv4Address(sa.c_str()));
143 m_ipHeader.SetTos(tos);
144 m_ipHeader.SetPayloadSize(8); // Full UDP header
146 }
147
150}
151
153{
154}
155
156std::string
159 std::string sa,
160 std::string da,
161 uint16_t sp,
162 uint16_t dp,
163 uint8_t tos,
164 uint32_t tftId,
165 bool useIpv6)
166{
167 std::ostringstream oss;
168 oss << c << " d = " << d;
169 if (useIpv6)
170 {
171 oss << ", sa = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(sa.c_str()))
172 << ", da = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(da.c_str()));
173 }
174 else
175 {
176 oss << ", sa = " << sa << ", da = " << da;
177 }
178 oss << ", sp = " << sp << ", dp = " << dp << ", tos = 0x" << std::hex << (int)tos
179 << " --> tftId = " << tftId;
180 return oss.str();
181}
182
183void
185{
187
188 Ptr<Packet> udpPacket = Create<Packet>();
189 udpPacket->AddHeader(m_udpHeader);
190 if (m_useIpv6)
191 {
192 udpPacket->AddHeader(m_ipv6Header);
193 }
194 else
195 {
196 udpPacket->AddHeader(m_ipHeader);
197 }
198 NS_LOG_LOGIC(this << *udpPacket);
199 uint32_t obtainedTftId =
200 m_c->Classify(udpPacket,
201 m_d,
203 NS_TEST_ASSERT_MSG_EQ(obtainedTftId, (uint16_t)m_tftId, "bad classification of UDP packet");
204}
205
212{
213 public:
215};
216
222
224 : TestSuite("eps-tft-classifier", UNIT)
225{
226 NS_LOG_FUNCTION(this);
227
229 // Same testcases using IPv4 and IPv6 addresses
230 // IPv6 addresses are IPv4 mapped addresses, i.e. 1.2.3.4 -> 0::ffff:1.2.3.4
231 // Currently, we use the format '0::ffff:0102:0304' because
232 // the format '0::ffff:1.2.3.4' is not supported by the Ipv6Address class
234
235 for (bool useIpv6 : {false, true})
236 {
238 // check some TFT matches
240
241 Ptr<EpcTftClassifier> c1 = Create<EpcTftClassifier>();
242
243 Ptr<EpcTft> tft1_1 = Create<EpcTft>();
244
245 EpcTft::PacketFilter pf1_1_1;
246 if (useIpv6)
247 {
248 pf1_1_1.remoteIpv6Address.Set("0::ffff:0100:0000");
249 pf1_1_1.remoteIpv6Prefix = Ipv6Prefix(96 + 8);
250 pf1_1_1.localIpv6Address.Set("0::ffff:0200:0000");
251 pf1_1_1.localIpv6Prefix = Ipv6Prefix(96 + 8);
252 }
253 else
254 {
255 pf1_1_1.remoteAddress.Set("1.0.0.0");
256 pf1_1_1.remoteMask.Set(0xff000000);
257 pf1_1_1.localAddress.Set("2.0.0.0");
258 pf1_1_1.localMask.Set(0xff000000);
259 }
260 tft1_1->Add(pf1_1_1);
261
262 EpcTft::PacketFilter pf1_1_2;
263 if (useIpv6)
264 {
265 pf1_1_2.remoteIpv6Address.Set("0::ffff:0303:0300");
266 pf1_1_2.remoteIpv6Prefix = Ipv6Prefix(96 + 24);
267 pf1_1_2.localIpv6Address.Set("0::ffff:0404:0400");
268 pf1_1_2.localIpv6Prefix = Ipv6Prefix(96 + 24);
269 }
270 else
271 {
272 pf1_1_2.remoteAddress.Set("3.3.3.0");
273 pf1_1_2.remoteMask.Set(0xffffff00);
274 pf1_1_2.localAddress.Set("4.4.4.0");
275 pf1_1_2.localMask.Set(0xffffff00);
276 }
277 tft1_1->Add(pf1_1_2);
278
279 c1->Add(tft1_1, 1);
280
281 Ptr<EpcTft> tft1_2 = Create<EpcTft>();
282
283 EpcTft::PacketFilter pf1_2_1;
284 pf1_2_1.remotePortStart = 1024;
285 pf1_2_1.remotePortEnd = 1035;
286 tft1_2->Add(pf1_2_1);
287
288 EpcTft::PacketFilter pf1_2_2;
289 pf1_2_2.localPortStart = 3456;
290 pf1_2_2.localPortEnd = 3489;
291 tft1_2->Add(pf1_2_2);
292
293 EpcTft::PacketFilter pf1_2_3;
294 pf1_2_3.localPortStart = 7895;
295 pf1_2_3.localPortEnd = 7895;
296 tft1_2->Add(pf1_2_3);
297
298 EpcTft::PacketFilter pf1_2_4;
299 pf1_2_4.remotePortStart = 5897;
300 pf1_2_4.remotePortEnd = 5897;
301 tft1_2->Add(pf1_2_4);
302
303 c1->Add(tft1_2, 2);
304
305 // --------------------------------classifier----direction-------src_addr---dst_addr--src_port--dst_port--ToS--TFT_id
306
307 // test IP addresses
310 "2.2.3.4",
311 "1.1.1.1",
312 4,
313 1234,
314 0,
315 1,
316 useIpv6),
320 "2.2.3.4",
321 "1.0.0.0",
322 2,
323 123,
324 5,
325 1,
326 useIpv6),
330 "6.2.3.4",
331 "1.1.1.1",
332 4,
333 1234,
334 0,
335 0,
336 useIpv6),
340 "3.3.3.4",
341 "4.4.4.1",
342 4,
343 1234,
344 0,
345 1,
346 useIpv6),
350 "3.3.4.4",
351 "4.4.4.1",
352 4,
353 1234,
354 0,
355 0,
356 useIpv6),
360 "3.3.3.4",
361 "4.4.2.1",
362 4,
363 1234,
364 0,
365 0,
366 useIpv6),
368
369 // test remote port
372 "9.1.1.1",
373 "8.1.1.1",
374 4,
375 1024,
376 0,
377 2,
378 useIpv6),
382 "9.1.1.1",
383 "8.1.1.1",
384 4,
385 1025,
386 0,
387 2,
388 useIpv6),
392 "9.1.1.1",
393 "8.1.1.1",
394 4,
395 1035,
396 0,
397 2,
398 useIpv6),
402 "9.1.1.1",
403 "8.1.1.1",
404 4,
405 1234,
406 0,
407 0,
408 useIpv6),
412 "9.1.1.1",
413 "8.1.1.1",
414 4,
415 1024,
416 0,
417 0,
418 useIpv6),
422 "9.1.1.1",
423 "8.1.1.1",
424 4,
425 1025,
426 0,
427 0,
428 useIpv6),
432 "9.1.1.1",
433 "8.1.1.1",
434 4,
435 1035,
436 0,
437 0,
438 useIpv6),
440
441 // test local port
444 "9.1.1.1",
445 "8.1.1.1",
446 4,
447 3456,
448 0,
449 0,
450 useIpv6),
454 "9.1.1.1",
455 "8.1.1.1",
456 4,
457 3457,
458 0,
459 0,
460 useIpv6),
464 "9.1.1.1",
465 "8.1.1.1",
466 4,
467 3489,
468 0,
469 0,
470 useIpv6),
474 "9.1.1.1",
475 "8.1.1.1",
476 3456,
477 6,
478 0,
479 2,
480 useIpv6),
484 "9.1.1.1",
485 "8.1.1.1",
486 3461,
487 3461,
488 0,
489 2,
490 useIpv6),
494 "9.1.1.1",
495 "8.1.1.1",
496 9,
497 3489,
498 0,
499 2,
500 useIpv6),
504 "9.1.1.1",
505 "8.1.1.1",
506 9,
507 7895,
508 0,
509 2,
510 useIpv6),
514 "9.1.1.1",
515 "8.1.1.1",
516 7895,
517 10,
518 0,
519 2,
520 useIpv6),
524 "9.1.1.1",
525 "8.1.1.1",
526 9,
527 5897,
528 0,
529 2,
530 useIpv6),
534 "9.1.1.1",
535 "8.1.1.1",
536 5897,
537 10,
538 0,
539 2,
540 useIpv6),
542
544 // check default TFT
546
547 Ptr<EpcTftClassifier> c2 = Create<EpcTftClassifier>();
548 c2->Add(EpcTft::Default(), 1);
549
550 // --------------------------------classifier---direction--------src_addr---dst_addr--src_port--dst_port--ToS--TFT
551 // id
552
553 // test IP addresses
556 "2.2.3.4",
557 "1.1.1.1",
558 4,
559 1234,
560 0,
561 1,
562 useIpv6),
566 "2.2.3.4",
567 "1.0.0.0",
568 2,
569 123,
570 5,
571 1,
572 useIpv6),
576 "6.2.3.4",
577 "1.1.1.1",
578 4,
579 1234,
580 0,
581 1,
582 useIpv6),
586 "3.3.3.4",
587 "4.4.4.1",
588 4,
589 1234,
590 0,
591 1,
592 useIpv6),
596 "3.3.4.4",
597 "4.4.4.1",
598 4,
599 1234,
600 0,
601 1,
602 useIpv6),
606 "3.3.3.4",
607 "4.4.2.1",
608 4,
609 1234,
610 0,
611 1,
612 useIpv6),
614
615 // test remote port
618 "9.1.1.1",
619 "8.1.1.1",
620 4,
621 1024,
622 0,
623 1,
624 useIpv6),
628 "9.1.1.1",
629 "8.1.1.1",
630 4,
631 1025,
632 0,
633 1,
634 useIpv6),
638 "9.1.1.1",
639 "8.1.1.1",
640 4,
641 1035,
642 0,
643 1,
644 useIpv6),
648 "9.1.1.1",
649 "8.1.1.1",
650 4,
651 1234,
652 0,
653 1,
654 useIpv6),
658 "9.1.1.1",
659 "8.1.1.1",
660 4,
661 1024,
662 0,
663 1,
664 useIpv6),
668 "9.1.1.1",
669 "8.1.1.1",
670 4,
671 1025,
672 0,
673 1,
674 useIpv6),
678 "9.1.1.1",
679 "8.1.1.1",
680 4,
681 1035,
682 0,
683 1,
684 useIpv6),
686
687 // test local port
690 "9.1.1.1",
691 "8.1.1.1",
692 4,
693 3456,
694 0,
695 1,
696 useIpv6),
700 "9.1.1.1",
701 "8.1.1.1",
702 4,
703 3457,
704 0,
705 1,
706 useIpv6),
710 "9.1.1.1",
711 "8.1.1.1",
712 4,
713 3489,
714 0,
715 1,
716 useIpv6),
720 "9.1.1.1",
721 "8.1.1.1",
722 3456,
723 6,
724 0,
725 1,
726 useIpv6),
730 "9.1.1.1",
731 "8.1.1.1",
732 3461,
733 3461,
734 0,
735 1,
736 useIpv6),
740 "9.1.1.1",
741 "8.1.1.1",
742 9,
743 3489,
744 0,
745 1,
746 useIpv6),
748
750 // check default TFT plus dedicated ones
752
753 Ptr<EpcTftClassifier> c3 = Create<EpcTftClassifier>();
754 c3->Add(EpcTft::Default(), 1);
755 c3->Add(tft1_1, 2);
756 c3->Add(tft1_2, 3);
757
758 // --------------------------------classifier---direction--------src_addr---dst_addr---src_port--dst_port--ToS--TFT_id
759
760 // test IP addresses
763 "2.2.3.4",
764 "1.1.1.1",
765 4,
766 1234,
767 0,
768 2,
769 useIpv6),
773 "2.2.3.4",
774 "1.0.0.0",
775 2,
776 123,
777 5,
778 2,
779 useIpv6),
783 "6.2.3.4",
784 "1.1.1.1",
785 4,
786 1234,
787 0,
788 1,
789 useIpv6),
793 "3.3.3.4",
794 "4.4.4.1",
795 4,
796 1234,
797 0,
798 2,
799 useIpv6),
803 "3.3.4.4",
804 "4.4.4.1",
805 4,
806 1234,
807 0,
808 1,
809 useIpv6),
813 "3.3.3.4",
814 "4.4.2.1",
815 4,
816 1234,
817 0,
818 1,
819 useIpv6),
821
822 // test remote port
825 "9.1.1.1",
826 "8.1.1.1",
827 4,
828 1024,
829 0,
830 3,
831 useIpv6),
835 "9.1.1.1",
836 "8.1.1.1",
837 4,
838 1025,
839 0,
840 3,
841 useIpv6),
845 "9.1.1.1",
846 "8.1.1.1",
847 4,
848 1035,
849 0,
850 3,
851 useIpv6),
855 "9.1.1.1",
856 "8.1.1.1",
857 4,
858 1234,
859 0,
860 1,
861 useIpv6),
865 "9.1.1.1",
866 "8.1.1.1",
867 4,
868 1024,
869 0,
870 1,
871 useIpv6),
875 "9.1.1.1",
876 "8.1.1.1",
877 4,
878 1025,
879 0,
880 1,
881 useIpv6),
885 "9.1.1.1",
886 "8.1.1.1",
887 4,
888 1035,
889 0,
890 1,
891 useIpv6),
893
894 // test local port
897 "9.1.1.1",
898 "8.1.1.1",
899 4,
900 3456,
901 0,
902 1,
903 useIpv6),
907 "9.1.1.1",
908 "8.1.1.1",
909 4,
910 3457,
911 0,
912 1,
913 useIpv6),
917 "9.1.1.1",
918 "8.1.1.1",
919 4,
920 3489,
921 0,
922 1,
923 useIpv6),
927 "9.1.1.1",
928 "8.1.1.1",
929 3456,
930 6,
931 0,
932 3,
933 useIpv6),
937 "9.1.1.1",
938 "8.1.1.1",
939 3461,
940 3461,
941 0,
942 3,
943 useIpv6),
947 "9.1.1.1",
948 "8.1.1.1",
949 9,
950 3489,
951 0,
952 3,
953 useIpv6),
955
957 // check two TFTs with different ports
959
960 Ptr<EpcTftClassifier> c4 = Create<EpcTftClassifier>();
961 Ptr<EpcTft> tft4_1 = Create<EpcTft>();
962 tft4_1->Add(pf1_2_3);
963 c4->Add(tft4_1, 1);
964 Ptr<EpcTft> tft4_2 = Create<EpcTft>();
965 tft4_2->Add(pf1_2_4);
966 c4->Add(tft4_2, 2);
969 "9.1.1.1",
970 "8.1.1.1",
971 9,
972 3489,
973 0,
974 0,
975 useIpv6),
979 "9.1.1.1",
980 "8.1.1.1",
981 9,
982 7895,
983 0,
984 1,
985 useIpv6),
989 "9.1.1.1",
990 "8.1.1.1",
991 7895,
992 10,
993 0,
994 1,
995 useIpv6),
999 "9.1.1.1",
1000 "8.1.1.1",
1001 9,
1002 5897,
1003 0,
1004 2,
1005 useIpv6),
1009 "9.1.1.1",
1010 "8.1.1.1",
1011 5897,
1012 10,
1013 0,
1014 2,
1015 useIpv6),
1017 }
1018}
Test case to check the functionality of the Tft Classifier.
Ipv4Header m_ipHeader
the IPv4 header
TcpHeader m_tcpHeader
the TCP header
Ptr< EpcTftClassifier > m_c
the EPC TFT classifier
static std::string BuildNameString(Ptr< EpcTftClassifier > c, EpcTft::Direction d, std::string sa, std::string da, uint16_t sp, uint16_t dp, uint8_t tos, uint32_t tftId, bool useIpv6)
Build name string.
bool m_useIpv6
use IPv4 or IPv6 header/addresses
EpcTftClassifierTestCase(Ptr< EpcTftClassifier > c, EpcTft::Direction d, std::string sa, std::string da, uint16_t sp, uint16_t dp, uint8_t tos, uint32_t tftId, bool useIpv6)
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
UdpHeader m_udpHeader
the UDP header
EpcTft::Direction m_d
the EPC TFT direction
Ipv6Header m_ipv6Header
the IPv6 header
Epc Tft Classifier Test Suite.
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction, uint16_t protocolNumber)
classify an IP packet
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:229
Direction
Indicates the direction of the traffic that is to be classified.
Definition: epc-tft.h:51
@ DOWNLINK
Definition: epc-tft.h:52
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
void Set(uint32_t address)
input address is in host order.
Packet header for IPv4.
Definition: ipv4-header.h:34
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:309
void SetPayloadSize(uint16_t size)
Definition: ipv4-header.cc:57
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:288
void SetTos(uint8_t tos)
Definition: ipv4-header.cc:85
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:295
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
void Set(uint32_t mask)
input mask is in host order.
Definition: ipv4-address.cc:91
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Packet header for IPv6.
Definition: ipv6-header.h:35
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:118
void SetSource(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:106
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
Definition: ipv6-header.cc:70
void SetTrafficClass(uint8_t traffic)
Set the "Traffic class" field.
Definition: ipv6-header.cc:46
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:82
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
static void Enable()
Enable the packet metadata.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
Packet header for UDP packets.
Definition: udp-header.h:41
void SetSourcePort(uint16_t port)
Definition: udp-header.cc:63
void SetDestinationPort(uint16_t port)
Definition: udp-header.cc:57
static const uint8_t PROT_NUMBER
protocol number (0x11)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
static EpcTftClassifierTestSuite g_lteTftClassifierTestSuite
Static variable for test initialization.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition: epc-tft.h:71
Ipv4Address localAddress
IPv4 address of the UE.
Definition: epc-tft.h:121
Ipv6Prefix localIpv6Prefix
IPv6 address prefix of the UE.
Definition: epc-tft.h:127
uint16_t localPortEnd
end of the port number range of the UE
Definition: epc-tft.h:132
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition: epc-tft.h:122
uint16_t remotePortEnd
end of the port number range of the remote host
Definition: epc-tft.h:130
Ipv6Address remoteIpv6Address
IPv6 address of the remote host.
Definition: epc-tft.h:124
Ipv4Mask remoteMask
IPv4 address mask of the remote host.
Definition: epc-tft.h:120
uint16_t remotePortStart
start of the port number range of the remote host
Definition: epc-tft.h:129
Ipv6Address localIpv6Address
IPv6 address of the UE.
Definition: epc-tft.h:126
Ipv4Address remoteAddress
IPv4 address of the remote host.
Definition: epc-tft.h:119
Ipv6Prefix remoteIpv6Prefix
IPv6 address prefix of the remote host.
Definition: epc-tft.h:125
uint16_t localPortStart
start of the port number range of the UE
Definition: epc-tft.h:131