Search in sources :

Example 1 with OpenstackPhyInterface

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

the class OpenstackNodeCodecTest method testOpenstackComputeNodeEncode.

/**
 * Tests the openstack compute node encoding.
 */
@Test
public void testOpenstackComputeNodeEncode() {
    OpenstackPhyInterface phyIntf1 = DefaultOpenstackPhyInterface.builder().network("mgmtnetwork").intf("eth3").build();
    OpenstackPhyInterface phyIntf2 = DefaultOpenstackPhyInterface.builder().network("oamnetwork").intf("eth4").build();
    OpenstackSshAuth sshAuth = DefaultOpenstackSshAuth.builder().id("sdn").password("sdn").build();
    ControllerInfo controller1 = new ControllerInfo(IpAddress.valueOf("10.10.10.2"), 6653, "tcp");
    ControllerInfo controller2 = new ControllerInfo(IpAddress.valueOf("10.10.10.3"), 6663, "tcp");
    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")).phyIntfs(ImmutableList.of(phyIntf1, phyIntf2)).controllers(ImmutableList.of(controller1, controller2)).sshAuthInfo(sshAuth).build();
    ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
    assertThat(nodeJson, matchesOpenstackNode(node));
}
Also used : OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DefaultOpenstackPhyInterface(org.onosproject.openstacknode.api.DefaultOpenstackPhyInterface) DefaultOpenstackSshAuth(org.onosproject.openstacknode.api.DefaultOpenstackSshAuth) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpenstackNodeJsonMatcher.matchesOpenstackNode(org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 2 with OpenstackPhyInterface

use of org.onosproject.openstacknode.api.OpenstackPhyInterface 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 3 with OpenstackPhyInterface

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

the class DefaultOpenstackNodeHandler method deviceCreatedStateDone.

private boolean deviceCreatedStateDone(OpenstackNode osNode) {
    if (osNode.dataIp() != null && !isIntfEnabled(osNode, VXLAN_TUNNEL)) {
        return false;
    }
    if (osNode.dataIp() != null && !isIntfEnabled(osNode, GRE_TUNNEL)) {
        return false;
    }
    if (osNode.dataIp() != null && !isIntfEnabled(osNode, GENEVE_TUNNEL)) {
        return false;
    }
    if (osNode.vlanIntf() != null && !isIntfEnabled(osNode, osNode.vlanIntf())) {
        return false;
    }
    if (osNode.type() == GATEWAY && !isIntfEnabled(osNode, osNode.uplinkPort())) {
        return false;
    }
    if (osNode.dpdkConfig() != null && osNode.dpdkConfig().dpdkIntfs() != null && !isDpdkIntfsCreated(osNode, osNode.dpdkConfig().dpdkIntfs())) {
        return false;
    }
    for (OpenstackPhyInterface phyIntf : osNode.phyIntfs()) {
        if (phyIntf == null) {
            return false;
        }
        String bridgeName = BRIDGE_PREFIX + phyIntf.network();
        String patchPortName = structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + phyIntf.network());
        if (!(hasPhyBridge(osNode, bridgeName) && hasPhyPatchPort(osNode, patchPortName) && hasPhyIntf(osNode, phyIntf.intf()))) {
            return false;
        }
    }
    return true;
}
Also used : OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface)

Example 4 with OpenstackPhyInterface

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

OpenstackPhyInterface (org.onosproject.openstacknode.api.OpenstackPhyInterface)4 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)3 OpenstackSshAuth (org.onosproject.openstacknode.api.OpenstackSshAuth)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)2 DpdkConfig (org.onosproject.openstacknode.api.DpdkConfig)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 DefaultKeystoneConfig (org.onosproject.openstacknode.api.DefaultKeystoneConfig)1 DefaultOpenstackPhyInterface (org.onosproject.openstacknode.api.DefaultOpenstackPhyInterface)1 DefaultOpenstackSshAuth (org.onosproject.openstacknode.api.DefaultOpenstackSshAuth)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