face: support runtime MTU changes on Ethernet faces
refs #3257
Change-Id: I160fe444b889b8f7be19022a2bd52bbc9f7a21aa
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
index 8006fbb..693d393 100644
--- a/tests/daemon/face/generic-link-service.t.cpp
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -282,6 +282,24 @@
BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
}
+// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
+// This test case ensures that packets are dropped if the MTU is zero
+BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop)
+{
+ // Initialize with Options that disable fragmentation
+ GenericLinkService::Options options;
+ options.allowFragmentation = false;
+ initialize(options);
+
+ transport->setMtu(0);
+
+ auto data = makeData("/test/data/123456789/987654321/123456789");
+ face->sendData(*data, 0);
+
+ BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
+ BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
+}
+
BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
{
// Initialize with Options that enable fragmentation
@@ -327,6 +345,24 @@
BOOST_CHECK_GT(transport->sentPackets.size(), 1);
}
+// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
+// This test case ensures that packets are dropped if the MTU is zero
+BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop)
+{
+ // Initialize with Options that enable fragmentation
+ GenericLinkService::Options options;
+ options.allowFragmentation = true;
+ initialize(options);
+
+ transport->setMtu(0);
+
+ auto data = makeData("/test/data/123456789/987654321/123456789");
+ face->sendData(*data, 0);
+
+ BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
+ BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1);
+}
+
BOOST_AUTO_TEST_CASE(ReassembleFragments)
{
// Initialize with Options that enables reassembly
diff --git a/tests/daemon/face/multicast-ethernet-transport.t.cpp b/tests/daemon/face/multicast-ethernet-transport.t.cpp
index 8dde05f..4e0df3c 100644
--- a/tests/daemon/face/multicast-ethernet-transport.t.cpp
+++ b/tests/daemon/face/multicast-ethernet-transport.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -89,6 +89,25 @@
BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
}
+BOOST_AUTO_TEST_CASE(NetifMtuChange)
+{
+ SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
+ initializeMulticast();
+ BOOST_CHECK_EQUAL(transport->getMtu(), netif->getMtu());
+
+ // netif changes MTU from initial value to 1024
+ netif->setMtu(1024);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 1024);
+
+ // netif changes MTU from 1024 to 4000
+ netif->setMtu(4000);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 4000);
+
+ // netif changes MTU from 4000 to 0
+ netif->setMtu(0);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 0);
+}
+
BOOST_AUTO_TEST_CASE(Close)
{
SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
diff --git a/tests/daemon/face/unicast-ethernet-transport.t.cpp b/tests/daemon/face/unicast-ethernet-transport.t.cpp
index 355a3ea..634a119 100644
--- a/tests/daemon/face/unicast-ethernet-transport.t.cpp
+++ b/tests/daemon/face/unicast-ethernet-transport.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -58,6 +58,25 @@
BOOST_CHECK_EQUAL(transport->canChangePersistencyTo(ndn::nfd::FACE_PERSISTENCY_PERMANENT), true);
}
+BOOST_AUTO_TEST_CASE(NetifMtuChange)
+{
+ SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
+ initializeUnicast();
+ BOOST_CHECK_EQUAL(transport->getMtu(), netif->getMtu());
+
+ // netif changes MTU from initial value to 1024
+ netif->setMtu(1024);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 1024);
+
+ // netif changes MTU from 1024 to 4000
+ netif->setMtu(4000);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 4000);
+
+ // netif changes MTU from 4000 to 0
+ netif->setMtu(0);
+ BOOST_CHECK_EQUAL(transport->getMtu(), 0);
+}
+
BOOST_AUTO_TEST_CASE(ExpirationTime)
{
SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);