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:
18 * Nicola Baldo <nbaldo@cttc.es>
19 * Manuel Requena <manuel.requena@cttc.es>
20 */
21
22#include "ns3/epc-tft-classifier.h"
23#include "ns3/ipv4-header.h"
24#include "ns3/ipv4-l3-protocol.h"
25#include "ns3/ipv6-header.h"
26#include "ns3/ipv6-l3-protocol.h"
27#include "ns3/log.h"
28#include "ns3/packet.h"
29#include "ns3/tcp-header.h"
30#include "ns3/tcp-l4-protocol.h"
31#include "ns3/test.h"
32#include "ns3/udp-header.h"
33#include "ns3/udp-l4-protocol.h"
34
35#include <iomanip>
36
37using namespace ns3;
38
39NS_LOG_COMPONENT_DEFINE("TestEpcTftClassifier");
40
50{
51 public:
68 std::string sa,
69 std::string da,
70 uint16_t sp,
71 uint16_t dp,
72 uint8_t tos,
73 uint32_t tftId,
74 bool useIpv6);
75
77
78 private:
81 uint8_t m_tftId;
82 bool m_useIpv6;
87
102 static std::string BuildNameString(Ptr<EpcTftClassifier> c,
104 std::string sa,
105 std::string da,
106 uint16_t sp,
107 uint16_t dp,
108 uint8_t tos,
109 uint32_t tftId,
110 bool useIpv6);
111
112 void DoRun() override;
113};
114
117 std::string sa,
118 std::string da,
119 uint16_t sp,
120 uint16_t dp,
121 uint8_t tos,
122 uint32_t tftId,
123 bool useIpv6)
124 : TestCase(BuildNameString(c, d, sa, da, sp, dp, tos, tftId, useIpv6)),
125 m_c(c),
126 m_d(d),
127 m_tftId(tftId),
128 m_useIpv6(useIpv6)
129{
130 NS_LOG_FUNCTION(this << c << d << sa << da << sp << dp << tos << tftId << useIpv6);
131
132 if (m_useIpv6)
133 {
137 m_ipv6Header.SetPayloadLength(8); // Full UDP header
139 }
140 else
141 {
142 m_ipHeader.SetSource(Ipv4Address(sa.c_str()));
144 m_ipHeader.SetTos(tos);
145 m_ipHeader.SetPayloadSize(8); // Full UDP header
147 }
148
151}
152
154{
155}
156
157std::string
160 std::string sa,
161 std::string da,
162 uint16_t sp,
163 uint16_t dp,
164 uint8_t tos,
165 uint32_t tftId,
166 bool useIpv6)
167{
168 std::ostringstream oss;
169 oss << c << " d = " << d;
170 if (useIpv6)
171 {
172 oss << ", sa = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(sa.c_str()))
173 << ", da = " << Ipv6Address::MakeIpv4MappedAddress(Ipv4Address(da.c_str()));
174 }
175 else
176 {
177 oss << ", sa = " << sa << ", da = " << da;
178 }
179 oss << ", sp = " << sp << ", dp = " << dp << ", tos = 0x" << std::hex << (int)tos
180 << " --> tftId = " << tftId;
181 return oss.str();
182}
183
184void
186{
188
189 Ptr<Packet> udpPacket = Create<Packet>();
190 udpPacket->AddHeader(m_udpHeader);
191 if (m_useIpv6)
192 {
193 udpPacket->AddHeader(m_ipv6Header);
194 }
195 else
196 {
197 udpPacket->AddHeader(m_ipHeader);
198 }
199 NS_LOG_LOGIC(this << *udpPacket);
200 uint32_t obtainedTftId =
201 m_c->Classify(udpPacket,
202 m_d,
204 NS_TEST_ASSERT_MSG_EQ(obtainedTftId, (uint16_t)m_tftId, "bad classification of UDP packet");
205}
206
213{
214 public:
216};
217
223
225 : TestSuite("eps-tft-classifier", UNIT)
226{
227 NS_LOG_FUNCTION(this);
228
230 // Same testcases using IPv4 and IPv6 addresses
231 // IPv6 addresses are IPv4 mapped addresses, i.e. 1.2.3.4 -> 0::ffff:1.2.3.4
232 // Currently, we use the format '0::ffff:0102:0304' because
233 // the format '0::ffff:1.2.3.4' is not supported by the Ipv6Address class
235
236 for (bool useIpv6 : {false, true})
237 {
239 // check some TFT matches
241
242 Ptr<EpcTftClassifier> c1 = Create<EpcTftClassifier>();
243
244 Ptr<EpcTft> tft1_1 = Create<EpcTft>();
245
246 EpcTft::PacketFilter pf1_1_1;
247 if (useIpv6)
248 {
249 pf1_1_1.remoteIpv6Address.Set("0::ffff:0100:0000");
250 pf1_1_1.remoteIpv6Prefix = Ipv6Prefix(96 + 8);
251 pf1_1_1.localIpv6Address.Set("0::ffff:0200:0000");
252 pf1_1_1.localIpv6Prefix = Ipv6Prefix(96 + 8);
253 }
254 else
255 {
256 pf1_1_1.remoteAddress.Set("1.0.0.0");
257 pf1_1_1.remoteMask.Set(0xff000000);
258 pf1_1_1.localAddress.Set("2.0.0.0");
259 pf1_1_1.localMask.Set(0xff000000);
260 }
261 tft1_1->Add(pf1_1_1);
262
263 EpcTft::PacketFilter pf1_1_2;
264 if (useIpv6)
265 {
266 pf1_1_2.remoteIpv6Address.Set("0::ffff:0303:0300");
267 pf1_1_2.remoteIpv6Prefix = Ipv6Prefix(96 + 24);
268 pf1_1_2.localIpv6Address.Set("0::ffff:0404:0400");
269 pf1_1_2.localIpv6Prefix = Ipv6Prefix(96 + 24);
270 }
271 else
272 {
273 pf1_1_2.remoteAddress.Set("3.3.3.0");
274 pf1_1_2.remoteMask.Set(0xffffff00);
275 pf1_1_2.localAddress.Set("4.4.4.0");
276 pf1_1_2.localMask.Set(0xffffff00);
277 }
278 tft1_1->Add(pf1_1_2);
279
280 c1->Add(tft1_1, 1);
281
282 Ptr<EpcTft> tft1_2 = Create<EpcTft>();
283
284 EpcTft::PacketFilter pf1_2_1;
285 pf1_2_1.remotePortStart = 1024;
286 pf1_2_1.remotePortEnd = 1035;
287 tft1_2->Add(pf1_2_1);
288
289 EpcTft::PacketFilter pf1_2_2;
290 pf1_2_2.localPortStart = 3456;
291 pf1_2_2.localPortEnd = 3489;
292 tft1_2->Add(pf1_2_2);
293
294 EpcTft::PacketFilter pf1_2_3;
295 pf1_2_3.localPortStart = 7895;
296 pf1_2_3.localPortEnd = 7895;
297 tft1_2->Add(pf1_2_3);
298
299 EpcTft::PacketFilter pf1_2_4;
300 pf1_2_4.remotePortStart = 5897;
301 pf1_2_4.remotePortEnd = 5897;
302 tft1_2->Add(pf1_2_4);
303
304 c1->Add(tft1_2, 2);
305
306 // --------------------------------classifier----direction-------src_addr---dst_addr--src_port--dst_port--ToS--TFT_id
307
308 // test IP addresses
311 "2.2.3.4",
312 "1.1.1.1",
313 4,
314 1234,
315 0,
316 1,
317 useIpv6),
321 "2.2.3.4",
322 "1.0.0.0",
323 2,
324 123,
325 5,
326 1,
327 useIpv6),
331 "6.2.3.4",
332 "1.1.1.1",
333 4,
334 1234,
335 0,
336 0,
337 useIpv6),
341 "3.3.3.4",
342 "4.4.4.1",
343 4,
344 1234,
345 0,
346 1,
347 useIpv6),
351 "3.3.4.4",
352 "4.4.4.1",
353 4,
354 1234,
355 0,
356 0,
357 useIpv6),
361 "3.3.3.4",
362 "4.4.2.1",
363 4,
364 1234,
365 0,
366 0,
367 useIpv6),
369
370 // test remote port
373 "9.1.1.1",
374 "8.1.1.1",
375 4,
376 1024,
377 0,
378 2,
379 useIpv6),
383 "9.1.1.1",
384 "8.1.1.1",
385 4,
386 1025,
387 0,
388 2,
389 useIpv6),
393 "9.1.1.1",
394 "8.1.1.1",
395 4,
396 1035,
397 0,
398 2,
399 useIpv6),
403 "9.1.1.1",
404 "8.1.1.1",
405 4,
406 1234,
407 0,
408 0,
409 useIpv6),
413 "9.1.1.1",
414 "8.1.1.1",
415 4,
416 1024,
417 0,
418 0,
419 useIpv6),
423 "9.1.1.1",
424 "8.1.1.1",
425 4,
426 1025,
427 0,
428 0,
429 useIpv6),
433 "9.1.1.1",
434 "8.1.1.1",
435 4,
436 1035,
437 0,
438 0,
439 useIpv6),
441
442 // test local port
445 "9.1.1.1",
446 "8.1.1.1",
447 4,
448 3456,
449 0,
450 0,
451 useIpv6),
455 "9.1.1.1",
456 "8.1.1.1",
457 4,
458 3457,
459 0,
460 0,
461 useIpv6),
465 "9.1.1.1",
466 "8.1.1.1",
467 4,
468 3489,
469 0,
470 0,
471 useIpv6),
475 "9.1.1.1",
476 "8.1.1.1",
477 3456,
478 6,
479 0,
480 2,
481 useIpv6),
485 "9.1.1.1",
486 "8.1.1.1",
487 3461,
488 3461,
489 0,
490 2,
491 useIpv6),
495 "9.1.1.1",
496 "8.1.1.1",
497 9,
498 3489,
499 0,
500 2,
501 useIpv6),
505 "9.1.1.1",
506 "8.1.1.1",
507 9,
508 7895,
509 0,
510 2,
511 useIpv6),
515 "9.1.1.1",
516 "8.1.1.1",
517 7895,
518 10,
519 0,
520 2,
521 useIpv6),
525 "9.1.1.1",
526 "8.1.1.1",
527 9,
528 5897,
529 0,
530 2,
531 useIpv6),
535 "9.1.1.1",
536 "8.1.1.1",
537 5897,
538 10,
539 0,
540 2,
541 useIpv6),
543
545 // check default TFT
547
548 Ptr<EpcTftClassifier> c2 = Create<EpcTftClassifier>();
549 c2->Add(EpcTft::Default(), 1);
550
551 // --------------------------------classifier---direction--------src_addr---dst_addr--src_port--dst_port--ToS--TFT
552 // id
553
554 // test IP addresses
557 "2.2.3.4",
558 "1.1.1.1",
559 4,
560 1234,
561 0,
562 1,
563 useIpv6),
567 "2.2.3.4",
568 "1.0.0.0",
569 2,
570 123,
571 5,
572 1,
573 useIpv6),
577 "6.2.3.4",
578 "1.1.1.1",
579 4,
580 1234,
581 0,
582 1,
583 useIpv6),
587 "3.3.3.4",
588 "4.4.4.1",
589 4,
590 1234,
591 0,
592 1,
593 useIpv6),
597 "3.3.4.4",
598 "4.4.4.1",
599 4,
600 1234,
601 0,
602 1,
603 useIpv6),
607 "3.3.3.4",
608 "4.4.2.1",
609 4,
610 1234,
611 0,
612 1,
613 useIpv6),
615
616 // test remote port
619 "9.1.1.1",
620 "8.1.1.1",
621 4,
622 1024,
623 0,
624 1,
625 useIpv6),
629 "9.1.1.1",
630 "8.1.1.1",
631 4,
632 1025,
633 0,
634 1,
635 useIpv6),
639 "9.1.1.1",
640 "8.1.1.1",
641 4,
642 1035,
643 0,
644 1,
645 useIpv6),
649 "9.1.1.1",
650 "8.1.1.1",
651 4,
652 1234,
653 0,
654 1,
655 useIpv6),
659 "9.1.1.1",
660 "8.1.1.1",
661 4,
662 1024,
663 0,
664 1,
665 useIpv6),
669 "9.1.1.1",
670 "8.1.1.1",
671 4,
672 1025,
673 0,
674 1,
675 useIpv6),
679 "9.1.1.1",
680 "8.1.1.1",
681 4,
682 1035,
683 0,
684 1,
685 useIpv6),
687
688 // test local port
691 "9.1.1.1",
692 "8.1.1.1",
693 4,
694 3456,
695 0,
696 1,
697 useIpv6),
701 "9.1.1.1",
702 "8.1.1.1",
703 4,
704 3457,
705 0,
706 1,
707 useIpv6),
711 "9.1.1.1",
712 "8.1.1.1",
713 4,
714 3489,
715 0,
716 1,
717 useIpv6),
721 "9.1.1.1",
722 "8.1.1.1",
723 3456,
724 6,
725 0,
726 1,
727 useIpv6),
731 "9.1.1.1",
732 "8.1.1.1",
733 3461,
734 3461,
735 0,
736 1,
737 useIpv6),
741 "9.1.1.1",
742 "8.1.1.1",
743 9,
744 3489,
745 0,
746 1,
747 useIpv6),
749
751 // check default TFT plus dedicated ones
753
754 Ptr<EpcTftClassifier> c3 = Create<EpcTftClassifier>();
755 c3->Add(EpcTft::Default(), 1);
756 c3->Add(tft1_1, 2);
757 c3->Add(tft1_2, 3);
758
759 // --------------------------------classifier---direction--------src_addr---dst_addr---src_port--dst_port--ToS--TFT_id
760
761 // test IP addresses
764 "2.2.3.4",
765 "1.1.1.1",
766 4,
767 1234,
768 0,
769 2,
770 useIpv6),
774 "2.2.3.4",
775 "1.0.0.0",
776 2,
777 123,
778 5,
779 2,
780 useIpv6),
784 "6.2.3.4",
785 "1.1.1.1",
786 4,
787 1234,
788 0,
789 1,
790 useIpv6),
794 "3.3.3.4",
795 "4.4.4.1",
796 4,
797 1234,
798 0,
799 2,
800 useIpv6),
804 "3.3.4.4",
805 "4.4.4.1",
806 4,
807 1234,
808 0,
809 1,
810 useIpv6),
814 "3.3.3.4",
815 "4.4.2.1",
816 4,
817 1234,
818 0,
819 1,
820 useIpv6),
822
823 // test remote port
826 "9.1.1.1",
827 "8.1.1.1",
828 4,
829 1024,
830 0,
831 3,
832 useIpv6),
836 "9.1.1.1",
837 "8.1.1.1",
838 4,
839 1025,
840 0,
841 3,
842 useIpv6),
846 "9.1.1.1",
847 "8.1.1.1",
848 4,
849 1035,
850 0,
851 3,
852 useIpv6),
856 "9.1.1.1",
857 "8.1.1.1",
858 4,
859 1234,
860 0,
861 1,
862 useIpv6),
866 "9.1.1.1",
867 "8.1.1.1",
868 4,
869 1024,
870 0,
871 1,
872 useIpv6),
876 "9.1.1.1",
877 "8.1.1.1",
878 4,
879 1025,
880 0,
881 1,
882 useIpv6),
886 "9.1.1.1",
887 "8.1.1.1",
888 4,
889 1035,
890 0,
891 1,
892 useIpv6),
894
895 // test local port
898 "9.1.1.1",
899 "8.1.1.1",
900 4,
901 3456,
902 0,
903 1,
904 useIpv6),
908 "9.1.1.1",
909 "8.1.1.1",
910 4,
911 3457,
912 0,
913 1,
914 useIpv6),
918 "9.1.1.1",
919 "8.1.1.1",
920 4,
921 3489,
922 0,
923 1,
924 useIpv6),
928 "9.1.1.1",
929 "8.1.1.1",
930 3456,
931 6,
932 0,
933 3,
934 useIpv6),
938 "9.1.1.1",
939 "8.1.1.1",
940 3461,
941 3461,
942 0,
943 3,
944 useIpv6),
948 "9.1.1.1",
949 "8.1.1.1",
950 9,
951 3489,
952 0,
953 3,
954 useIpv6),
956
958 // check two TFTs with different ports
960
961 Ptr<EpcTftClassifier> c4 = Create<EpcTftClassifier>();
962 Ptr<EpcTft> tft4_1 = Create<EpcTft>();
963 tft4_1->Add(pf1_2_3);
964 c4->Add(tft4_1, 1);
965 Ptr<EpcTft> tft4_2 = Create<EpcTft>();
966 tft4_2->Add(pf1_2_4);
967 c4->Add(tft4_2, 2);
970 "9.1.1.1",
971 "8.1.1.1",
972 9,
973 3489,
974 0,
975 0,
976 useIpv6),
980 "9.1.1.1",
981 "8.1.1.1",
982 9,
983 7895,
984 0,
985 1,
986 useIpv6),
990 "9.1.1.1",
991 "8.1.1.1",
992 7895,
993 10,
994 0,
995 1,
996 useIpv6),
1000 "9.1.1.1",
1001 "8.1.1.1",
1002 9,
1003 5897,
1004 0,
1005 2,
1006 useIpv6),
1010 "9.1.1.1",
1011 "8.1.1.1",
1012 5897,
1013 10,
1014 0,
1015 2,
1016 useIpv6),
1018 }
1019}
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:77
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
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:42
void SetDestinationPort(uint16_t port)
Definition: udp-header.cc:36
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