Search in sources :

Example 1 with DpdkInterface

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();
}
Also used : DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultDpdkConfig(org.onosproject.openstacknode.api.DefaultDpdkConfig)

Example 2 with DpdkInterface

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;
}
Also used : DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) GENEVE(org.onosproject.openstacknode.api.Constants.GENEVE) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) OSClient(org.openstack4j.api.OSClient) OVSDB_PORT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.OVSDB_PORT) OpenstackNodeUtil.structurePortName(org.onosproject.openstacknode.util.OpenstackNodeUtil.structurePortName) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) BRIDGE_PREFIX(org.onosproject.openstacknode.api.Constants.BRIDGE_PREFIX) GRE(org.onosproject.openstacknode.api.Constants.GRE) COMPLETE(org.onosproject.openstacknode.api.NodeState.COMPLETE) INTEGRATION_BRIDGE(org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE) OpenstackNodeUtil.getConnectedClient(org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) INTEGRATION_TO_PHYSICAL_PREFIX(org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNodeUtil.isOvsdbConnected(org.onosproject.openstacknode.util.OpenstackNodeUtil.isOvsdbConnected) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) BridgeName(org.onosproject.net.behaviour.BridgeName) Collection(java.util.Collection) OpenstackNodeUtil.addOrRemoveSystemInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveSystemInterface) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) OpenstackNodeUtil.getOvsdbClient(org.onosproject.openstacknode.util.OpenstackNodeUtil.getOvsdbClient) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) AUTO_RECOVERY(org.onosproject.openstacknode.impl.OsgiPropertyConstants.AUTO_RECOVERY) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) INIT(org.onosproject.openstacknode.api.NodeState.INIT) ComponentContext(org.osgi.service.component.ComponentContext) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) Interface(org.onosproject.ovsdb.rfc.table.Interface) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) INCOMPLETE(org.onosproject.openstacknode.api.NodeState.INCOMPLETE) ControllerNode(org.onosproject.cluster.ControllerNode) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) TUNNEL_BRIDGE(org.onosproject.openstacknode.api.Constants.TUNNEL_BRIDGE) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) OVSDB_PORT_NUM_DEFAULT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.OVSDB_PORT_NUM_DEFAULT) Activate(org.osgi.service.component.annotations.Activate) VXLAN_TUNNEL(org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL) GENEVE_TUNNEL(org.onosproject.openstacknode.api.Constants.GENEVE_TUNNEL) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) PHYSICAL_TO_INTEGRATION_SUFFIX(org.onosproject.openstacknode.api.Constants.PHYSICAL_TO_INTEGRATION_SUFFIX) DEVICE_CREATED(org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) GRE_TUNNEL(org.onosproject.openstacknode.api.Constants.GRE_TUNNEL) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface) OpenstackNodeUtil.getBooleanProperty(org.onosproject.openstacknode.util.OpenstackNodeUtil.getBooleanProperty) Logger(org.slf4j.Logger) PatchDescription(org.onosproject.net.behaviour.PatchDescription) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) OpenstackNodeHandler(org.onosproject.openstacknode.api.OpenstackNodeHandler) APP_ID(org.onosproject.openstacknode.api.OpenstackNodeService.APP_ID) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TunnelKeys(org.onosproject.net.behaviour.TunnelKeys) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) NETDEV(org.onosproject.openstacknode.api.DpdkConfig.DatapathType.NETDEV) VXLAN(org.onosproject.openstacknode.api.Constants.VXLAN) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) NodeState(org.onosproject.openstacknode.api.NodeState) AUTO_RECOVERY_DEFAULT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.AUTO_RECOVERY_DEFAULT) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) OpenstackNodeUtil.addOrRemoveSystemInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveSystemInterface) Interface(org.onosproject.ovsdb.rfc.table.Interface) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface)

Example 3 with DpdkInterface

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();
}
Also used : Type(org.onosproject.openstacknode.api.DpdkInterface.Type) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) DefaultDpdkInterface(org.onosproject.openstacknode.api.DefaultDpdkInterface) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with DpdkInterface

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;
}
Also used : DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) DatapathType(org.onosproject.openstacknode.api.DpdkConfig.DatapathType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with DpdkInterface

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));
}
Also used : DpdkConfig(org.onosproject.openstacknode.api.DpdkConfig) DefaultDpdkConfig(org.onosproject.openstacknode.api.DefaultDpdkConfig) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) DefaultDpdkInterface(org.onosproject.openstacknode.api.DefaultDpdkInterface) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) OpenstackNodeJsonMatcher.matchesOpenstackNode(org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) Test(org.junit.Test)

Aggregations

DpdkInterface (org.onosproject.openstacknode.api.DpdkInterface)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 IpAddress (org.onlab.packet.IpAddress)1 TpPort.tpPort (org.onlab.packet.TpPort.tpPort)1 Tools (org.onlab.util.Tools)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1