A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-mesh-under-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 SRM Institute of Science and Technology, India
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Usham Roy <ushamroy80@gmail.com>
7 */
8
9#include "mock-net-device.h"
10
11#include "ns3/boolean.h"
12#include "ns3/iana-ieee802-numbers.h"
13#include "ns3/mac16-address.h"
14#include "ns3/mac48-address.h"
15#include "ns3/node.h"
16#include "ns3/packet.h"
17#include "ns3/simulator.h"
18#include "ns3/sixlowpan-header.h"
19#include "ns3/sixlowpan-mesh-under-routing.h"
20#include "ns3/sixlowpan-net-device.h"
21#include "ns3/sixlowpan-simple-flooding.h"
22#include "ns3/test.h"
23#include "ns3/uinteger.h"
24
25#include <vector>
26
27using namespace ns3;
28
29/**
30 * @ingroup sixlowpan-tests
31 *
32 * @brief Verify the FIFO drop policy of the duplicate-detection cache.
33 *
34 * The base-class cache keeps at most MeshCacheLength entries per
35 * originator. Once that capacity is reached, the oldest entry is
36 * dropped on each new insertion (FIFO drop policy).
37 */
39{
40 public:
42 : TestCase("Duplicate cache drops oldest entry when full")
43 {
44 }
45
46 private:
47 void DoRun() override
48 {
50 policy->SetAttribute("MeshCacheLength", UintegerValue(3));
51
52 Mac16Address orig("00:01");
53
54 policy->RecordPacket(orig, 1);
55 policy->RecordPacket(orig, 2);
56 policy->RecordPacket(orig, 3);
57
58 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(orig, 1), true, "seq 1 should be cached");
59 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(orig, 2), true, "seq 2 should be cached");
60 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(orig, 3), true, "seq 3 should be cached");
61
62 // Insert seq 4 -- the oldest entry (seq 1) is dropped.
63 policy->RecordPacket(orig, 4);
64
65 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(orig, 1),
66 false,
67 "seq 1 should have been dropped (FIFO)");
68 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(orig, 4), true, "seq 4 should be cached");
69 }
70};
71
72/**
73 * @ingroup sixlowpan-tests
74 *
75 * @brief Verify per-originator cache partitioning under overflow.
76 *
77 * Each originator has its own FIFO. Overflowing one originator's cache
78 * must drop only that originator's oldest entry; it must never drop an
79 * entry belonging to a different originator.
80 */
82{
83 public:
85 : TestCase("Overflowing one originator does not drop another's entries")
86 {
87 }
88
89 private:
90 void DoRun() override
91 {
93 policy->SetAttribute("MeshCacheLength", UintegerValue(2));
94
95 Mac16Address origA("00:01");
96 Mac16Address origB("00:02");
97
98 // Fill origB to capacity, then push origA one past capacity.
99 policy->RecordPacket(origB, 1);
100 policy->RecordPacket(origB, 2);
101 policy->RecordPacket(origA, 1);
102 policy->RecordPacket(origA, 2);
103 policy->RecordPacket(origA, 3); // origA overflows: its oldest (seq 1) is dropped
104
105 // The overflow dropped only origA's oldest entry.
106 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(origA, 1), false, "origA seq 1 dropped (FIFO)");
107 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(origA, 2), true, "origA seq 2 still cached");
108 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(origA, 3), true, "origA seq 3 cached");
109
110 // origB's entries are untouched by origA's overflow.
111 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(origB, 1), true, "origB seq 1 untouched");
112 NS_TEST_ASSERT_MSG_EQ(policy->IsDuplicate(origB, 2), true, "origB seq 2 untouched");
113 }
114};
115
116/**
117 * @ingroup sixlowpan-tests
118 *
119 * @brief Verify the default policy schedules and invokes the forward callback.
120 */
122{
123 public:
125 : TestCase("SimpleFlooding invokes the forward callback once")
126 {
127 }
128
129 private:
130 /**
131 * @brief Callback used to capture forward invocations.
132 * @param packet The forwarded packet.
133 */
135 {
136 m_forwardedPacket = packet;
138 }
139
140 void DoRun() override
141 {
143 policy->AssignStreams(1);
144
145 Ptr<Packet> packet = Create<Packet>(64);
146 Mac16Address orig("00:01");
147
150
151 policy->OnPacketForward(packet, orig, /*seqNo=*/1, /*hopsLeft=*/5, cb);
152
155
156 NS_TEST_ASSERT_MSG_EQ(m_forwardCount, 1, "Forward callback should fire exactly once");
157 NS_TEST_ASSERT_MSG_EQ(m_forwardedPacket, packet, "Same packet pointer should be forwarded");
158 }
159
160 void DoTeardown() override
161 {
163 }
164
165 Ptr<Packet> m_forwardedPacket; ///< Packet captured at the forward callback.
166 int m_forwardCount{0}; ///< Number of times the forward callback was invoked.
167};
168
169/**
170 * @ingroup sixlowpan-tests
171 *
172 * @brief Base for device-level mesh-under tests.
173 *
174 * Builds a SixLowPanNetDevice over a MockNetDevice, injects mesh frames
175 * through the underlying device and captures both the frames the device
176 * re-broadcasts and the packets it delivers locally. Subclasses exercise
177 * the device public API end to end, verifying that the policy
178 * delegation preserves the historical device behavior.
179 */
181{
182 public:
183 /**
184 * @brief Constructor.
185 * @param name The test case name.
186 */
187 MeshUnderDeviceTestCase(std::string name)
188 : TestCase(name)
189 {
190 }
191
192 protected:
193 /**
194 * @brief Build the node, the underlying MockNetDevice and the 6LoWPAN device.
195 *
196 * The underlying device gets the MAC address 00:00:00:00:00:01, so the
197 * node's 16-bit mesh address is 00:01.
198 *
199 * @param useMesh The device's UseMeshUnder attribute (mesh-under membership).
200 * @param forwardMesh The device's ForwardMesh attribute (relaying).
201 */
202 void SetupDevice(bool useMesh = true, bool forwardMesh = true)
203 {
205
207 node->AddDevice(m_mock);
208 m_mock->SetNode(node);
209 m_mock->SetAddress(Mac48Address("00:00:00:00:00:01"));
210 m_mock->SetMtu(150);
212
214 node->AddDevice(m_dev);
215 m_dev->SetNetDevice(m_mock);
216 m_dev->SetAttribute("UseMeshUnder", BooleanValue(useMesh));
217 m_dev->SetAttribute("ForwardMesh", BooleanValue(forwardMesh));
218 m_dev->SetReceiveCallback(MakeCallback(&MeshUnderDeviceTestCase::CaptureUp, this));
219 }
220
221 /**
222 * @brief Build a mesh frame (MESH + BC0 + uncompressed IPv6 payload).
223 *
224 * @param originator The MESH originator address.
225 * @param finalDst The MESH final destination address.
226 * @param hopsLeft The MESH hops-left value.
227 * @param seqNo The BC0 sequence number.
228 * @return The assembled frame.
229 */
231 Mac16Address finalDst,
232 uint8_t hopsLeft,
233 uint8_t seqNo)
234 {
235 Ptr<Packet> packet = Create<Packet>(40);
236
237 SixLowPanIpv6 uncompressedHdr;
238 packet->AddHeader(uncompressedHdr);
239
240 SixLowPanBc0 bc0Hdr;
241 bc0Hdr.SetSequenceNumber(seqNo);
242 packet->AddHeader(bc0Hdr);
243
244 SixLowPanMesh meshHdr;
245 meshHdr.SetOriginator(originator);
246 meshHdr.SetFinalDst(finalDst);
247 meshHdr.SetHopsLeft(hopsLeft);
248 packet->AddHeader(meshHdr);
249
250 return packet;
251 }
252
253 /**
254 * @brief Schedule the injection of a frame, as if received from the channel.
255 *
256 * The event is scheduled with the node's context, as a channel would.
257 *
258 * @param when The injection time.
259 * @param packet The frame to inject.
260 */
261 void ScheduleInject(Time when, Ptr<Packet> packet)
262 {
263 Simulator::ScheduleWithContext(m_mock->GetNode()->GetId(),
264 when,
266 m_mock,
267 packet,
268 uint16_t{iana::ieee802numbers::LoWPAN},
269 m_mock->GetBroadcast(),
270 Address(Mac48Address("00:00:00:00:00:02")),
272 }
273
274 /**
275 * @brief Capture a frame the device re-broadcasts.
276 * @param device The sending device.
277 * @param packet The transmitted frame.
278 * @param protocol The protocol number.
279 * @param source The source address.
280 * @param destination The destination address.
281 * @param packetType The packet type.
282 * @return true
283 */
285 Ptr<const Packet> packet,
286 uint16_t protocol,
287 const Address& source,
288 const Address& destination,
289 NetDevice::PacketType packetType)
290 {
291 m_sentFrames.push_back(packet->Copy());
292 return true;
293 }
294
295 /**
296 * @brief Capture a locally delivered packet.
297 * @param device The receiving device.
298 * @param packet The delivered packet.
299 * @param protocol The protocol number.
300 * @param source The source address.
301 * @return true
302 */
304 Ptr<const Packet> packet,
305 uint16_t protocol,
306 const Address& source)
307 {
309 return true;
310 }
311
312 void DoTeardown() override
313 {
314 m_dev = nullptr;
315 m_mock = nullptr;
317 }
318
319 Ptr<MockNetDevice> m_mock; ///< Underlying (mock) device.
320 Ptr<SixLowPanNetDevice> m_dev; ///< Device under test.
321 std::vector<Ptr<Packet>> m_sentFrames; ///< Frames re-broadcast by the device.
322 uint32_t m_deliveredCount{0}; ///< Packets delivered locally.
323};
324
325/**
326 * @ingroup sixlowpan-tests
327 *
328 * @brief The device forwards a new mesh frame once and drops duplicates.
329 */
331{
332 public:
334 : MeshUnderDeviceTestCase("Device forwards new mesh frames once, with decremented hops")
335 {
336 }
337
338 private:
339 void DoRun() override
340 {
341 SetupDevice();
342
343 Mac16Address originator("00:02");
344 Mac16Address finalDst("00:03"); // Another node: to be forwarded, not delivered.
345
347 BuildMeshFrame(originator, finalDst, /*hopsLeft=*/5, /*seqNo=*/1));
348 // The same (originator, sequence) pair again: a duplicate.
350 BuildMeshFrame(originator, finalDst, /*hopsLeft=*/5, /*seqNo=*/1));
351
354
355 NS_TEST_ASSERT_MSG_EQ(m_sentFrames.size(), 1, "One forward for two copies (dedup)");
356 NS_TEST_ASSERT_MSG_EQ(m_deliveredCount, 0, "Frame for another node must not be delivered");
357
358 if (!m_sentFrames.empty())
359 {
360 SixLowPanMesh meshHdr;
361 SixLowPanBc0 bc0Hdr;
362 m_sentFrames[0]->RemoveHeader(meshHdr);
363 m_sentFrames[0]->RemoveHeader(bc0Hdr);
364 NS_TEST_ASSERT_MSG_EQ(meshHdr.GetHopsLeft(), 4, "Hops left must be decremented");
366 Address(originator),
367 "Originator preserved");
368 NS_TEST_ASSERT_MSG_EQ(meshHdr.GetFinalDst(), Address(finalDst), "Final dst preserved");
369 NS_TEST_ASSERT_MSG_EQ(bc0Hdr.GetSequenceNumber(), 1, "Sequence number preserved");
370 }
371 }
372};
373
374/**
375 * @ingroup sixlowpan-tests
376 *
377 * @brief A mesh frame destined to the node is delivered locally.
378 *
379 * A node in the mesh (UseMeshUnder enabled) must decode and deliver a mesh
380 * frame addressed to it, and must not re-broadcast a unicast frame it
381 * is the destination of.
382 */
384{
385 public:
387 : MeshUnderDeviceTestCase("Mesh frame for this node is delivered")
388 {
389 }
390
391 private:
392 void DoRun() override
393 {
394 SetupDevice();
395
396 Mac16Address originator("00:02");
397 Mac16Address finalDst("00:01"); // This node.
398
400 BuildMeshFrame(originator, finalDst, /*hopsLeft=*/5, /*seqNo=*/1));
401
404
405 NS_TEST_ASSERT_MSG_EQ(m_deliveredCount, 1, "Frame for this node must be delivered");
406 NS_TEST_ASSERT_MSG_EQ(m_sentFrames.size(), 0, "Unicast frame for this node: no forward");
407 }
408};
409
410/**
411 * @ingroup sixlowpan-tests
412 *
413 * @brief Hop limit and broadcast handling on the receive path.
414 */
416{
417 public:
419 : MeshUnderDeviceTestCase("Hop limit is honored; broadcast is forwarded and delivered")
420 {
421 }
422
423 private:
424 void DoRun() override
425 {
426 SetupDevice();
427
428 Mac16Address originator("00:02");
429
430 // Exhausted hop count: must not be forwarded.
432 BuildMeshFrame(originator,
433 Mac16Address("00:03"),
434 /*hopsLeft=*/0,
435 /*seqNo=*/1));
436 // Broadcast: must be forwarded and delivered.
438 BuildMeshFrame(originator,
439 Mac16Address("ff:ff"),
440 /*hopsLeft=*/3,
441 /*seqNo=*/2));
442
445
446 NS_TEST_ASSERT_MSG_EQ(m_sentFrames.size(), 1, "Only the broadcast frame is forwarded");
447 NS_TEST_ASSERT_MSG_EQ(m_deliveredCount, 1, "The broadcast frame is also delivered");
448
449 if (!m_sentFrames.empty())
450 {
451 SixLowPanMesh meshHdr;
452 m_sentFrames[0]->RemoveHeader(meshHdr);
453 NS_TEST_ASSERT_MSG_EQ(meshHdr.GetHopsLeft(), 2, "Hops left must be decremented");
454 }
455 }
456};
457
458/**
459 * @ingroup sixlowpan-tests
460 *
461 * @brief A node outside the mesh receiving a mesh frame reports and drops it.
462 *
463 * With UseMeshUnder disabled, a received mesh-under frame is a network
464 * misconfiguration: it must be dropped (DROP_MESH_NOT_ENABLED), not
465 * delivered and not forwarded.
466 */
468{
469 public:
471 : MeshUnderDeviceTestCase("Mesh frame without UseMeshUnder is reported and dropped")
472 {
473 }
474
475 private:
476 /**
477 * @brief Capture drop-trace invocations.
478 * @param reason The drop reason.
479 * @param packet The dropped packet.
480 * @param device The dropping device.
481 * @param ifindex The interface index.
482 */
484 Ptr<const Packet> packet,
486 uint32_t ifindex)
487 {
488 m_dropCount++;
489 m_lastDropReason = reason;
490 }
491
492 void DoRun() override
493 {
494 SetupDevice(/*useMesh=*/false);
495 m_dev->TraceConnectWithoutContext(
496 "Drop",
498
499 // A mesh frame addressed to this very node: it must still be dropped.
502 Mac16Address("00:01"),
503 /*hopsLeft=*/5,
504 /*seqNo=*/1));
505
508
510 0,
511 "Frame must not be delivered without UseMeshUnder");
513 0,
514 "Frame must not be forwarded without UseMeshUnder");
515 NS_TEST_ASSERT_MSG_EQ(m_dropCount, 1, "The drop must be reported on the Drop trace");
518 "The drop reason must be DROP_MESH_NOT_ENABLED");
519 }
520
521 uint32_t m_dropCount{0}; ///< Number of drop-trace invocations.
524};
525
526/**
527 * @ingroup sixlowpan-tests
528 *
529 * @brief A node in the mesh with ForwardMesh disabled receives but does not relay.
530 */
532{
533 public:
535 : MeshUnderDeviceTestCase("Node with ForwardMesh disabled delivers but does not relay")
536 {
537 }
538
539 private:
540 void DoRun() override
541 {
542 SetupDevice(/*useMesh=*/true, /*forwardMesh=*/false);
543
544 Mac16Address originator("00:02");
545
546 // A frame for another node: without ForwardMesh it goes nowhere.
548 BuildMeshFrame(originator,
549 Mac16Address("00:03"),
550 /*hopsLeft=*/5,
551 /*seqNo=*/1));
552 // A broadcast frame: delivered locally, but still not relayed.
554 BuildMeshFrame(originator,
555 Mac16Address("ff:ff"),
556 /*hopsLeft=*/5,
557 /*seqNo=*/2));
558
561
562 NS_TEST_ASSERT_MSG_EQ(m_sentFrames.size(), 0, "No relaying with ForwardMesh disabled");
563 NS_TEST_ASSERT_MSG_EQ(m_deliveredCount, 1, "The broadcast frame is still delivered");
564 }
565};
566
567/**
568 * @ingroup sixlowpan-tests
569 *
570 * @brief Three-node chain: the middle node decides whether the far node is reached.
571 *
572 * A frame from node A (00:02) to node C (00:03) arrives at the middle
573 * node B (00:01) only; whatever B transmits reaches C. When B is part
574 * of the mesh and forwards, C receives the packet. When B is outside
575 * the mesh, C receives nothing.
576 */
578{
579 public:
580 /**
581 * @brief Constructor.
582 * @param middleInMesh Whether the middle node takes part in the mesh.
583 */
585 : MeshUnderDeviceTestCase(middleInMesh
586 ? "3-node chain: middle node relays to the far node"
587 : "3-node chain: middle node outside the mesh, no relay"),
588 m_middleInMesh(middleInMesh)
589 {
590 }
591
592 private:
593 /**
594 * @brief Deliver whatever the middle node transmits to the far node,
595 * as a channel would.
596 * @param device The sending device.
597 * @param packet The transmitted frame.
598 * @param protocol The protocol number.
599 * @param source The source address.
600 * @param destination The destination address.
601 * @param packetType The packet type.
602 * @return true
603 */
605 Ptr<const Packet> packet,
606 uint16_t protocol,
607 const Address& source,
608 const Address& destination,
609 NetDevice::PacketType packetType)
610 {
611 Simulator::ScheduleWithContext(m_mockFar->GetNode()->GetId(),
612 MicroSeconds(100),
614 m_mockFar,
615 packet->Copy(),
616 protocol,
617 m_mockFar->GetBroadcast(),
618 source,
620 return true;
621 }
622
623 /**
624 * @brief Count packets delivered on the far node.
625 * @param device The receiving device.
626 * @param packet The delivered packet.
627 * @param protocol The protocol number.
628 * @param source The source address.
629 * @return true
630 */
632 Ptr<const Packet> packet,
633 uint16_t protocol,
634 const Address& source)
635 {
637 return true;
638 }
639
640 void DoRun() override
641 {
642 // Middle node (B, 00:01): the base fixture device.
643 SetupDevice(/*useMesh=*/m_middleInMesh, /*forwardMesh=*/true);
645
646 // Far node (C, 00:03).
647 Ptr<Node> nodeFar = CreateObject<Node>();
649 nodeFar->AddDevice(m_mockFar);
650 m_mockFar->SetNode(nodeFar);
651 m_mockFar->SetAddress(Mac48Address("00:00:00:00:00:03"));
652 m_mockFar->SetMtu(150);
654 nodeFar->AddDevice(m_devFar);
655 m_devFar->SetNetDevice(m_mockFar);
656 m_devFar->SetAttribute("UseMeshUnder", BooleanValue(true));
657 m_devFar->SetReceiveCallback(
659
660 // A frame from A (00:02) to C (00:03) arrives at B only.
663 Mac16Address("00:03"),
664 /*hopsLeft=*/5,
665 /*seqNo=*/1));
666
669
671 (m_middleInMesh ? 1 : 0),
672 "Far node delivery depends on the middle node relaying");
673 NS_TEST_ASSERT_MSG_EQ(m_deliveredCount, 0, "The frame is not for the middle node");
674 }
675
676 void DoTeardown() override
677 {
678 m_devFar = nullptr;
679 m_mockFar = nullptr;
681 }
682
683 bool m_middleInMesh; ///< Whether the middle node takes part in the mesh.
684 Ptr<MockNetDevice> m_mockFar; ///< Far node underlying (mock) device.
685 Ptr<SixLowPanNetDevice> m_devFar; ///< Far node device under test.
686 uint32_t m_deliveredFar{0}; ///< Packets delivered on the far node.
687};
688
689/**
690 * @ingroup sixlowpan-tests
691 *
692 * @brief The device default policy and stream assignment match the
693 * historical behavior.
694 */
696{
697 public:
699 : TestCase("Default policy exists at construction; AssignStreams returns 2")
700 {
701 }
702
703 private:
704 void DoRun() override
705 {
707
708 // The MeshUnderRouting attribute default provides a policy at
709 // construction, so stream assignment is effective during setup.
710 Ptr<SixLowPanMeshUnderRouting> policy = dev->GetMeshUnderRouting();
711 NS_TEST_ASSERT_MSG_NE(policy, nullptr, "Default policy must exist at construction");
713 nullptr,
714 "Default policy must be SixLowPanSimpleFlooding");
715
716 // The historical implementation assigned two streams (device RNG and
717 // forwarding jitter).
718 NS_TEST_ASSERT_MSG_EQ(dev->AssignStreams(7), 2, "Two streams, as before the refactoring");
719 }
720
721 void DoTeardown() override
722 {
724 }
725};
726
727/**
728 * @ingroup sixlowpan-tests
729 *
730 * @brief 6LoWPAN mesh-under forwarding test suite.
731 */
751
752/// Static suite registration.
Verify the FIFO drop policy of the duplicate-detection cache.
void DoRun() override
Implementation to actually run this TestCase.
Verify per-originator cache partitioning under overflow.
void DoRun() override
Implementation to actually run this TestCase.
Three-node chain: the middle node decides whether the far node is reached.
bool RelayToFarNode(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, NetDevice::PacketType packetType)
Deliver whatever the middle node transmits to the far node, as a channel would.
void DoRun() override
Implementation to actually run this TestCase.
bool CaptureUpFar(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source)
Count packets delivered on the far node.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
bool m_middleInMesh
Whether the middle node takes part in the mesh.
MeshUnderChainRelayTestCase(bool middleInMesh)
Constructor.
Ptr< SixLowPanNetDevice > m_devFar
Far node device under test.
uint32_t m_deliveredFar
Packets delivered on the far node.
Ptr< MockNetDevice > m_mockFar
Far node underlying (mock) device.
A mesh frame destined to the node is delivered locally.
void DoRun() override
Implementation to actually run this TestCase.
The device forwards a new mesh frame once and drops duplicates.
void DoRun() override
Implementation to actually run this TestCase.
Hop limit and broadcast handling on the receive path.
void DoRun() override
Implementation to actually run this TestCase.
A node outside the mesh receiving a mesh frame reports and drops it.
void CaptureDrop(SixLowPanNetDevice::DropReason reason, Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > device, uint32_t ifindex)
Capture drop-trace invocations.
uint32_t m_dropCount
Number of drop-trace invocations.
void DoRun() override
Implementation to actually run this TestCase.
SixLowPanNetDevice::DropReason m_lastDropReason
Last reported drop reason.
A node in the mesh with ForwardMesh disabled receives but does not relay.
void DoRun() override
Implementation to actually run this TestCase.
The device default policy and stream assignment match the historical behavior.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
bool CaptureSend(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, NetDevice::PacketType packetType)
Capture a frame the device re-broadcasts.
std::vector< Ptr< Packet > > m_sentFrames
Frames re-broadcast by the device.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void SetupDevice(bool useMesh=true, bool forwardMesh=true)
Build the node, the underlying MockNetDevice and the 6LoWPAN device.
Ptr< SixLowPanNetDevice > m_dev
Device under test.
bool CaptureUp(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source)
Capture a locally delivered packet.
MeshUnderDeviceTestCase(std::string name)
Constructor.
static Ptr< Packet > BuildMeshFrame(Mac16Address originator, Mac16Address finalDst, uint8_t hopsLeft, uint8_t seqNo)
Build a mesh frame (MESH + BC0 + uncompressed IPv6 payload).
void ScheduleInject(Time when, Ptr< Packet > packet)
Schedule the injection of a frame, as if received from the channel.
uint32_t m_deliveredCount
Packets delivered locally.
Ptr< MockNetDevice > m_mock
Underlying (mock) device.
Verify the default policy schedules and invokes the forward callback.
int m_forwardCount
Number of times the forward callback was invoked.
Ptr< Packet > m_forwardedPacket
Packet captured at the forward callback.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void RecordForward(Ptr< Packet > packet)
Callback used to capture forward invocations.
void DoRun() override
Implementation to actually run this TestCase.
6LoWPAN mesh-under forwarding test suite.
a polymophic address class
Definition address.h:114
This class can contain 16 bit addresses.
an EUI-48 address
void Receive(Ptr< Packet > packet, uint16_t protocol, Address to, Address from, NetDevice::PacketType packetType)
Pretend that a packet has been received from a connected Channel.
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:314
@ PACKET_BROADCAST
Packet addressed to all.
Definition net-device.h:317
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:597
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
6LoWPAN BC0 header - see RFC 4944.
void SetSequenceNumber(uint8_t seqNumber)
Set the "Sequence Number" field.
uint8_t GetSequenceNumber() const
Get the "Sequence Number" field.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
6LoWPAN Mesh header - see RFC 4944.
Address GetOriginator() const
Get the "Originator" address.
void SetHopsLeft(uint8_t hopsLeft)
Set the "Hops Left" field.
void SetFinalDst(Address finalDst)
Set the "Final Destination" address.
uint8_t GetHopsLeft() const
Get the "Hops Left" field.
Address GetFinalDst() const
Get the "Final Destination" address.
void SetOriginator(Address originator)
Set the "Originator" address.
Callback< void, Ptr< Packet > > ForwardCallback
Callback used by a policy to forward a packet.
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
@ DROP_MESH_NOT_ENABLED
Mesh-under packet received with UseMeshUnder disabled.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout exceeded.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Hold an unsigned integer type.
Definition uinteger.h:34
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
#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:133
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:553
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1347
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
static SixLowPanMeshUnderTestSuite g_sixLowPanMeshUnderTestSuite
Static suite registration.