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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors:
7 * Nicola Baldo <nbaldo@cttc.es>
8 * Manuel Requena <manuel.requena@cttc.es>
9 */
10
11#include "ns3/epc-tft-classifier.h"
12#include "ns3/ipv4-header.h"
13#include "ns3/ipv4-l3-protocol.h"
14#include "ns3/ipv6-header.h"
15#include "ns3/ipv6-l3-protocol.h"
16#include "ns3/log.h"
17#include "ns3/packet.h"
18#include "ns3/tcp-header.h"
19#include "ns3/tcp-l4-protocol.h"
20#include "ns3/test.h"
21#include "ns3/udp-header.h"
22#include "ns3/udp-l4-protocol.h"
23
24#include <iomanip>
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE("TestEpcTftClassifier");
29
30/**
31 * @ingroup lte-test
32 *
33 * @brief Test case to check the functionality of the Tft Classifier. Test
34 * consist of defining different TFT configurations, i.e. direction, ports,
35 * address, and it is checking if the clasiffication of UDP packets is
36 * done correctly.
37 */
39{
40 public:
41 /**
42 * Constructor
43 *
44 * @param c the EPC TFT classifier
45 * @param d the EPC TFT direction
46 * @param sa the source address (in IPv4 format)
47 * @param da the destination address (in IPv4 format)
48 * @param sp the source port
49 * @param dp the destination port
50 * @param tos the TOS
51 * @param tftId the TFT ID
52 * @param useIpv6 use IPv6 or IPv4 addresses. If set, addresses will be used as IPv4 mapped
53 * addresses
54 */
57 std::string sa,
58 std::string da,
59 uint16_t sp,
60 uint16_t dp,
61 uint8_t tos,
62 uint32_t tftId,
63 bool useIpv6);
64
66
67 private:
68 Ptr<EpcTftClassifier> m_c; ///< the EPC TFT classifier
69 EpcTft::Direction m_d; ///< the EPC TFT direction
70 uint8_t m_tftId; ///< the TFT ID
71 bool m_useIpv6; ///< use IPv4 or IPv6 header/addresses
72 Ipv4Header m_ipHeader; ///< the IPv4 header
73 Ipv6Header m_ipv6Header; ///< the IPv6 header
74 UdpHeader m_udpHeader; ///< the UDP header
75 TcpHeader m_tcpHeader; ///< the TCP header
76
77 /**
78 * Build name string
79 * @param c the EPC TFT classifier
80 * @param d the EPC TFT direction
81 * @param sa the source address
82 * @param da the destination address
83 * @param sp the source port
84 * @param dp the destination port
85 * @param tos the TOS
86 * @param tftId the TFT ID
87 * @param useIpv6 use IPv6 or IPv4 addresses. If set, addresses will be used as IPv4
88 * mapped addresses
89 * @returns the name string
90 */
91 static std::string BuildNameString(Ptr<EpcTftClassifier> c,
93 std::string sa,
94 std::string da,
95 uint16_t sp,
96 uint16_t dp,
97 uint8_t tos,
98 uint32_t tftId,
99 bool useIpv6);
100
101 void DoRun() override;
102};
103
106 std::string sa,
107 std::string da,
108 uint16_t sp,
109 uint16_t dp,
110 uint8_t tos,
111 uint32_t tftId,
112 bool useIpv6)
113 : TestCase(BuildNameString(c, d, sa, da, sp, dp, tos, tftId, useIpv6)),
114 m_c(c),
115 m_d(d),
116 m_tftId(tftId),
117 m_useIpv6(useIpv6)
118{
119 NS_LOG_FUNCTION(this << c << d << sa << da << sp << dp << tos << tftId << useIpv6);
120
121 if (m_useIpv6)
122 {
125 m_ipv6Header.SetTrafficClass(tos);
126 m_ipv6Header.SetPayloadLength(8); // Full UDP header
128 }
129 else
130 {
131 m_ipHeader.SetSource(Ipv4Address(sa.c_str()));
132 m_ipHeader.SetDestination(Ipv4Address(da.c_str()));
133 m_ipHeader.SetTos(tos);
134 m_ipHeader.SetPayloadSize(8); // Full UDP header
136 }
137
138 m_udpHeader.SetSourcePort(sp);
139 m_udpHeader.SetDestinationPort(dp);
140}
141
145
146std::string
149 std::string sa,
150 std::string da,
151 uint16_t sp,
152 uint16_t dp,
153 uint8_t tos,
154 uint32_t tftId,
155 bool useIpv6)
156{
157 std::ostringstream oss;
158 oss << c << " d = " << d;
159 if (useIpv6)
160 {
161 oss << ", sa = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(sa.c_str()))
162 << ", da = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(da.c_str()));
163 }
164 else
165 {
166 oss << ", sa = " << sa << ", da = " << da;
167 }
168 oss << ", sp = " << sp << ", dp = " << dp << ", tos = 0x" << std::hex << (int)tos
169 << " --> tftId = " << tftId;
170 return oss.str();
171}
172
173void
175{
177
178 Ptr<Packet> udpPacket = Create<Packet>();
179 udpPacket->AddHeader(m_udpHeader);
180 if (m_useIpv6)
181 {
182 udpPacket->AddHeader(m_ipv6Header);
183 }
184 else
185 {
186 udpPacket->AddHeader(m_ipHeader);
187 }
188 NS_LOG_LOGIC(this << *udpPacket);
189 uint32_t obtainedTftId =
190 m_c->Classify(udpPacket,
191 m_d,
193 NS_TEST_ASSERT_MSG_EQ(obtainedTftId, (uint16_t)m_tftId, "bad classification of UDP packet");
194}
195
196/**
197 * @ingroup lte-test
198 *
199 * @brief Epc Tft Classifier Test Suite
200 */
202{
203 public:
205};
206
207/**
208 * @ingroup lte-test
209 * Static variable for test initialization
210 */
212
214 : TestSuite("eps-tft-classifier", Type::UNIT)
215{
216 NS_LOG_FUNCTION(this);
217
218 /////////////////////////////////////////////////////////////////////////////////
219 // Same testcases using IPv4 and IPv6 addresses
220 // IPv6 addresses are IPv4 mapped addresses, i.e. 1.2.3.4 -> 0::ffff:1.2.3.4
221 // Currently, we use the format '0::ffff:0102:0304' because
222 // the format '0::ffff:1.2.3.4' is not supported by the Ipv6Address class
223 /////////////////////////////////////////////////////////////////////////////////
224
225 for (bool useIpv6 : {false, true})
226 {
227 //////////////////////////
228 // check some TFT matches
229 //////////////////////////
230
232
233 Ptr<EpcTft> tft1_1 = Create<EpcTft>();
234
235 EpcTft::PacketFilter pf1_1_1;
236 if (useIpv6)
237 {
238 pf1_1_1.remoteIpv6Address.Set("0::ffff:0100:0000");
239 pf1_1_1.remoteIpv6Prefix = Ipv6Prefix(96 + 8);
240 pf1_1_1.localIpv6Address.Set("0::ffff:0200:0000");
241 pf1_1_1.localIpv6Prefix = Ipv6Prefix(96 + 8);
242 }
243 else
244 {
245 pf1_1_1.remoteAddress.Set("1.0.0.0");
246 pf1_1_1.remoteMask.Set(0xff000000);
247 pf1_1_1.localAddress.Set("2.0.0.0");
248 pf1_1_1.localMask.Set(0xff000000);
249 }
250 tft1_1->Add(pf1_1_1);
251
252 EpcTft::PacketFilter pf1_1_2;
253 if (useIpv6)
254 {
255 pf1_1_2.remoteIpv6Address.Set("0::ffff:0303:0300");
256 pf1_1_2.remoteIpv6Prefix = Ipv6Prefix(96 + 24);
257 pf1_1_2.localIpv6Address.Set("0::ffff:0404:0400");
258 pf1_1_2.localIpv6Prefix = Ipv6Prefix(96 + 24);
259 }
260 else
261 {
262 pf1_1_2.remoteAddress.Set("3.3.3.0");
263 pf1_1_2.remoteMask.Set(0xffffff00);
264 pf1_1_2.localAddress.Set("4.4.4.0");
265 pf1_1_2.localMask.Set(0xffffff00);
266 }
267 tft1_1->Add(pf1_1_2);
268
269 c1->Add(tft1_1, 1);
270
271 Ptr<EpcTft> tft1_2 = Create<EpcTft>();
272
273 EpcTft::PacketFilter pf1_2_1;
274 pf1_2_1.remotePortStart = 1024;
275 pf1_2_1.remotePortEnd = 1035;
276 tft1_2->Add(pf1_2_1);
277
278 EpcTft::PacketFilter pf1_2_2;
279 pf1_2_2.localPortStart = 3456;
280 pf1_2_2.localPortEnd = 3489;
281 tft1_2->Add(pf1_2_2);
282
283 EpcTft::PacketFilter pf1_2_3;
284 pf1_2_3.localPortStart = 7895;
285 pf1_2_3.localPortEnd = 7895;
286 tft1_2->Add(pf1_2_3);
287
288 EpcTft::PacketFilter pf1_2_4;
289 pf1_2_4.remotePortStart = 5897;
290 pf1_2_4.remotePortEnd = 5897;
291 tft1_2->Add(pf1_2_4);
292
293 c1->Add(tft1_2, 2);
294
295 // --------------------------------classifier----direction-------src_addr---dst_addr--src_port--dst_port--ToS--TFT_id
296
297 // test IP addresses
300 "2.2.3.4",
301 "1.1.1.1",
302 4,
303 1234,
304 0,
305 1,
306 useIpv6),
310 "2.2.3.4",
311 "1.0.0.0",
312 2,
313 123,
314 5,
315 1,
316 useIpv6),
320 "6.2.3.4",
321 "1.1.1.1",
322 4,
323 1234,
324 0,
325 0,
326 useIpv6),
330 "3.3.3.4",
331 "4.4.4.1",
332 4,
333 1234,
334 0,
335 1,
336 useIpv6),
340 "3.3.4.4",
341 "4.4.4.1",
342 4,
343 1234,
344 0,
345 0,
346 useIpv6),
350 "3.3.3.4",
351 "4.4.2.1",
352 4,
353 1234,
354 0,
355 0,
356 useIpv6),
358
359 // test remote port
362 "9.1.1.1",
363 "8.1.1.1",
364 4,
365 1024,
366 0,
367 2,
368 useIpv6),
372 "9.1.1.1",
373 "8.1.1.1",
374 4,
375 1025,
376 0,
377 2,
378 useIpv6),
382 "9.1.1.1",
383 "8.1.1.1",
384 4,
385 1035,
386 0,
387 2,
388 useIpv6),
392 "9.1.1.1",
393 "8.1.1.1",
394 4,
395 1234,
396 0,
397 0,
398 useIpv6),
402 "9.1.1.1",
403 "8.1.1.1",
404 4,
405 1024,
406 0,
407 0,
408 useIpv6),
412 "9.1.1.1",
413 "8.1.1.1",
414 4,
415 1025,
416 0,
417 0,
418 useIpv6),
422 "9.1.1.1",
423 "8.1.1.1",
424 4,
425 1035,
426 0,
427 0,
428 useIpv6),
430
431 // test local port
434 "9.1.1.1",
435 "8.1.1.1",
436 4,
437 3456,
438 0,
439 0,
440 useIpv6),
444 "9.1.1.1",
445 "8.1.1.1",
446 4,
447 3457,
448 0,
449 0,
450 useIpv6),
454 "9.1.1.1",
455 "8.1.1.1",
456 4,
457 3489,
458 0,
459 0,
460 useIpv6),
464 "9.1.1.1",
465 "8.1.1.1",
466 3456,
467 6,
468 0,
469 2,
470 useIpv6),
474 "9.1.1.1",
475 "8.1.1.1",
476 3461,
477 3461,
478 0,
479 2,
480 useIpv6),
484 "9.1.1.1",
485 "8.1.1.1",
486 9,
487 3489,
488 0,
489 2,
490 useIpv6),
494 "9.1.1.1",
495 "8.1.1.1",
496 9,
497 7895,
498 0,
499 2,
500 useIpv6),
504 "9.1.1.1",
505 "8.1.1.1",
506 7895,
507 10,
508 0,
509 2,
510 useIpv6),
514 "9.1.1.1",
515 "8.1.1.1",
516 9,
517 5897,
518 0,
519 2,
520 useIpv6),
524 "9.1.1.1",
525 "8.1.1.1",
526 5897,
527 10,
528 0,
529 2,
530 useIpv6),
532
533 ///////////////////////////
534 // check default TFT
535 ///////////////////////////
536
538 c2->Add(EpcTft::Default(), 1);
539
540 // --------------------------------classifier---direction--------src_addr---dst_addr--src_port--dst_port--ToS--TFT
541 // id
542
543 // test IP addresses
546 "2.2.3.4",
547 "1.1.1.1",
548 4,
549 1234,
550 0,
551 1,
552 useIpv6),
556 "2.2.3.4",
557 "1.0.0.0",
558 2,
559 123,
560 5,
561 1,
562 useIpv6),
566 "6.2.3.4",
567 "1.1.1.1",
568 4,
569 1234,
570 0,
571 1,
572 useIpv6),
576 "3.3.3.4",
577 "4.4.4.1",
578 4,
579 1234,
580 0,
581 1,
582 useIpv6),
586 "3.3.4.4",
587 "4.4.4.1",
588 4,
589 1234,
590 0,
591 1,
592 useIpv6),
596 "3.3.3.4",
597 "4.4.2.1",
598 4,
599 1234,
600 0,
601 1,
602 useIpv6),
604
605 // test remote port
608 "9.1.1.1",
609 "8.1.1.1",
610 4,
611 1024,
612 0,
613 1,
614 useIpv6),
618 "9.1.1.1",
619 "8.1.1.1",
620 4,
621 1025,
622 0,
623 1,
624 useIpv6),
628 "9.1.1.1",
629 "8.1.1.1",
630 4,
631 1035,
632 0,
633 1,
634 useIpv6),
638 "9.1.1.1",
639 "8.1.1.1",
640 4,
641 1234,
642 0,
643 1,
644 useIpv6),
648 "9.1.1.1",
649 "8.1.1.1",
650 4,
651 1024,
652 0,
653 1,
654 useIpv6),
658 "9.1.1.1",
659 "8.1.1.1",
660 4,
661 1025,
662 0,
663 1,
664 useIpv6),
668 "9.1.1.1",
669 "8.1.1.1",
670 4,
671 1035,
672 0,
673 1,
674 useIpv6),
676
677 // test local port
680 "9.1.1.1",
681 "8.1.1.1",
682 4,
683 3456,
684 0,
685 1,
686 useIpv6),
690 "9.1.1.1",
691 "8.1.1.1",
692 4,
693 3457,
694 0,
695 1,
696 useIpv6),
700 "9.1.1.1",
701 "8.1.1.1",
702 4,
703 3489,
704 0,
705 1,
706 useIpv6),
710 "9.1.1.1",
711 "8.1.1.1",
712 3456,
713 6,
714 0,
715 1,
716 useIpv6),
720 "9.1.1.1",
721 "8.1.1.1",
722 3461,
723 3461,
724 0,
725 1,
726 useIpv6),
730 "9.1.1.1",
731 "8.1.1.1",
732 9,
733 3489,
734 0,
735 1,
736 useIpv6),
738
739 ///////////////////////////////////////////
740 // check default TFT plus dedicated ones
741 ///////////////////////////////////////////
742
744 c3->Add(EpcTft::Default(), 1);
745 c3->Add(tft1_1, 2);
746 c3->Add(tft1_2, 3);
747
748 // --------------------------------classifier---direction--------src_addr---dst_addr---src_port--dst_port--ToS--TFT_id
749
750 // test IP addresses
753 "2.2.3.4",
754 "1.1.1.1",
755 4,
756 1234,
757 0,
758 2,
759 useIpv6),
763 "2.2.3.4",
764 "1.0.0.0",
765 2,
766 123,
767 5,
768 2,
769 useIpv6),
773 "6.2.3.4",
774 "1.1.1.1",
775 4,
776 1234,
777 0,
778 1,
779 useIpv6),
783 "3.3.3.4",
784 "4.4.4.1",
785 4,
786 1234,
787 0,
788 2,
789 useIpv6),
793 "3.3.4.4",
794 "4.4.4.1",
795 4,
796 1234,
797 0,
798 1,
799 useIpv6),
803 "3.3.3.4",
804 "4.4.2.1",
805 4,
806 1234,
807 0,
808 1,
809 useIpv6),
811
812 // test remote port
815 "9.1.1.1",
816 "8.1.1.1",
817 4,
818 1024,
819 0,
820 3,
821 useIpv6),
825 "9.1.1.1",
826 "8.1.1.1",
827 4,
828 1025,
829 0,
830 3,
831 useIpv6),
835 "9.1.1.1",
836 "8.1.1.1",
837 4,
838 1035,
839 0,
840 3,
841 useIpv6),
845 "9.1.1.1",
846 "8.1.1.1",
847 4,
848 1234,
849 0,
850 1,
851 useIpv6),
855 "9.1.1.1",
856 "8.1.1.1",
857 4,
858 1024,
859 0,
860 1,
861 useIpv6),
865 "9.1.1.1",
866 "8.1.1.1",
867 4,
868 1025,
869 0,
870 1,
871 useIpv6),
875 "9.1.1.1",
876 "8.1.1.1",
877 4,
878 1035,
879 0,
880 1,
881 useIpv6),
883
884 // test local port
887 "9.1.1.1",
888 "8.1.1.1",
889 4,
890 3456,
891 0,
892 1,
893 useIpv6),
897 "9.1.1.1",
898 "8.1.1.1",
899 4,
900 3457,
901 0,
902 1,
903 useIpv6),
907 "9.1.1.1",
908 "8.1.1.1",
909 4,
910 3489,
911 0,
912 1,
913 useIpv6),
917 "9.1.1.1",
918 "8.1.1.1",
919 3456,
920 6,
921 0,
922 3,
923 useIpv6),
927 "9.1.1.1",
928 "8.1.1.1",
929 3461,
930 3461,
931 0,
932 3,
933 useIpv6),
937 "9.1.1.1",
938 "8.1.1.1",
939 9,
940 3489,
941 0,
942 3,
943 useIpv6),
945
946 ///////////////////////////////////////////
947 // check two TFTs with different ports
948 ///////////////////////////////////////////
949
951 Ptr<EpcTft> tft4_1 = Create<EpcTft>();
952 tft4_1->Add(pf1_2_3);
953 c4->Add(tft4_1, 1);
954 Ptr<EpcTft> tft4_2 = Create<EpcTft>();
955 tft4_2->Add(pf1_2_4);
956 c4->Add(tft4_2, 2);
959 "9.1.1.1",
960 "8.1.1.1",
961 9,
962 3489,
963 0,
964 0,
965 useIpv6),
969 "9.1.1.1",
970 "8.1.1.1",
971 9,
972 7895,
973 0,
974 1,
975 useIpv6),
979 "9.1.1.1",
980 "8.1.1.1",
981 7895,
982 10,
983 0,
984 1,
985 useIpv6),
989 "9.1.1.1",
990 "8.1.1.1",
991 9,
992 5897,
993 0,
994 2,
995 useIpv6),
999 "9.1.1.1",
1000 "8.1.1.1",
1001 5897,
1002 10,
1003 0,
1004 2,
1005 useIpv6),
1007 }
1008}
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.
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition epc-tft.cc:218
Direction
Indicates the direction of the traffic that is to be classified.
Definition epc-tft.h:40
Ipv4 addresses are stored in host order in this class.
void Set(uint32_t address)
input address is in host order.
Packet header for IPv4.
Definition ipv4-header.h:23
static constexpr uint16_t PROT_NUMBER
Protocol number.
void Set(uint32_t mask)
input mask is in host order.
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:24
static constexpr uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Describes an IPv6 prefix.
static void Enable()
Enable the packet metadata.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1055
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1274
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
static constexpr auto UNIT
Definition test.h:1291
Packet header for UDP packets.
Definition udp-header.h:30
static constexpr uint8_t PROT_NUMBER
Protocol number (see http://www.iana.org/assignments/protocol-numbers)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:134
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:60
Ipv4Address localAddress
IPv4 address of the UE.
Definition epc-tft.h:110
Ipv6Prefix localIpv6Prefix
IPv6 address prefix of the UE.
Definition epc-tft.h:116
uint16_t localPortEnd
end of the port number range of the UE
Definition epc-tft.h:121
Ipv4Mask localMask
IPv4 address mask of the UE.
Definition epc-tft.h:111
uint16_t remotePortEnd
end of the port number range of the remote host
Definition epc-tft.h:119
Ipv6Address remoteIpv6Address
IPv6 address of the remote host.
Definition epc-tft.h:113
Ipv4Mask remoteMask
IPv4 address mask of the remote host.
Definition epc-tft.h:109
uint16_t remotePortStart
start of the port number range of the remote host
Definition epc-tft.h:118
Ipv6Address localIpv6Address
IPv6 address of the UE.
Definition epc-tft.h:115
Ipv4Address remoteAddress
IPv4 address of the remote host.
Definition epc-tft.h:108
Ipv6Prefix remoteIpv6Prefix
IPv6 address prefix of the remote host.
Definition epc-tft.h:114
uint16_t localPortStart
start of the port number range of the UE
Definition epc-tft.h:120