Search in sources :

Example 1 with DpdkConfig

use of org.onosproject.openstacknode.api.DpdkConfig in project onos by opennetworkinglab.

the class OpenstackNodeCodec method decode.

@Override
public OpenstackNode decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
    String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
    String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
    DefaultOpenstackNode.Builder nodeBuilder = DefaultOpenstackNode.builder().hostname(hostname).type(OpenstackNode.NodeType.valueOf(type)).state(NodeState.INIT).managementIp(IpAddress.valueOf(mIp));
    if (type.equals(GATEWAY)) {
        nodeBuilder.uplinkPort(nullIsIllegal(json.get(UPLINK_PORT).asText(), UPLINK_PORT + MISSING_MESSAGE));
    }
    if (type.equals(CONTROLLER)) {
        JsonNode keystoneConfigJson = json.get(KEYSTONE_CONFIG);
        KeystoneConfig keystoneConfig;
        if (keystoneConfigJson != null) {
            final JsonCodec<KeystoneConfig> keystoneConfigCodec = context.codec(KeystoneConfig.class);
            keystoneConfig = keystoneConfigCodec.decode((ObjectNode) keystoneConfigJson.deepCopy(), context);
        } else {
            JsonNode authJson = json.get(AUTHENTICATION);
            final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
            OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
            String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(), ENDPOINT + MISSING_MESSAGE);
            keystoneConfig = DefaultKeystoneConfig.builder().authentication(auth).endpoint(endpoint).build();
        }
        nodeBuilder.keystoneConfig(keystoneConfig);
    }
    if (json.get(VLAN_INTF_NAME) != null) {
        nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
    }
    if (json.get(DATA_IP) != null) {
        nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
    }
    JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
    if (intBridgeJson != null) {
        nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
    }
    // parse physical interfaces
    List<OpenstackPhyInterface> phyIntfs = new ArrayList<>();
    JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
    if (phyIntfsJson != null) {
        final JsonCodec<OpenstackPhyInterface> phyIntfCodec = context.codec(OpenstackPhyInterface.class);
        IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
            ObjectNode intfJson = get(phyIntfsJson, i);
            phyIntfs.add(phyIntfCodec.decode(intfJson, context));
        });
    }
    nodeBuilder.phyIntfs(phyIntfs);
    // parse customized controllers
    List<ControllerInfo> controllers = new ArrayList<>();
    JsonNode controllersJson = json.get(CONTROLLERS);
    if (controllersJson != null) {
        final JsonCodec<ControllerInfo> controllerCodec = context.codec(ControllerInfo.class);
        IntStream.range(0, controllersJson.size()).forEach(i -> {
            ObjectNode controllerJson = get(controllersJson, i);
            controllers.add(controllerCodec.decode(controllerJson, context));
        });
    }
    nodeBuilder.controllers(controllers);
    // parse neutron config
    JsonNode neutronConfigJson = json.get(NEUTRON_CONFIG);
    if (neutronConfigJson != null) {
        final JsonCodec<NeutronConfig> neutronConfigJsonCodec = context.codec(NeutronConfig.class);
        NeutronConfig neutronConfig = neutronConfigJsonCodec.decode((ObjectNode) neutronConfigJson.deepCopy(), context);
        nodeBuilder.neutronConfig(neutronConfig);
    }
    // parse ssh authentication
    JsonNode sshAuthJson = json.get(SSH_AUTH);
    if (sshAuthJson != null) {
        final JsonCodec<OpenstackSshAuth> sshAuthJsonCodec = context.codec(OpenstackSshAuth.class);
        OpenstackSshAuth sshAuth = sshAuthJsonCodec.decode((ObjectNode) sshAuthJson.deepCopy(), context);
        nodeBuilder.sshAuthInfo(sshAuth);
    }
    // parse DPDK configuration
    JsonNode dpdkConfigJson = json.get(DPDK_CONFIG);
    if (dpdkConfigJson != null) {
        final JsonCodec<DpdkConfig> dpdkConfigJsonCodec = context.codec(DpdkConfig.class);
        DpdkConfig dpdkConfig = dpdkConfigJsonCodec.decode((ObjectNode) dpdkConfigJson.deepCopy(), context);
        nodeBuilder.dpdkConfig(dpdkConfig);
    }
    log.trace("node is {}", nodeBuilder.build().toString());
    return nodeBuilder.build();
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KeystoneConfig(org.onosproject.openstacknode.api.KeystoneConfig) DefaultKeystoneConfig(org.onosproject.openstacknode.api.DefaultKeystoneConfig) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DpdkConfig(org.onosproject.openstacknode.api.DpdkConfig) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 2 with DpdkConfig

use of org.onosproject.openstacknode.api.DpdkConfig 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)

Example 3 with DpdkConfig

use of org.onosproject.openstacknode.api.DpdkConfig in project onos by opennetworkinglab.

the class OpenstackNodeJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
    // check hostname
    String jsonHostname = jsonNode.get(Constants.HOST_NAME).asText();
    String hostname = node.hostname();
    if (!jsonHostname.equals(hostname)) {
        description.appendText("hostname was " + jsonHostname);
        return false;
    }
    // check type
    String jsonType = jsonNode.get(Constants.TYPE).asText();
    String type = node.type().name();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    // check management IP
    String jsonMgmtIp = jsonNode.get(MANAGEMENT_IP).asText();
    String mgmtIp = node.managementIp().toString();
    if (!jsonMgmtIp.equals(mgmtIp)) {
        description.appendText("management IP was " + jsonMgmtIp);
        return false;
    }
    // check integration bridge
    JsonNode jsonIntgBridge = jsonNode.get(INTEGRATION_BRIDGE);
    if (jsonIntgBridge != null) {
        String intgBridge = node.intgBridge().toString();
        if (!jsonIntgBridge.asText().equals(intgBridge)) {
            description.appendText("integration bridge was " + jsonIntgBridge);
            return false;
        }
    }
    // check state
    String jsonState = jsonNode.get(STATE).asText();
    String state = node.state().name();
    if (!jsonState.equals(state)) {
        description.appendText("state was " + jsonState);
        return false;
    }
    // check VLAN interface
    JsonNode jsonVlanIntf = jsonNode.get(VLAN_INTF_NAME);
    if (jsonVlanIntf != null) {
        String vlanIntf = node.vlanIntf();
        if (!jsonVlanIntf.asText().equals(vlanIntf)) {
            description.appendText("VLAN interface was " + jsonVlanIntf.asText());
            return false;
        }
    }
    // check data IP
    JsonNode jsonDataIp = jsonNode.get(DATA_IP);
    if (jsonDataIp != null) {
        String dataIp = node.dataIp().toString();
        if (!jsonDataIp.asText().equals(dataIp)) {
            description.appendText("Data IP was " + jsonDataIp.asText());
            return false;
        }
    }
    // check openstack ssh auth
    JsonNode jsonSshAuth = jsonNode.get(SSH_AUTH);
    if (jsonSshAuth != null) {
        OpenstackSshAuth sshAuth = node.sshAuthInfo();
        OpenstackSshAuthJsonMatcher sshAuthJsonMatcher = OpenstackSshAuthJsonMatcher.matchOpenstackSshAuth(sshAuth);
        if (!sshAuthJsonMatcher.matches(jsonSshAuth)) {
            return false;
        }
    }
    // check dpdk config
    JsonNode jsonDpdkConfig = jsonNode.get(DPDK_CONFIG);
    if (jsonDpdkConfig != null) {
        DpdkConfig dpdkConfig = node.dpdkConfig();
    }
    // check physical interfaces
    JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
    if (jsonPhyIntfs != null) {
        if (jsonPhyIntfs.size() != node.phyIntfs().size()) {
            description.appendText("physical interface size was " + jsonPhyIntfs.size());
            return false;
        }
        for (OpenstackPhyInterface phyIntf : node.phyIntfs()) {
            boolean intfFound = false;
            for (int intfIndex = 0; intfIndex < jsonPhyIntfs.size(); intfIndex++) {
                OpenstackPhyInterfaceJsonMatcher intfMatcher = OpenstackPhyInterfaceJsonMatcher.matchesOpenstackPhyInterface(phyIntf);
                if (intfMatcher.matches(jsonPhyIntfs.get(intfIndex))) {
                    intfFound = true;
                    break;
                }
            }
            if (!intfFound) {
                description.appendText("PhyIntf not found " + phyIntf.toString());
                return false;
            }
        }
    }
    // check controllers
    JsonNode jsonControllers = jsonNode.get(CONTROLLERS);
    if (jsonControllers != null) {
        if (jsonControllers.size() != node.controllers().size()) {
            description.appendText("controllers size was " + jsonControllers.size());
            return false;
        }
        for (ControllerInfo controller : node.controllers()) {
            boolean ctrlFound = false;
            for (int ctrlIndex = 0; ctrlIndex < jsonControllers.size(); ctrlIndex++) {
                OpenstackControllerJsonMatcher ctrlMatcher = OpenstackControllerJsonMatcher.matchesOpenstackController(controller);
                if (ctrlMatcher.matches(jsonControllers.get(ctrlIndex))) {
                    ctrlFound = true;
                    break;
                }
            }
            if (!ctrlFound) {
                description.appendText("Controller not found " + controller.toString());
                return false;
            }
        }
    }
    return true;
}
Also used : OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DpdkConfig(org.onosproject.openstacknode.api.DpdkConfig) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) JsonNode(com.fasterxml.jackson.databind.JsonNode) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Aggregations

DpdkConfig (org.onosproject.openstacknode.api.DpdkConfig)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)2 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)2 OpenstackPhyInterface (org.onosproject.openstacknode.api.OpenstackPhyInterface)2 OpenstackSshAuth (org.onosproject.openstacknode.api.OpenstackSshAuth)2 Test (org.junit.Test)1 DefaultDpdkConfig (org.onosproject.openstacknode.api.DefaultDpdkConfig)1 DefaultDpdkInterface (org.onosproject.openstacknode.api.DefaultDpdkInterface)1 DefaultKeystoneConfig (org.onosproject.openstacknode.api.DefaultKeystoneConfig)1 DpdkInterface (org.onosproject.openstacknode.api.DpdkInterface)1 KeystoneConfig (org.onosproject.openstacknode.api.KeystoneConfig)1 NeutronConfig (org.onosproject.openstacknode.api.NeutronConfig)1 OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)1 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)1 OpenstackNodeJsonMatcher.matchesOpenstackNode (org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode)1