Search in sources :

Example 86 with FlowEntry

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

the class OfdpaPipelineTraceable method handleOutputFlows.

// Handles output flows
private List<FlowEntry> handleOutputFlows(TrafficSelector currentPacket, List<FlowEntry> outputFlows, TrafficSelector.Builder egressPacket, List<PortNumber> outputPorts, PipelineTraceableHitChain currentHitChain, PipelineTraceableOutput.Builder outputBuilder, TrafficSelector initialPacket) {
    // TODO optimization
    // outputFlows contains also last rule of device, so we need filtering for OUTPUT instructions.
    List<FlowEntry> outputFlowEntries = outputFlows.stream().filter(flow -> flow.treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).count() > 0).collect(Collectors.toList());
    if (outputFlowEntries.size() > 1) {
        outputBuilder.appendToLog("More than one flow rule with OUTPUT instruction");
        log.warn("There cannot be more than one flow entry with OUTPUT instruction for {}", currentPacket);
    }
    if (outputFlowEntries.size() == 1) {
        OutputInstruction outputInstruction = (OutputInstruction) outputFlowEntries.get(0).treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).findFirst().get();
        buildOutputFromDevice(egressPacket, outputPorts, outputInstruction, currentHitChain, outputBuilder, initialPacket, false);
    }
    return outputFlowEntries;
}
Also used : PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) PipelineTraceable(org.onosproject.net.behaviour.PipelineTraceable) L2_INTERFACE_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_INTERFACE_TYPE) TMAC_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.TMAC_TABLE) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IndexTableId(org.onosproject.net.flow.IndexTableId) VLAN_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.VLAN_TABLE) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) L3_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L3_MULTICAST_TYPE) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) EthType(org.onlab.packet.EthType) PipelineTraceableOutput(org.onosproject.net.PipelineTraceableOutput) List(java.util.List) PipelineTraceableInput(org.onosproject.net.PipelineTraceableInput) FlowRule(org.onosproject.net.flow.FlowRule) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Pipeliner(org.onosproject.net.behaviour.Pipeliner) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) BRIDGING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.BRIDGING_TABLE) TableId(org.onosproject.net.flow.TableId) ACL_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.ACL_TABLE) GroupBucket(org.onosproject.net.group.GroupBucket) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) OvsOfdpaPipeline(org.onosproject.driver.pipeline.ofdpa.OvsOfdpaPipeline) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket) L2_FLOOD_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_FLOOD_TYPE) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) MPLS_L3_TYPE_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MPLS_L3_TYPE_TABLE) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MULTICAST_ROUTING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MULTICAST_ROUTING_TABLE) Comparator(java.util.Comparator) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 87 with FlowEntry

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

the class DistributedVirtualFlowRuleStore method removeFlowRuleInternal.

private FlowRuleEvent removeFlowRuleInternal(VirtualFlowEntry rule) {
    final DeviceId deviceId = rule.flowEntry().deviceId();
    // This is where one could mark a rule as removed and still keep it in the store.
    final FlowEntry removed = flowTable.remove(rule.networkId(), deviceId, rule.flowEntry());
    // rule may be partial rule that is missing treatment, we should use rule from store instead
    return removed != null ? new FlowRuleEvent(RULE_REMOVED, removed) : null;
}
Also used : FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) VirtualFlowEntry(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry)

Example 88 with FlowEntry

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

the class DistributedStatisticStoreTest method testRemoveStatistic.

@Test
public void testRemoveStatistic() {
    FlowEntry flowEntry = makeFlowEntry(1);
    store.prepareForStatistics(flowEntry);
    store.addOrUpdateStatistic(flowEntry);
    cp1 = new ConnectPoint(flowEntry.deviceId(), PortNumber.portNumber(0));
    assertNotNull(store.getCurrentStatistic(cp1));
    store.removeFromStatistics(flowEntry);
    assertThat(store.getCurrentStatistic(cp1), is(empty()));
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 89 with FlowEntry

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

the class DistributedStatisticStoreTest method testAddStatistic.

@Test
public void testAddStatistic() {
    FlowEntry flowEntry2 = new DefaultFlowEntry(flowRule1);
    assertEquals("PENDING_ADD", flowEntry2.state().toString());
    FlowEntry flowTest1 = makeFlowEntry(1);
    store.prepareForStatistics(flowTest1);
    store.addOrUpdateStatistic(flowTest1);
    cp1 = new ConnectPoint(flowTest1.deviceId(), PortNumber.portNumber(0));
    ConnectPoint cp2 = new ConnectPoint(flowTest1.deviceId(), PortNumber.portNumber(1));
    assertThat("Current map should be null", store.getCurrentStatistic(cp2), is(nullValue()));
    Set<FlowEntry> currStatistic = store.getCurrentStatistic(cp1);
    int currTotal = 0;
    Iterator count = currStatistic.iterator();
    while (count.hasNext()) {
        count.next();
        currTotal++;
    }
    assertThat(currTotal, is(1));
    assertEquals(new NodeId("1"), nodeId);
    assertEquals("ADDED", flowTest1.state().toString());
    assertThat(store.getPreviousStatistic(cp1), is(empty()));
    FlowEntry flowTest2 = makeFlowEntry(10);
    ConnectPoint cp3 = new ConnectPoint(flowTest2.deviceId(), PortNumber.portNumber(0));
    store.addOrUpdateStatistic(flowTest2);
    Set<FlowEntry> prevStatistic = store.getPreviousStatistic(cp3);
    int prevTotal = 0;
    count = prevStatistic.iterator();
    while (count.hasNext()) {
        count.next();
        prevTotal++;
    }
    assertThat(prevTotal, is(1));
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Iterator(java.util.Iterator) NodeId(org.onosproject.cluster.NodeId) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 90 with FlowEntry

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

the class DefaultVirtualFlowRuleProviderTest method devirtualizeFlowRuleWithoutInPort.

@Test
public void devirtualizeFlowRuleWithoutInPort() {
    TrafficSelector ts = DefaultTrafficSelector.builder().build();
    TrafficTreatment tr = DefaultTrafficTreatment.builder().setOutput(PORT_NUM2).build();
    FlowRule r1 = DefaultFlowRule.builder().forDevice(VDID).withSelector(ts).withTreatment(tr).withPriority(10).fromApp(vAppId).makeTemporary(TIMEOUT).build();
    virtualProvider.applyFlowRule(VNET_ID, r1);
    assertEquals("3 rules should exist", 3, virtualProvider.flowRuleService.getFlowRuleCount());
    FlowRule inFromDID1 = null;
    FlowRule inFromDID2 = null;
    FlowRule out = null;
    Set<FlowEntry> phyRules = new HashSet<>();
    for (FlowEntry i : virtualProvider.flowRuleService.getFlowEntries(DID1)) {
        phyRules.add(i);
    }
    for (FlowEntry i : virtualProvider.flowRuleService.getFlowEntries(DID2)) {
        phyRules.add(i);
    }
    for (FlowRule rule : phyRules) {
        for (Instruction inst : rule.treatment().allInstructions()) {
            if (inst.type() == Instruction.Type.L2MODIFICATION) {
                L2ModificationInstruction i = (L2ModificationInstruction) inst;
                if (i.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
                    inFromDID1 = rule;
                    break;
                } else {
                    out = rule;
                    break;
                }
            } else {
                inFromDID2 = rule;
                break;
            }
        }
    }
    assertEquals(DID1, inFromDID1.deviceId());
    assertEquals(DID2, inFromDID2.deviceId());
    assertEquals(DID2, out.deviceId());
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)123 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)27 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 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)15 List (java.util.List)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