Search in sources :

Example 26 with ControllerInfo

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

the class DefaultOvsdbClient method getOvsdbBridge.

private OvsdbBridge getOvsdbBridge(Row row, Uuid bridgeUuid) {
    DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
    if (bridge == null) {
        return null;
    }
    OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
    @SuppressWarnings("unchecked") Set<String> datapathIds = datapathIdSet.set();
    if (datapathIds == null || datapathIds.isEmpty()) {
        return null;
    }
    String datapathId = (String) datapathIds.toArray()[0];
    String bridgeName = bridge.getName();
    if ((datapathId == null) || (bridgeName == null)) {
        return null;
    }
    List<Controller> controllers = getControllers(bridgeUuid);
    if (controllers != null) {
        List<ControllerInfo> controllerInfos = controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toList());
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).controllers(controllerInfos).build();
    } else {
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
    }
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) QUEUE_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY) Controller(org.onosproject.ovsdb.rfc.table.Controller) ColumnSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException) OFPORT(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT) PortNumber(org.onosproject.net.PortNumber) QueueId(org.onosproject.net.behaviour.QueueId) FromJsonUtil(org.onosproject.ovsdb.rfc.utils.FromJsonUtil) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Update(org.onosproject.ovsdb.rfc.operations.Update) Qos(org.onosproject.ovsdb.rfc.table.Qos) Callback(org.onosproject.ovsdb.rfc.jsonrpc.Callback) Set(java.util.Set) MIRRORS(org.onosproject.ovsdb.controller.OvsdbConstant.MIRRORS) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) MIRROR(org.onosproject.ovsdb.controller.OvsdbConstant.MIRROR) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) OvsdbStore(org.onosproject.ovsdb.controller.OvsdbStore) DeviceId(org.onosproject.net.DeviceId) DATABASENAME(org.onosproject.ovsdb.controller.OvsdbConstant.DATABASENAME) Interface(org.onosproject.ovsdb.rfc.table.Interface) JsonRpcWriterUtil(org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil) MirroringStatistics(org.onosproject.net.behaviour.MirroringStatistics) PORTS(org.onosproject.ovsdb.controller.OvsdbConstant.PORTS) ArrayList(java.util.ArrayList) DeviceCpuStats(org.onosproject.net.behaviour.DeviceCpuStats) Lists(com.google.common.collect.Lists) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) INTERFACE(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACE) BRIDGE_CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE_CONTROLLER) OvsdbPortName(org.onosproject.ovsdb.controller.OvsdbPortName) QUEUE(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE) QosId(org.onosproject.net.behaviour.QosId) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) EXTERNAL_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID) EXTERNAL_ID_INTERFACE_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID_INTERFACE_ID) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbTable(org.onosproject.ovsdb.rfc.table.OvsdbTable) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) Column(org.onosproject.ovsdb.rfc.notation.Column) MutationUtil(org.onosproject.ovsdb.rfc.utils.MutationUtil) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Row(org.onosproject.ovsdb.rfc.notation.Row) CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER) TableGenerator(org.onosproject.ovsdb.rfc.table.TableGenerator) ControlProtocolVersion(org.onosproject.net.behaviour.ControlProtocolVersion) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) OvsdbPortNumber(org.onosproject.ovsdb.controller.OvsdbPortNumber) OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) QOS_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EXTERNAL_ID_KEY) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) SettableFuture(com.google.common.util.concurrent.SettableFuture) DeviceMemoryStats(org.onosproject.net.behaviour.DeviceMemoryStats) QUEUES(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUES) Delete(org.onosproject.ovsdb.rfc.operations.Delete) UUID(org.onosproject.ovsdb.controller.OvsdbConstant.UUID) ConditionUtil(org.onosproject.ovsdb.rfc.utils.ConditionUtil) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) OFPORT_ERROR(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT_ERROR) TYPEVXLAN(org.onosproject.ovsdb.controller.OvsdbConstant.TYPEVXLAN) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) Queue(org.onosproject.ovsdb.rfc.table.Queue) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) Insert(org.onosproject.ovsdb.rfc.operations.Insert) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) BRIDGE(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) HashSet(java.util.HashSet) PORT(org.onosproject.ovsdb.controller.OvsdbConstant.PORT) ImmutableList(com.google.common.collect.ImmutableList) TableUpdates(org.onosproject.ovsdb.rfc.message.TableUpdates) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) PORT_QOS(org.onosproject.ovsdb.controller.OvsdbConstant.PORT_QOS) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) IpAddress(org.onlab.packet.IpAddress) Port(org.onosproject.ovsdb.rfc.table.Port) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) VersionMismatchException(org.onosproject.ovsdb.rfc.exception.VersionMismatchException) MirroringName(org.onosproject.net.behaviour.MirroringName) BRIDGES(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGES) Maps(com.google.common.collect.Maps) INTERFACES(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACES) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) QOS(org.onosproject.ovsdb.controller.OvsdbConstant.QOS) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Collections(java.util.Collections) Condition(org.onosproject.ovsdb.rfc.notation.Condition) Controller(org.onosproject.ovsdb.rfc.table.Controller) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 27 with ControllerInfo

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

the class ServerControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    List<ControllerInfo> controllers = Lists.newArrayList();
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    MastershipService mastershipService = getHandler().get(MastershipService.class);
    checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("I am not master for {}. " + "Please use master {} to get controllers for this device", deviceId, mastershipService.getMasterFor(deviceId));
        return controllers;
    }
    // Hit the path that provides the server's controllers
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_CONTROLLERS_GET, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get controllers of device: {}", deviceId);
        return controllers;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to get controllers of device: {}", deviceId);
        return controllers;
    }
    if (jsonMap == null) {
        log.error("Failed to get controllers of device: {}", deviceId);
        return controllers;
    }
    // Fetch controllers' array
    JsonNode ctrlNode = objNode.path(PARAM_CTRL);
    for (JsonNode cn : ctrlNode) {
        ObjectNode ctrlObjNode = (ObjectNode) cn;
        // Get the attributes of a controller
        String ctrlIpStr = get(cn, PARAM_CTRL_IP);
        int ctrlPort = ctrlObjNode.path(PARAM_CTRL_PORT).asInt();
        String ctrlType = get(cn, PARAM_CTRL_TYPE);
        // Implies no controller
        if (ctrlIpStr.isEmpty()) {
            continue;
        }
        // Check data format and range
        IpAddress ctrlIp = null;
        try {
            ctrlIp = IpAddress.valueOf(ctrlIpStr);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(e);
        }
        if ((ctrlPort < 0) || (ctrlPort > TpPort.MAX_PORT)) {
            final String msg = "Invalid controller port: " + ctrlPort;
            throw new IllegalArgumentException(msg);
        }
        controllers.add(new ControllerInfo(ctrlIp, ctrlPort, ctrlType));
    }
    return controllers;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MastershipService(org.onosproject.mastership.MastershipService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) IpAddress(org.onlab.packet.IpAddress) Map(java.util.Map) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 28 with ControllerInfo

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

the class XmlConfigParserTest method basics.

@Test
public void basics() throws IOException {
    InputStream stream = getClass().getResourceAsStream("/testConfig.xml");
    List<ControllerInfo> controllers = XmlConfigParser.parseStreamControllers(XmlConfigParser.loadXml(stream));
    assertTrue(controllers.get(0).equals(new ControllerInfo(IpAddress.valueOf("10.128.12.1"), 6653, "tcp")));
    assertTrue(controllers.get(1).equals(new ControllerInfo(IpAddress.valueOf("10.128.12.2"), 6654, "tcp")));
}
Also used : InputStream(java.io.InputStream) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 29 with ControllerInfo

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

the class XmlConfigParserTest method controllersConfig.

@Test
public void controllersConfig() {
    InputStream streamOrig = getClass().getResourceAsStream("/testConfig.xml");
    InputStream streamCfg = XmlConfigParser.class.getResourceAsStream("/controllers.xml");
    String config = XmlConfigParser.createControllersConfig(XmlConfigParser.loadXml(streamCfg), XmlConfigParser.loadXml(streamOrig), "running", "merge", "create", new ArrayList<>(Arrays.asList(new ControllerInfo(IpAddress.valueOf("192.168.1.1"), 5000, "tcp"))));
    assertTrue(config.contains("192.168.1.1"));
    assertTrue(config.contains("tcp"));
    assertTrue(config.contains("5000"));
}
Also used : InputStream(java.io.InputStream) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 30 with ControllerInfo

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

the class XmlConfigParser method parseStreamControllers.

public static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) {
    List<ControllerInfo> controllers = new ArrayList<>();
    List<HierarchicalConfiguration> fields = cfg.configurationsAt("data.capable-switch." + "logical-switches." + "switch.controllers.controller");
    for (HierarchicalConfiguration sub : fields) {
        controllers.add(new ControllerInfo(IpAddress.valueOf(sub.getString("ip-address")), Integer.parseInt(sub.getString("port")), sub.getString("protocol")));
    }
    return controllers;
}
Also used : ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) 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