Search in sources :

Example 81 with FlowEntry

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

the class RoadmManager method removeConnection.

@Override
public void removeConnection(DeviceId deviceId, FlowId flowId) {
    checkNotNull(deviceId);
    checkNotNull(flowId);
    for (FlowEntry entry : flowRuleService.getFlowEntries(deviceId)) {
        if (entry.id().equals(flowId)) {
            flowRuleService.removeFlowRules(entry);
            log.info("Deleted connection {}", entry.id());
            break;
        }
    }
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 82 with FlowEntry

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

the class GnmiTerminalDeviceFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    // TODO: currently, we store flow rules in a cluster store. Should check if rule/config exists via gNMI.
    if (!setupBehaviour("getFlowEntries")) {
        return Collections.emptyList();
    }
    DeviceConnectionCache cache = getConnectionCache();
    Set<FlowRule> cachedRules = cache.get(deviceId);
    if (cachedRules == null) {
        return ImmutableList.of();
    }
    return cachedRules.stream().filter(Objects::nonNull).map(r -> new DefaultFlowEntry(r, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList());
}
Also used : FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) Gnmi(gnmi.Gnmi) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) OC_NAME(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) GnmiClient(org.onosproject.gnmi.api.GnmiClient) AbstractGrpcHandlerBehaviour(org.onosproject.grpc.utils.AbstractGrpcHandlerBehaviour) GnmiPathBuilder(org.onosproject.gnmi.api.GnmiUtils.GnmiPathBuilder) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) GnmiController(org.onosproject.gnmi.api.GnmiController) Collections(java.util.Collections) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Objects(java.util.Objects) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) FlowRule(org.onosproject.net.flow.FlowRule)

Example 83 with FlowEntry

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

the class RoadmCrossConnectCommand method dropRule.

/**
 * This function drops XC installed on the device, which is matching parsed criteria.
 * Takes as an input "global" parameters (passed by user through the console).
 * @return - returns number of the rules that were dropped.
 */
protected FlowId dropRule() {
    // Preparing parameters
    DeviceId device = DeviceId.deviceId(deviceId);
    PortNumber inPort = PortNumber.portNumber(srcPort);
    PortNumber outPort = PortNumber.portNumber(dstPort);
    // Creating some variables
    OchSignal ochSignal = null;
    PortNumber inputPortNumber = null;
    PortNumber outputPortNumber = null;
    // Main idea: Go over all flow rules (read out from the storage) of current device and
    // filter them based on input and output port with respect to OchSignal
    FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
    Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
    FlowId flowId = null;
    OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
    for (FlowEntry flowRule : flowRules) {
        // Taken from FlowRuleParser
        for (Criterion c : flowRule.selector().criteria()) {
            if (c instanceof OchSignalCriterion) {
                ochSignal = ((OchSignalCriterion) c).lambda();
            }
            if (c instanceof PortCriterion) {
                // obtain input port
                inputPortNumber = ((PortCriterion) c).port();
            }
        }
        for (Instruction i : flowRule.treatment().immediate()) {
            if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
                ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
            }
            if (i instanceof Instructions.OutputInstruction) {
                // obtain output port
                outputPortNumber = ((Instructions.OutputInstruction) i).port();
            }
        }
        // If we found match, then let's delete this rule
        if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
            flowId = flowRule.id();
            RoadmService manager = AbstractShellCommand.get(RoadmService.class);
            manager.removeConnection(device, flowId);
            print("Dropping existing XC from the device %s", deviceId);
            return flowId;
        }
    }
    return null;
}
Also used : DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) FlowId(org.onosproject.net.flow.FlowId) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) RoadmService(org.onosproject.roadm.RoadmService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 84 with FlowEntry

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

the class FlowRuleManagerTest method flowRemoved.

@Test
public void flowRemoved() {
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
    service.removeFlowRules(f1);
    // FIXME modification of "stored" flow entry outside of store
    fe1.setState(FlowEntryState.REMOVED);
    providerService.flowRemoved(fe1);
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
    providerService.flowRemoved(fe1);
    validateEvents();
    FlowRule f3 = flowRule(3, 3);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    service.applyFlowRules(f3);
    providerService.pushFlowMetrics(DID, Collections.singletonList(fe3));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
    providerService.flowRemoved(fe3);
    validateEvents();
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 85 with FlowEntry

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

the class FlowRuleManagerTest method extraneousFlow.

@Test
public void extraneousFlow() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    FlowRule f3 = flowRule(3, 3);
    mgr.applyFlowRules(f1, f2);
    // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
    // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
    // FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2, fe3));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)122 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)26 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 Instruction (org.onosproject.net.flow.instructions.Instruction)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 List (java.util.List)14 DeviceService (org.onosproject.net.device.DeviceService)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11