Search in sources :

Example 21 with ControllerInfo

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

the class JuniperUtils method getOpenFlowControllersFromConfig.

public static List<ControllerInfo> getOpenFlowControllersFromConfig(HierarchicalConfiguration cfg) {
    List<ControllerInfo> controllers = new ArrayList<>();
    String ipKey = "configuration.protocols.openflow.mode.ofagent-mode.controller.ip";
    if (!cfg.configurationsAt(ipKey).isEmpty()) {
        List<HierarchicalConfiguration> ipNodes = cfg.configurationsAt(ipKey);
        ipNodes.forEach(ipNode -> {
            int port = 0;
            String proto = UNKNOWN;
            HierarchicalConfiguration protocolNode = ipNode.configurationAt(PROTOCOL);
            HierarchicalConfiguration tcpNode = protocolNode.configurationAt(TCP);
            if (!tcpNode.isEmpty()) {
                String portString = tcpNode.getString(PORT);
                if (portString != null && !portString.isEmpty()) {
                    port = Integer.parseInt(portString);
                }
                proto = TCP;
            }
            String ipaddress = ipNode.getString(NAME);
            if (ipaddress == null) {
                ipaddress = UNKNOWN;
            }
            if (ipaddress.equals(UNKNOWN) || proto.equals(UNKNOWN) || port == 0) {
                log.error("Controller infomation is invalid. Skip this controller node." + " ipaddress: {}, proto: {}, port: {}", ipaddress, proto, port);
                return;
            }
            controllers.add(new ControllerInfo(IpAddress.valueOf(ipaddress), port, proto));
        });
    } else {
        log.error("Controller not present");
    }
    return controllers;
}
Also used : ArrayList(java.util.ArrayList) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 22 with ControllerInfo

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

the class NetconfControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId deviceId = handler.data().deviceId();
    Preconditions.checkNotNull(controller, "Netconf controller is null");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(deviceId)) {
        try {
            String reply = controller.getNetconfDevice(deviceId).getSession().getConfig(DatastoreId.RUNNING);
            log.debug("Reply XML {}", reply);
            controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate with device {} ", deviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
    }
    return controllers;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 23 with ControllerInfo

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

the class FujitsuVoltControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(ncDeviceId)) {
        try {
            StringBuilder request = new StringBuilder();
            request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
            request.append(buildEmptyTag(VOLT_OFCONFIG));
            request.append(VOLT_NE_CLOSE);
            String reply;
            reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
            log.debug("Reply XML {}", reply);
            controllers.addAll(parseStreamVoltControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} ", ncDeviceId);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
    }
    return ImmutableList.copyOf(controllers);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 24 with ControllerInfo

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

the class DellRestOpenFlowControllerConfig method getControllerCommands.

// Get controller commands for maximum first 2 controllers
private List<String> getControllerCommands(List<ControllerInfo> controllers) {
    List<String> controllerCommands = new ArrayList<>();
    for (int controllerNum = 0; controllerNum < MAX_CONTROLLERS; ++controllerNum) {
        if (controllers.size() > controllerNum) {
            ControllerInfo controllerInfo = controllers.get(controllerNum);
            // Only "tcp" type is supported
            if (controllerInfo.type().equals(TCP)) {
                String ip = controllerInfo.ip().toString();
                int port = controllerInfo.port();
                controllerCommands.add(String.format(SET_CONTROLLER, controllerNum + 1, ip, port));
            } else {
                log.warn("Controller type can only be 'tcp'");
                controllerCommands.add(String.format(NO_CONTROLLER, controllerNum + 1));
            }
        } else {
            // remove existing controller
            controllerCommands.add(String.format(NO_CONTROLLER, controllerNum + 1));
        }
    }
    return controllerCommands;
}
Also used : ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 25 with ControllerInfo

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

the class ControllerConfigAristaImpl method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    log.debug("Arista get Controllers");
    List<ControllerInfo> controllers = new ArrayList<>();
    Optional<JsonNode> res = AristaUtils.retrieveCommandResult(handler(), SHOW_CONTROLLER_CMD);
    if (res == null) {
        log.warn("There is no connected controller.");
        return controllers;
    }
    JsonNode controllerInfo = res.get().findValue(CONTROLLER_INFO);
    Iterator<JsonNode> controlleriter = controllerInfo.iterator();
    while (controlleriter.hasNext()) {
        JsonNode temp1 = controlleriter.next();
        if (temp1.has(CONTROLLER_ADDR)) {
            JsonNode controllerAddr = temp1.get(CONTROLLER_ADDR);
            if (controllerAddr.has(CONTROLLER_IP) && controllerAddr.has(CONTROLLER_PORT)) {
                String ip = controllerAddr.get(CONTROLLER_IP).asText();
                int port = controllerAddr.get(CONTROLLER_PORT).asInt();
                ControllerInfo info = new ControllerInfo(IpAddress.valueOf(ip), port, PROTOCOL_TCP);
                controllers.add(info);
                log.debug("Controller Information {}", info.target());
            }
        }
    }
    return ImmutableList.copyOf(controllers);
}
Also used : ArrayList(java.util.ArrayList) 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