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;
}
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;
}
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()));
}
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));
}
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());
}
Aggregations