Search in sources :

Example 31 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method getFlowEntry.

@Override
public FlowEntry getFlowEntry(NetworkId networkId, FlowRule rule) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(rule.deviceId());
    if (master == null) {
        log.debug("Failed to getFlowEntry: No master for {}, vnet {}", rule.deviceId(), networkId);
        return null;
    }
    if (Objects.equals(local, master)) {
        return flowTable.getFlowEntry(networkId, rule);
    }
    log.trace("Forwarding getFlowEntry to {}, which is the primary (master) " + "for device {}, vnet {}", master, rule.deviceId(), networkId);
    VirtualFlowRule vRule = new VirtualFlowRule(networkId, rule);
    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(vRule, GET_FLOW_ENTRY, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) VirtualFlowRule(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule)

Example 32 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method addOrUpdateFlowRule.

@Override
public FlowRuleEvent addOrUpdateFlowRule(NetworkId networkId, FlowEntry rule) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(rule.deviceId());
    if (Objects.equals(local, master)) {
        return addOrUpdateFlowRuleInternal(networkId, rule);
    }
    log.warn("Tried to update FlowRule {} state," + " while the Node was not the master.", rule);
    return null;
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService)

Example 33 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method removeFlowRule.

@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
    final DeviceId deviceId = rule.deviceId();
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (Objects.equals(local, master)) {
        // bypass and handle it locally
        return removeFlowRuleInternal(new VirtualFlowEntry(networkId, rule));
    }
    if (master == null) {
        log.warn("Failed to removeFlowRule: No master for {}", deviceId);
        // TODO: revisit if this should be null (="no-op") or Exception
        return null;
    }
    log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId);
    return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new VirtualFlowEntry(networkId, rule), REMOVE_FLOW_ENTRY, serializer::encode, serializer::decode, master));
}
Also used : VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) VirtualFlowEntry(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService)

Example 34 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method storeBatch.

@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation operation) {
    if (operation.getOperations().isEmpty()) {
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    DeviceId deviceId = operation.deviceId();
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("No master for {}, vnet {} : flows will be marked for removal", deviceId, networkId);
        updateStoreInternal(networkId, operation);
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    if (Objects.equals(local, master)) {
        storeBatchInternal(networkId, operation);
        return;
    }
    log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}, vent {}", master, deviceId, networkId);
    clusterCommunicator.unicast(new VirtualFlowRuleBatchOperation(networkId, operation), APPLY_BATCH_FLOWS, serializer::encode, master).whenComplete((result, error) -> {
        if (error != null) {
            log.warn("Failed to storeBatch: {} to {}", operation, master, error);
            Set<FlowRule> allFailures = operation.getOperations().stream().map(BatchOperationEntry::target).collect(Collectors.toSet());
            notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
        }
    });
}
Also used : VirtualFlowRuleBatchOperation(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRuleBatchOperation) VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) FlowRule(org.onosproject.net.flow.FlowRule) VirtualFlowRule(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Example 35 with MastershipService

use of org.onosproject.mastership.MastershipService 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)

Aggregations

MastershipService (org.onosproject.mastership.MastershipService)42 DeviceId (org.onosproject.net.DeviceId)30 DriverHandler (org.onosproject.net.driver.DriverHandler)20 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)20 NodeId (org.onosproject.cluster.NodeId)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)5 DeviceService (org.onosproject.net.device.DeviceService)5 ArrayList (java.util.ArrayList)4 ClusterService (org.onosproject.cluster.ClusterService)4 Set (java.util.Set)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)3 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)3 MastershipRole (org.onosproject.net.MastershipRole)3