Search in sources :

Example 31 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class RestSBControllerMock method get.

@Override
public InputStream get(DeviceId device, String request, MediaType mediaType) {
    /**
     * We fake the HTTP get in order to
     * emulate the expected response.
     */
    ObjectMapper mapper = new ObjectMapper();
    // Create the object node to host the data
    ObjectNode sendObjNode = mapper.createObjectNode();
    // Insert header
    ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
    // Add each controller's information object
    for (ControllerInfo ctrl : controllers) {
        ObjectNode ctrlObjNode = mapper.createObjectNode();
        ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
        ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
        ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
        ctrlsArrayNode.add(ctrlObjNode);
    }
    return new ByteArrayInputStream(sendObjNode.toString().getBytes());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 32 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class DeviceSetControllersCommand method getControllerInfo.

private ControllerInfo getControllerInfo(Annotations annotation, String s) {
    String[] data = s.split(":");
    if (data.length != 3) {
        print("Wrong format of the controller %s, should be in the format <protocol>:<ip>:<port>", s);
        return null;
    }
    String type = data[0];
    IpAddress ip = IpAddress.valueOf(data[1]);
    int port = Integer.parseInt(data[2]);
    if (annotation != null) {
        return new ControllerInfo(ip, port, type, annotation);
    }
    return new ControllerInfo(ip, port, type);
}
Also used : IpAddress(org.onlab.packet.IpAddress) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 33 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class ControllerConfigCiscoImpl method parseControllerInfo.

private List<ControllerInfo> parseControllerInfo(String data) {
    final String regex = "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):(\\d{1,5})";
    Pattern pattern = Pattern.compile(regex);
    Matcher match = pattern.matcher(data);
    List<ControllerInfo> controllers = new ArrayList<ControllerInfo>();
    while (match.find()) {
        String str = match.group();
        String[] ips = str.split(":");
        ControllerInfo info = new ControllerInfo(IpAddress.valueOf(ips[0]), Integer.parseInt(ips[1]), "tcp");
        controllers.add(info);
    }
    return controllers;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 34 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class DefaultKubevirtNodeHandler method createPhysicalBridgeWithConnectedMode.

private void createPhysicalBridgeWithConnectedMode(KubevirtNode osNode, KubevirtPhyInterface phyInterface) {
    Device device = deviceService.getDevice(osNode.ovsdb());
    IpAddress controllerIp = apiConfigService.apiConfig().controllerIp();
    String serviceFqdn = apiConfigService.apiConfig().serviceFqdn();
    IpAddress serviceIp = null;
    if (controllerIp == null) {
        if (serviceFqdn != null) {
            serviceIp = resolveHostname(serviceFqdn);
        }
        if (serviceIp != null) {
            controllerIp = serviceIp;
        } else {
            controllerIp = apiConfigService.apiConfig().ipAddress();
        }
    }
    ControllerInfo controlInfo = new ControllerInfo(controllerIp, DEFAULT_OFPORT, DEFAULT_OF_PROTO);
    List<ControllerInfo> controllers = Lists.newArrayList(controlInfo);
    String dpid = phyInterface.physBridge().toString().substring(DPID_BEGIN);
    String bridgeName = BRIDGE_PREFIX + phyInterface.network();
    BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).mcastSnoopingEnable().disableInBand().controllers(controllers);
    BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
    bridgeConfig.addBridge(builder.build());
}
Also used : Device(org.onosproject.net.Device) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 35 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo 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

ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)38 ArrayList (java.util.ArrayList)19 DeviceId (org.onosproject.net.DeviceId)11 IpAddress (org.onlab.packet.IpAddress)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Test (org.junit.Test)7 Device (org.onosproject.net.Device)6 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)6 BridgeDescription (org.onosproject.net.behaviour.BridgeDescription)6 DefaultBridgeDescription (org.onosproject.net.behaviour.DefaultBridgeDescription)6 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Objects (java.util.Objects)5 Collectors (java.util.stream.Collectors)5 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 DriverHandler (org.onosproject.net.driver.DriverHandler)5 Logger (org.slf4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4