Supports dpdk config in OpenstackNode.
Change-Id: I332d7643acb56c5fa7460edb6e4c90a2d862706f
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkConfigJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkConfigJsonMatcher.java
new file mode 100644
index 0000000..fd98a13
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkConfigJsonMatcher.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacknode.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.openstacknode.api.DpdkConfig;
+import org.onosproject.openstacknode.api.DpdkConfig.DatapathType;
+import org.onosproject.openstacknode.api.DpdkInterface;
+
+/**
+ * Hamcrest matcher for dpdk config.
+ */
+public final class DpdkConfigJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+ private final DpdkConfig dpdkConfig;
+
+ private static final String DATA_PATH_TYPE = "datapathType";
+ private static final String SOCKET_DIR = "socketDir";
+ private static final String DPDK_INTFS = "dpdkIntfs";
+
+ private DpdkConfigJsonMatcher(DpdkConfig dpdkConfig) {
+ this.dpdkConfig = dpdkConfig;
+ }
+
+ @Override
+ protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+ // check datapath type
+ DatapathType jsonDatapathType = DatapathType.valueOf(
+ jsonNode.get(DATA_PATH_TYPE).asText().toUpperCase());
+ DatapathType datapathType = dpdkConfig.datapathType();
+
+ if (!jsonDatapathType.equals(datapathType)) {
+ description.appendText("datapath type was " + jsonDatapathType.name());
+ return false;
+ }
+
+ // check socket directory
+ JsonNode jsonSocketDir = jsonNode.get(SOCKET_DIR);
+ if (jsonSocketDir != null) {
+ String socketDir = dpdkConfig.socketDir();
+
+ if (!jsonSocketDir.asText().equals(socketDir)) {
+ description.appendText("socketDir was " + jsonSocketDir);
+ return false;
+ }
+ }
+
+ // check dpdk interfaces
+ JsonNode jsonDpdkintfs = jsonNode.get(DPDK_INTFS);
+ if (jsonDpdkintfs != null) {
+ if (jsonDpdkintfs.size() != dpdkConfig.dpdkIntfs().size()) {
+ description.appendText("dpdk interface size was " + jsonDpdkintfs.size());
+ return false;
+ }
+
+ for (DpdkInterface dpdkIntf : dpdkConfig.dpdkIntfs()) {
+ boolean intfFound = false;
+ for (int intfIndex = 0; intfIndex < jsonDpdkintfs.size(); intfIndex++) {
+ DpdkInterfaceJsonMatcher intfMatcher =
+ DpdkInterfaceJsonMatcher.matchesDpdkInterface(dpdkIntf);
+ if (intfMatcher.matches(jsonDpdkintfs.get(intfIndex))) {
+ intfFound = true;
+ break;
+ }
+ }
+
+ if (!intfFound) {
+ description.appendText("DpdkIntf not found " + dpdkIntf.toString());
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(dpdkConfig.toString());
+ }
+
+ /**
+ * Factory to allocate and dpdk config matcher.
+ *
+ * @param dpdkConfig dpdk config object we are looking for
+ * @return matcher
+ */
+ public static DpdkConfigJsonMatcher matchDpdkConfig(DpdkConfig dpdkConfig) {
+ return new DpdkConfigJsonMatcher(dpdkConfig);
+ }
+}
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkInterfaceJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkInterfaceJsonMatcher.java
new file mode 100644
index 0000000..a5b17e4
--- /dev/null
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/DpdkInterfaceJsonMatcher.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacknode.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.openstacknode.api.DpdkInterface;
+import org.onosproject.openstacknode.api.DpdkInterface.Type;
+import org.slf4j.Logger;
+
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Hamcrest matcher for dpdk interface.
+ */
+public final class DpdkInterfaceJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+ private final Logger log = getLogger(getClass());
+
+ private static final String DEVICE_NAME = "deviceName";
+ private static final String INTF = "intf";
+ private static final String PCI_ADDRESS = "pciAddress";
+ private static final String TYPE = "type";
+ private static final String MTU = "mtu";
+
+ private final DpdkInterface dpdkIntf;
+
+ private DpdkInterfaceJsonMatcher(DpdkInterface dpdkIntf) {
+ this.dpdkIntf = dpdkIntf;
+ }
+
+ @Override
+ protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+ // check device name
+ String jsonDeviceName = jsonNode.get(DEVICE_NAME).asText();
+ String deviceName = dpdkIntf.deviceName();
+ if (!jsonDeviceName.equals(deviceName)) {
+ description.appendText("device name was " + jsonDeviceName);
+ return false;
+ }
+
+ String jsonIntf = jsonNode.get(INTF).asText();
+ String intf = dpdkIntf.intf();
+ if (!jsonIntf.equals(intf)) {
+ description.appendText("interface name was " + jsonIntf);
+ return false;
+ }
+
+ String jsonPciAddress = jsonNode.get(PCI_ADDRESS).asText();
+ String pciAddress = dpdkIntf.pciAddress();
+ if (!jsonPciAddress.equals(pciAddress)) {
+ description.appendText("pci address was " + jsonPciAddress);
+ return false;
+ }
+
+ Type jsonType = Type.valueOf(jsonNode.get(TYPE).asText());
+ Type type = dpdkIntf.type();
+ if (!jsonType.equals(type)) {
+ description.appendText("type was " + jsonType.name());
+ return false;
+ }
+
+ JsonNode jsonMtu = jsonNode.get(MTU);
+ if (jsonMtu != null) {
+ Long mtu = dpdkIntf.mtu();
+ if (!jsonMtu.asText().equals(mtu.toString())) {
+ description.appendText("mtu was " + jsonMtu.asText());
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(dpdkIntf.toString());
+ }
+
+ /**
+ * Factory to allocate an dpdk interface matcher.
+ *
+ * @param dpdkIntf dpdk interface object we are looking for
+ * @return matcher
+ */
+ public static DpdkInterfaceJsonMatcher matchesDpdkInterface(DpdkInterface dpdkIntf) {
+ return new DpdkInterfaceJsonMatcher(dpdkIntf);
+ }
+}
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
index 4268d6c..af5fdf4 100644
--- a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeCodecTest.java
@@ -29,18 +29,24 @@
import org.onosproject.core.CoreService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.openstacknode.api.DefaultOpenstackAuth;
+import org.onosproject.openstacknode.api.DefaultOpenstackNode;
+import org.onosproject.openstacknode.api.DpdkConfig;
+import org.onosproject.openstacknode.api.DpdkInterface;
import org.onosproject.openstacknode.api.NodeState;
import org.onosproject.openstacknode.api.OpenstackAuth;
import org.onosproject.openstacknode.api.OpenstackNode;
import org.onosproject.openstacknode.api.OpenstackPhyInterface;
import org.onosproject.openstacknode.api.OpenstackSshAuth;
-import org.onosproject.openstacknode.api.DefaultOpenstackAuth;
-import org.onosproject.openstacknode.api.DefaultOpenstackNode;
+import org.onosproject.openstacknode.impl.DefaultDpdkConfig;
+import org.onosproject.openstacknode.impl.DefaultDpdkInterface;
import org.onosproject.openstacknode.impl.DefaultOpenstackPhyInterface;
import org.onosproject.openstacknode.impl.DefaultOpenstackSshAuth;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -50,6 +56,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode;
@@ -63,6 +70,8 @@
JsonCodec<ControllerInfo> openstackControllerJsonCodec;
JsonCodec<OpenstackAuth> openstackAuthJsonCodec;
JsonCodec<OpenstackSshAuth> openstackSshAuthJsonCodec;
+ JsonCodec<DpdkConfig> dpdkConfigJsonCodec;
+ JsonCodec<DpdkInterface> dpdkInterfaceJsonCodec;
final CoreService mockCoreService = createMock(CoreService.class);
private static final String REST_APP_ID = "org.onosproject.rest";
@@ -75,12 +84,16 @@
openstackControllerJsonCodec = new OpenstackControllerCodec();
openstackAuthJsonCodec = new OpenstackAuthCodec();
openstackSshAuthJsonCodec = new OpenstackSshAuthCodec();
+ dpdkConfigJsonCodec = new DpdkConfigCodec();
+ dpdkInterfaceJsonCodec = new DpdkInterfaceCodec();
assertThat(openstackNodeCodec, notNullValue());
assertThat(openstackPhyIntfJsonCodec, notNullValue());
assertThat(openstackControllerJsonCodec, notNullValue());
assertThat(openstackAuthJsonCodec, notNullValue());
assertThat(openstackSshAuthJsonCodec, notNullValue());
+ assertThat(dpdkConfigJsonCodec, notNullValue());
+ assertThat(dpdkInterfaceJsonCodec, notNullValue());
expect(mockCoreService.registerApplication(REST_APP_ID))
.andReturn(APP_ID).anyTimes();
@@ -119,12 +132,11 @@
.state(NodeState.INIT)
.managementIp(IpAddress.valueOf("10.10.10.1"))
.intgBridge(DeviceId.deviceId("br-int"))
- .vlanIntf("vxlan")
+ .vlanIntf("vlan")
.dataIp(IpAddress.valueOf("20.20.20.2"))
.phyIntfs(ImmutableList.of(phyIntf1, phyIntf2))
.controllers(ImmutableList.of(controller1, controller2))
.sshAuthInfo(sshAuth)
- .socketDir("/var/lib/libvirt/qemu")
.build();
ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
@@ -134,7 +146,7 @@
/**
* Tests the openstack compute node decoding.
*
- * @throws IOException
+ * @throws IOException io exception
*/
@Test
public void testOpenstackComputeNodeDecode() throws IOException {
@@ -150,8 +162,7 @@
assertThat(node.controllers().size(), is(2));
assertThat(node.sshAuthInfo().id(), is("sdn"));
assertThat(node.sshAuthInfo().password(), is("sdn"));
- assertThat(node.datapathType(), is(OpenstackNode.DatapathType.NORMAL));
- assertThat(node.socketDir(), is("/var/lib/libvirt/qemu"));
+ assertThat(node.datapathType(), is(DpdkConfig.DatapathType.NORMAL));
node.phyIntfs().forEach(intf -> {
@@ -171,10 +182,65 @@
assertThat(ctrl.port(), is(6663));
}
});
+ }
- OpenstackNode dpdkNode = getOpenstackNode("OpenstackDpdkComputeNode.json");
+ /**
+ * Tests the openstack compute node encoding with dpdk config.
+ */
+ @Test
+ public void testOpenstackDpdkComputeNodeEncode() {
+ DpdkInterface dpdkInterface1 = DefaultDpdkInterface.builder()
+ .deviceName("br-int")
+ .intf("dpdk0")
+ .mtu(Long.valueOf(1600))
+ .pciAddress("0000:85:00.0")
+ .type(DpdkInterface.Type.DPDK)
+ .build();
- assertThat(dpdkNode.datapathType(), is(OpenstackNode.DatapathType.NETDEV));
+ DpdkInterface dpdkInterface2 = DefaultDpdkInterface.builder()
+ .deviceName("br-tun")
+ .intf("dpdk1")
+ .pciAddress("0000:85:00.1")
+ .type(DpdkInterface.Type.DPDK)
+ .build();
+
+ Collection<DpdkInterface> dpdkInterfaceCollection = new ArrayList<>();
+ dpdkInterfaceCollection.add(dpdkInterface1);
+ dpdkInterfaceCollection.add(dpdkInterface2);
+
+
+ DpdkConfig dpdkConfig = DefaultDpdkConfig.builder()
+ .datapathType(DpdkConfig.DatapathType.NETDEV)
+ .dpdkIntfs(dpdkInterfaceCollection)
+ .build();
+
+ OpenstackNode node = DefaultOpenstackNode.builder()
+ .hostname("compute")
+ .type(OpenstackNode.NodeType.COMPUTE)
+ .state(NodeState.INIT)
+ .managementIp(IpAddress.valueOf("10.10.10.1"))
+ .intgBridge(DeviceId.deviceId("br-int"))
+ .vlanIntf("vlan")
+ .dataIp(IpAddress.valueOf("20.20.20.2"))
+ .dpdkConfig(dpdkConfig)
+ .build();
+
+ ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
+ assertThat(nodeJson, matchesOpenstackNode(node));
+ }
+
+ /**
+ * Tests the openstack compute node decoding with dpdk config.
+ *
+ * @throws IOException io exception
+ */
+ @Test
+ public void testOpenstackDpdkComputeNodeDecode() throws IOException {
+ OpenstackNode node = getOpenstackNode("OpenstackDpdkComputeNode.json");
+
+ assertEquals(node.datapathType(), DpdkConfig.DatapathType.NETDEV);
+ assertEquals(node.socketDir(), "/var/lib/libvirt/qemu");
+ assertEquals(node.dpdkConfig().dpdkIntfs().size(), 2);
}
/**
@@ -277,6 +343,12 @@
if (entityClass == OpenstackSshAuth.class) {
return (JsonCodec<T>) openstackSshAuthJsonCodec;
}
+ if (entityClass == DpdkConfig.class) {
+ return (JsonCodec<T>) dpdkConfigJsonCodec;
+ }
+ if (entityClass == DpdkInterface.class) {
+ return (JsonCodec<T>) dpdkInterfaceJsonCodec;
+ }
return manager.getCodec(entityClass);
}
diff --git a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
index 49c08c6..6e3b473 100644
--- a/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
+++ b/apps/openstacknode/app/src/test/java/org/onosproject/openstacknode/codec/OpenstackNodeJsonMatcher.java
@@ -20,6 +20,7 @@
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.onosproject.net.behaviour.ControllerInfo;
import org.onosproject.openstacknode.api.Constants;
+import org.onosproject.openstacknode.api.DpdkConfig;
import org.onosproject.openstacknode.api.OpenstackAuth;
import org.onosproject.openstacknode.api.OpenstackNode;
import org.onosproject.openstacknode.api.OpenstackPhyInterface;
@@ -38,12 +39,11 @@
private static final String INTEGRATION_BRIDGE = "integrationBridge";
private static final String STATE = "state";
private static final String PHYSICAL_INTERFACES = "phyIntfs";
+ private static final String DPDK_CONFIG = "dpdkConfig";
private static final String CONTROLLERS = "controllers";
private static final String AUTHENTICATION = "authentication";
private static final String END_POINT = "endpoint";
private static final String SSH_AUTH = "sshAuth";
- private static final String DATA_PATH_TYPE = "datapathType";
- private static final String SOCKET_DIR = "socketDir";
private OpenstackNodeJsonMatcher(OpenstackNode node) {
this.node = node;
@@ -135,6 +135,13 @@
}
}
+ // check dpdk config
+ JsonNode jsonDpdkConfig = jsonNode.get(DPDK_CONFIG);
+ if (jsonDpdkConfig != null) {
+ DpdkConfig dpdkConfig = node.dpdkConfig();
+
+ }
+
// check endpoint URL
JsonNode jsonEndpoint = jsonNode.get(END_POINT);
if (jsonEndpoint != null) {
@@ -145,26 +152,6 @@
}
}
- // check datapath type
- JsonNode jsonDatapathType = jsonNode.get(DATA_PATH_TYPE);
- if (jsonDatapathType != null) {
- OpenstackNode.DatapathType datapathType = node.datapathType();
- if (!OpenstackNode.DatapathType.valueOf(jsonDatapathType.asText()).equals(datapathType)) {
- description.appendText("datapathType was " + jsonDatapathType);
- return false;
- }
- }
-
- // check socket directory
- JsonNode jsonSocketDir = jsonNode.get(SOCKET_DIR);
- if (jsonSocketDir != null) {
- String socketDir = node.socketDir();
- if (!jsonSocketDir.asText().equals(socketDir)) {
- description.appendText("socketDir was " + jsonSocketDir);
- return false;
- }
- }
-
// check physical interfaces
JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
if (jsonPhyIntfs != null) {