Search in sources :

Example 1 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy in project trellis-control by opennetworkinglab.

the class PolicyManager method redirectPolicyNextObjective.

private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
    Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
    Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
    List<DeviceId> edgeDevices = getEdgeDeviceIds();
    egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
    // No ports no friend
    if (egressPortsToEnforce.isEmpty()) {
        log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    // We need to add a treatment for each valid egress port. The treatment
    // requires to set src and dst mac address and set the egress port. We are
    // deliberately not providing the metadata to prevent the programming of
    // some tables which are already controlled by SegmentRouting or are unnecessary
    int nextId = flowObjectiveService.allocateNextId();
    DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
    MacAddress srcDeviceMac;
    try {
        srcDeviceMac = getDeviceMacAddress(srcDevice);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    MacAddress neigborDeviceMac;
    TrafficTreatment.Builder tBuilder;
    for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
        try {
            neigborDeviceMac = getDeviceMacAddress(entry.getValue());
        } catch (DeviceConfigNotFoundException e) {
            log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
            return null;
        }
        tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
        builder.addTreatment(tBuilder.build());
    }
    return builder;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) DeviceId(org.onosproject.net.DeviceId) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) Link(org.onosproject.net.Link)

Example 2 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy in project trellis-control by opennetworkinglab.

the class RedirectPolicyCodecTest method testDecode.

@Test
public void testDecode() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    InputStream jsonStream1 = RedirectPolicyCodecTest.class.getResourceAsStream("/redirectpolicy.json");
    ObjectNode json = mapper.readTree(jsonStream1).deepCopy();
    RedirectPolicy actual = codec.decode(json, context);
    assertEquals(redirectPolicy, actual);
}
Also used : RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy in project trellis-control by opennetworkinglab.

the class PolicyManager method installPolicyInDevice.

// Orchestrate policy installation according to the type
private void installPolicyInDevice(DeviceId deviceId, Policy policy) {
    if (!SUPPORTED_POLICIES.contains(policy.policyType())) {
        log.warn("Policy {} type {} not yet supported", policy.policyId(), policy.policyType());
        return;
    }
    PolicyKey policyKey;
    Operation.Builder operation;
    if (log.isDebugEnabled()) {
        log.debug("Installing {} policy {} for dev: {}", policy.policyType(), policy.policyId(), deviceId);
    }
    policyKey = new PolicyKey(deviceId, policy.policyId());
    // Prevent duplicate installation of the policies. With the current
    // implementation is not possible to update a policy since a change
    // in the params will create a new policy. Thus, there is no need to
    // check the equality like we do for the TM
    Operation oldPolicyOp = Versioned.valueOrNull(operations.get(policyKey.toString()));
    if (oldPolicyOp != null && oldPolicyOp.isInstall()) {
        if (log.isDebugEnabled()) {
            log.debug("There is already an install operation for policy {}", policy.policyId());
        }
        // If we add or submit a policy multiple times
        // We skip the installation update the policy state directly
        updatePolicy(policy.policyId(), true);
        return;
    }
    operation = Operation.builder().isInstall(true).policy(policy);
    // TODO To better handle different policy types consider the abstraction of a compiler (subtypes ?)
    if (policy.policyType() == PolicyType.DROP) {
        // DROP policies do not need the next objective installation phase
        // we can update directly the map and signal the ops as done
        operation.isDone(true);
        operations.put(policyKey.toString(), operation.build());
    } else if (policy.policyType() == PolicyType.REDIRECT) {
        // REDIRECT Uses next objective context to update the ops as done when
        // it returns successfully. In the other cases leaves the ops as undone
        // and the relative policy will remain in pending.
        operations.put(policyKey.toString(), operation.build());
        NextObjective.Builder builder = redirectPolicyNextObjective(deviceId, (RedirectPolicy) policy);
        // Handle error here - leave the operation as undone and pending
        if (builder != null) {
            CompletableFuture<Objective> future = new CompletableFuture<>();
            if (log.isDebugEnabled()) {
                log.debug("Installing REDIRECT next objective for dev: {}", deviceId);
            }
            ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
                if (log.isDebugEnabled()) {
                    log.debug("REDIRECT next objective for policy {} installed in dev: {}", policy.policyId(), deviceId);
                }
                future.complete(objective);
            }, (objective, error) -> {
                log.warn("Failed to install REDIRECT next objective for policy {}: {} in dev: {}", policy.policyId(), error, deviceId);
                future.complete(null);
            });
            // Context is not serializable
            NextObjective serializableObjective = builder.add();
            flowObjectiveService.next(deviceId, builder.add(context));
            future.whenComplete((objective, ex) -> {
                if (ex != null) {
                    log.error("Exception installing REDIRECT next objective", ex);
                } else if (objective != null) {
                    operations.computeIfPresent(policyKey.toString(), (k, v) -> {
                        if (!v.isDone() && v.isInstall()) {
                            v.isDone(true);
                            v.objectiveOperation(serializableObjective);
                        }
                        return v;
                    });
                }
            });
        }
    }
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Example 4 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy in project trellis-control by opennetworkinglab.

the class RedirectPolicyCodec method decode.

@Override
public RedirectPolicy decode(ObjectNode json, CodecContext context) {
    List<DeviceId> spinesToEnforce = new LinkedList<>();
    ObjectNode spinesNode = nullIsIllegal(get(json, SPINES_TO_ENFORCES), SPINES_TO_ENFORCES + MISSING_MEMBER_MESSAGE);
    ArrayNode deviceIdArr = nullIsIllegal((ArrayNode) spinesNode.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE);
    deviceIdArr.forEach(deviceId -> spinesToEnforce.add(DeviceId.deviceId(deviceId.textValue())));
    return new RedirectPolicy(Set.copyOf(spinesToEnforce));
}
Also used : RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) LinkedList(java.util.LinkedList)

Example 5 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy in project trellis-control by opennetworkinglab.

the class PolicyRedirectAddCommand method doExecute.

@Override
protected void doExecute() {
    Set<DeviceId> spinesToEnforce = spinesToEnforce();
    if (spinesToEnforce.isEmpty()) {
        print("Unable to submit redirect policy");
        return;
    }
    PolicyService policyService = AbstractShellCommand.get(PolicyService.class);
    PolicyId policyId = policyService.addOrUpdatePolicy(new RedirectPolicy(spinesToEnforce));
    print("Policy %s has been submitted", policyId);
}
Also used : RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId)

Aggregations

RedirectPolicy (org.onosproject.segmentrouting.policy.api.RedirectPolicy)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 DeviceId (org.onosproject.net.DeviceId)5 PolicyService (org.onosproject.segmentrouting.policy.api.PolicyService)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Produces (javax.ws.rs.Produces)3 DropPolicy (org.onosproject.segmentrouting.policy.api.DropPolicy)3 Policy (org.onosproject.segmentrouting.policy.api.Policy)3 PolicyType (org.onosproject.segmentrouting.policy.api.Policy.PolicyType)3 PolicyData (org.onosproject.segmentrouting.policy.api.PolicyData)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 HashFunction (com.google.common.hash.HashFunction)2 Hashing (com.google.common.hash.Hashing)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2