Supports MTU option in OpenstackSwitching dhcp handler.
Change-Id: Ic3b712814d20d17b32dc66963a0845291828c97b
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
index 0b751e6..3a11e5a 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
@@ -62,6 +62,7 @@
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.HostRoute;
import org.openstack4j.model.network.IP;
+import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
import org.osgi.service.component.ComponentContext;
@@ -87,6 +88,7 @@
import static org.onosproject.openstacknetworking.api.Constants.DHCP_ARP_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_DHCP_RULE;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -425,7 +427,11 @@
option = new DhcpOption();
option.setCode(DHCP_OPTION_MTU);
option.setLength((byte) 2);
- option.setData(ByteBuffer.allocate(2).putShort((short) dhcpDataMtu).array());
+ Network osNetwork = osNetworkService.network(osSubnet.getNetworkId());
+ checkNotNull(osNetwork);
+ checkNotNull(osNetwork.getMTU());
+
+ option.setData(ByteBuffer.allocate(2).putShort(osNetwork.getMTU().shortValue()).array());
options.add(option);
// classless static route
diff --git a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandlerTest.java b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandlerTest.java
index 1206ce3..28323b0 100644
--- a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandlerTest.java
+++ b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandlerTest.java
@@ -51,10 +51,13 @@
import org.openstack4j.model.network.IPVersionType;
import org.openstack4j.model.network.Ipv6AddressMode;
import org.openstack4j.model.network.Ipv6RaMode;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Pool;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.State;
import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.network.builder.NetworkBuilder;
import org.openstack4j.model.network.builder.PortBuilder;
import org.openstack4j.model.network.builder.SubnetBuilder;
import org.openstack4j.openstack.networking.domain.NeutronIP;
@@ -293,6 +296,11 @@
return new TestSubnet();
}
+ @Override
+ public Network network(String networkId) {
+ return new TestNetwork();
+ }
+
/**
* Mocks the Neutron port.
*/
@@ -410,6 +418,106 @@
}
/**
+ * Mocks the Neutron network.
+ */
+ private class TestNetwork implements Network {
+
+ @Override
+ public State getStatus() {
+ return null;
+ }
+
+ @Override
+ public List<String> getSubnets() {
+ return null;
+ }
+
+ @Override
+ public String getProviderPhyNet() {
+ return null;
+ }
+
+ @Override
+ public boolean isAdminStateUp() {
+ return false;
+ }
+
+ @Override
+ public NetworkType getNetworkType() {
+ return null;
+ }
+
+ @Override
+ public boolean isRouterExternal() {
+ return false;
+ }
+
+ @Override
+ public boolean isShared() {
+ return false;
+ }
+
+ @Override
+ public String getProviderSegID() {
+ return null;
+ }
+
+ @Override
+ public List<? extends Subnet> getNeutronSubnets() {
+ return null;
+ }
+
+ @Override
+ public Integer getMTU() {
+ return Integer.valueOf(4000);
+ }
+
+ @Override
+ public List<String> getAvailabilityZoneHints() {
+ return null;
+ }
+
+ @Override
+ public List<String> getAvailabilityZones() {
+ return null;
+ }
+
+ @Override
+ public NetworkBuilder toBuilder() {
+ return null;
+ }
+
+ @Override
+ public String getTenantId() {
+ return null;
+ }
+
+ @Override
+ public void setTenantId(String s) {
+
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public void setName(String s) {
+
+ }
+
+ @Override
+ public String getId() {
+ return null;
+ }
+
+ @Override
+ public void setId(String s) {
+
+ }
+ }
+ /**
* Mocks the Neutron subnet.
*/
private class TestSubnet implements Subnet {
@@ -421,7 +529,7 @@
@Override
public String getNetworkId() {
- return null;
+ return "1";
}
@Override