Search in sources :

Example 41 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class ConnectivityIntentCodec method intentAttributes.

/**
 * Extracts connectivity intent specific attributes from a JSON object
 * and adds them to a builder.
 *
 * @param json root JSON object
 * @param context code context
 * @param builder builder to use for storing the attributes. Constraints,
 *                selector and treatment are modified by this call.
 */
public static void intentAttributes(ObjectNode json, CodecContext context, ConnectivityIntent.Builder builder) {
    JsonNode constraintsJson = json.get(CONSTRAINTS);
    if (constraintsJson != null) {
        JsonCodec<Constraint> constraintsCodec = context.codec(Constraint.class);
        ArrayList<Constraint> constraints = new ArrayList<>(constraintsJson.size());
        IntStream.range(0, constraintsJson.size()).forEach(i -> constraints.add(constraintsCodec.decode(get(constraintsJson, i), context)));
        builder.constraints(constraints);
    }
    ObjectNode selectorJson = get(json, SELECTOR);
    if (selectorJson != null) {
        JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        TrafficSelector selector = selectorCodec.decode(selectorJson, context);
        builder.selector(selector);
    }
    ObjectNode treatmentJson = get(json, TREATMENT);
    if (treatmentJson != null) {
        JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        TrafficTreatment treatment = treatmentCodec.decode(treatmentJson, context);
        builder.treatment(treatment);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 42 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class ConnectivityIntentCodec method encode.

@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
    checkNotNull(intent, "Connectivity intent cannot be null");
    final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
    final ObjectNode result = intentCodec.encode(intent, context);
    if (intent.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
    }
    if (intent.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
    }
    result.put(IntentCodec.PRIORITY, intent.priority());
    if (intent.constraints() != null) {
        final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
        if (intent.constraints() != null) {
            final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
            for (final Constraint constraint : intent.constraints()) {
                final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
                jsonConstraints.add(constraintNode);
            }
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 43 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchLineConnectionFromDevice.

private List<FlowRule> fetchLineConnectionFromDevice(String channel, Frequency centralFreq) {
    List<FlowRule> confirmedRules = new ArrayList<>();
    FlowRule cacheAddRule;
    FlowRule cacheDropRule;
    NetconfSession session = getNetconfSession();
    log.debug("fetchOpticalConnectionsFromDevice {} frequency {}", did(), centralFreq);
    // Build the corresponding flow rule as expected
    // Selector including port and ochSignal
    // Treatment including port
    PortNumber inputPortNumber = PortNumber.portNumber(channel);
    PortNumber outputPortNumber = PortNumber.portNumber(channel);
    log.debug("fetchOpticalConnectionsFromDevice {} port {}-{}", did(), inputPortNumber, outputPortNumber);
    TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).add(Criteria.matchLambda(toOchSignal(centralFreq, 50.0))).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).build();
    TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(outputPortNumber).build();
    TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).build();
    TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(toOchSignal(centralFreq, 50.0))).setOutput(outputPortNumber).build();
    // Retrieved rules and cached rules are considered equal if both selector and treatment are equal
    cacheAddRule = null;
    cacheDropRule = null;
    if (getConnectionCache().size(did()) != 0) {
        cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
        cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
    }
    // Include the DROP rule to the retrieved rules if found in cache
    if ((cacheDropRule != null)) {
        confirmedRules.add(cacheDropRule);
        log.debug("fetchOpticalConnectionsFromDevice {} DROP LINE rule included in the cache {}", did(), cacheDropRule);
    } else {
        log.warn("fetchOpticalConnectionsFromDevice {} DROP LINE rule not included in cache", did());
    }
    // Include the ADD rule to the retrieved rules if found in cache
    if ((cacheAddRule != null)) {
        confirmedRules.add(cacheAddRule);
        log.debug("fetchOpticalConnectionsFromDevice {} ADD LINE rule included in the cache {}", did(), cacheAddRule.selector());
    } else {
        log.warn("fetchOpticalConnectionsFromDevice {} ADD LINE rule not included in cache", did());
    }
    // If neither Add or Drop rules are present in the cache, remove configuration from the device
    if ((cacheDropRule == null) && (cacheAddRule == null)) {
        log.warn("fetchOpticalConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
        FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        try {
            // TODO this is not required if allowExternalFlowRules
            TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
            removeFlowRule(session, addRule);
            TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
            removeFlowRule(session, dropRule);
        } catch (NetconfException e) {
            openConfigError("Error removing LINE rule from device", e);
        }
    }
    return confirmedRules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) XPath(javax.xml.xpath.XPath) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) Spectrum(org.onlab.util.Spectrum) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController) Document(org.w3c.dom.Document) NamespaceContext(javax.xml.namespace.NamespaceContext) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) InputSource(org.xml.sax.InputSource) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) DatastoreId(org.onosproject.netconf.DatastoreId) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) StringReader(java.io.StringReader) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ChannelSpacing(org.onosproject.net.ChannelSpacing) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DeviceId(org.onosproject.net.DeviceId) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 44 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchClientConnectionFromDevice.

private List<FlowRule> fetchClientConnectionFromDevice(PortNumber clientPortNumber, PortNumber linePortNumber) {
    List<FlowRule> confirmedRules = new ArrayList<>();
    FlowRule cacheAddRule;
    FlowRule cacheDropRule;
    NetconfSession session = getNetconfSession();
    // Build the corresponding flow rule as expected
    // Selector including port
    // Treatment including port
    log.debug("fetchClientConnectionsFromDevice {} client {} line {}", did(), clientPortNumber, linePortNumber);
    TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(linePortNumber).build();
    TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(clientPortNumber).build();
    TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(clientPortNumber).build();
    TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().setOutput(linePortNumber).build();
    // Retrieved rules and cached rules are considered equal if both selector and treatment are equal
    cacheAddRule = null;
    cacheDropRule = null;
    if (getConnectionCache().size(did()) != 0) {
        cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
        cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
    }
    // Include the DROP rule to the retrieved rules if found in cache
    if ((cacheDropRule != null)) {
        confirmedRules.add(cacheDropRule);
        log.debug("fetchClientConnectionsFromDevice {} DROP CLIENT rule in the cache {}", did(), cacheDropRule);
    } else {
        log.warn("fetchClientConnectionsFromDevice {} DROP CLIENT rule not found in cache", did());
    }
    // Include the ADD rule to the retrieved rules if found in cache
    if ((cacheAddRule != null)) {
        confirmedRules.add(cacheAddRule);
        log.debug("fetchClientConnectionsFromDevice {} ADD CLIENT rule in the cache {}", did(), cacheAddRule);
    } else {
        log.warn("fetchClientConnectionsFromDevice {} ADD CLIENT rule not found in cache", did());
    }
    if ((cacheDropRule == null) && (cacheAddRule == null)) {
        log.warn("fetchClientConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
        FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        try {
            // TODO this is not required if allowExternalFlowRules
            TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
            removeFlowRule(session, addRule);
            TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
            removeFlowRule(session, dropRule);
        } catch (NetconfException e) {
            openConfigError("Error removing CLIENT rule from device", e);
        }
    }
    return confirmedRules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) XPath(javax.xml.xpath.XPath) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) Spectrum(org.onlab.util.Spectrum) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController) Document(org.w3c.dom.Document) NamespaceContext(javax.xml.namespace.NamespaceContext) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) InputSource(org.xml.sax.InputSource) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) DatastoreId(org.onosproject.netconf.DatastoreId) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) StringReader(java.io.StringReader) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ChannelSpacing(org.onosproject.net.ChannelSpacing) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DeviceId(org.onosproject.net.DeviceId) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 45 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class LumentumSdnRoadmFlowRuleProgrammable method fetchRules.

// Returns the currently installed flow entries on the device.
private List<FlowRule> fetchRules(OID oid, boolean isAdd, PortNumber linePort) {
    List<FlowRule> rules = new LinkedList<>();
    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            continue;
        }
        VariableBinding[] varBindings = event.getVariableBindings();
        for (VariableBinding varBinding : varBindings) {
            CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
            if (varBinding.getVariable().toInt() == IN_SERVICE) {
                int channel = varBinding.getOid().removeLast();
                PortNumber addDropPort = getAddDropPort(channel, isAdd);
                if (addDropPort == null) {
                    continue;
                }
                TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(isAdd ? addDropPort : linePort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(toOchSignal(channel))).build();
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(isAdd ? linePort : addDropPort).build();
                // Lookup flow ID and priority
                int hash = Objects.hash(data().deviceId(), selector, treatment);
                Pair<FlowId, Integer> lookup = cache.get(hash);
                if (lookup == null) {
                    continue;
                }
                FlowRule fr = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
                rules.add(fr);
            }
        }
    }
    return rules;
}
Also used : CrossConnectCache(org.onosproject.driver.optical.flowrule.CrossConnectCache) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) LinkedList(java.util.LinkedList) TreeEvent(org.snmp4j.util.TreeEvent) FlowId(org.onosproject.net.flow.FlowId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CrossConnectFlowRule(org.onosproject.driver.optical.flowrule.CrossConnectFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)395 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)369 TrafficSelector (org.onosproject.net.flow.TrafficSelector)257 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)236 FlowRule (org.onosproject.net.flow.FlowRule)93 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)86 PiAction (org.onosproject.net.pi.runtime.PiAction)79 Test (org.junit.Test)78 PortNumber (org.onosproject.net.PortNumber)70 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)56 Instruction (org.onosproject.net.flow.instructions.Instruction)52 DeviceId (org.onosproject.net.DeviceId)46 NextObjective (org.onosproject.net.flowobjective.NextObjective)45 ConnectPoint (org.onosproject.net.ConnectPoint)44 List (java.util.List)43 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)43 Ethernet (org.onlab.packet.Ethernet)40 Criterion (org.onosproject.net.flow.criteria.Criterion)39 GroupBucket (org.onosproject.net.group.GroupBucket)39 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)37