use of org.onosproject.openstacknode.api.DpdkInterface in project onos by opennetworkinglab.
the class DpdkConfigCodec method decode.
@Override
public DpdkConfig decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String datapathType = nullIsIllegal(json.get(DATA_PATH_TYPE).asText(), DATA_PATH_TYPE + MISSING_MESSAGE);
DefaultDpdkConfig.Builder builder = DefaultDpdkConfig.builder().datapathType(DpdkConfig.DatapathType.valueOf(datapathType.toUpperCase(Locale.ENGLISH)));
if (json.get(SOCKET_DIR) != null) {
builder.socketDir(json.get(SOCKET_DIR).asText());
}
List<DpdkInterface> dpdkInterfaces = new ArrayList<>();
JsonNode dpdkIntfsJson = json.get(DPDK_INTFS);
if (dpdkIntfsJson != null) {
final JsonCodec<DpdkInterface> dpdkIntfCodec = context.codec(DpdkInterface.class);
IntStream.range(0, dpdkIntfsJson.size()).forEach(i -> {
ObjectNode intfJson = get(dpdkIntfsJson, i);
dpdkInterfaces.add(dpdkIntfCodec.decode(intfJson, context));
});
}
builder.dpdkIntfs(dpdkInterfaces);
return builder.build();
}
use of org.onosproject.openstacknode.api.DpdkInterface in project onos by opennetworkinglab.
the class DefaultOpenstackNodeHandler method isDpdkIntfsCreated.
private boolean isDpdkIntfsCreated(OpenstackNode osNode, Collection<DpdkInterface> dpdkInterfaces) {
OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
if (client == null) {
log.info("Failed to get ovsdb client");
return false;
}
Set<OvsdbPort> ports = client.getPorts();
for (DpdkInterface dpdkIntf : dpdkInterfaces) {
Optional<OvsdbPort> port = ports.stream().filter(ovsdbPort -> ovsdbPort.portName().value().equals(dpdkIntf.intf())).findAny();
if (!port.isPresent()) {
return false;
}
Interface intf = client.getInterface(dpdkIntf.intf());
if (intf == null) {
return false;
}
OvsdbSet mtu = (OvsdbSet) intf.getMtuColumn().data();
if (mtu == null) {
return false;
}
OvsdbMap option = (OvsdbMap) intf.getOptionsColumn().data();
if (option == null) {
return false;
}
if (!mtu.set().contains(dpdkIntf.mtu().intValue()) || !option.toString().contains(dpdkIntf.pciAddress())) {
log.trace("The dpdk interface {} was created but mtu or " + "pci address is different from the config.");
return false;
}
}
return true;
}
use of org.onosproject.openstacknode.api.DpdkInterface in project onos by opennetworkinglab.
the class DpdkInterfaceCodec method decode.
@Override
public DpdkInterface decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String deviceName = nullIsIllegal(json.get(DEVICE_NAME).asText(), DEVICE_NAME + MISSING_MESSAGE);
String intf = nullIsIllegal(json.get(INTF).asText(), INTF + MISSING_MESSAGE);
String pciAddress = nullIsIllegal(json.get(PCI_ADDRESS).asText(), PCI_ADDRESS + MISSING_MESSAGE);
String typeString = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
Type type;
try {
type = Type.valueOf(typeString.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
log.error(TYPE + MISSING_MESSAGE);
throw new IllegalArgumentException(e);
}
DpdkInterface.Builder builder = DefaultDpdkInterface.builder().deviceName(deviceName).intf(intf).pciAddress(pciAddress).type(type);
JsonNode mtuJson = json.get(MTU);
if (mtuJson != null) {
builder.mtu(Long.parseLong(mtuJson.asText()));
}
return builder.build();
}
use of org.onosproject.openstacknode.api.DpdkInterface in project onos by opennetworkinglab.
the class DpdkConfigJsonMatcher method matchesSafely.
@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;
}
use of org.onosproject.openstacknode.api.DpdkInterface in project onos by opennetworkinglab.
the class OpenstackNodeCodecTest method testOpenstackDpdkComputeNodeEncode.
/**
* 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();
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));
}
Aggregations