use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleManager method removeFlowRules.
@Override
public void removeFlowRules(FlowRule... flowRules) {
checkPermission(FLOWRULE_WRITE);
FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
for (FlowRule flowRule : flowRules) {
builder.remove(flowRule);
}
apply(builder.build());
}
use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.
the class FabricUpfTranslatorTest method uplinkUpfTerminationNoTcToFabricEntryTest.
@Test
public void uplinkUpfTerminationNoTcToFabricEntryTest() {
FlowRule translatedRule;
FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_UPF_TERMINATION_NO_TC;
try {
translatedRule = upfTranslator.upfTerminationUplinkToFabricEntry(TestUpfConstants.UPLINK_UPF_TERMINATION_NO_TC, TestUpfConstants.DEVICE_ID, TestUpfConstants.APP_ID, TestUpfConstants.DEFAULT_PRIORITY);
} catch (UpfProgrammableException e) {
assertThat("Abstract uplink UPF Termination should correctly " + "translate to Fabric UPF Termination without error", false);
return;
}
assertThat(translatedRule, equalTo(expectedRule));
assertThat(translatedRule.treatment(), equalTo(expectedRule.treatment()));
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManager method getFlowRulesByGroupId.
@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
DeviceService deviceService = manager.get(networkId(), DeviceService.class);
Set<FlowRule> matches = Sets.newHashSet();
long toLookUp = ((long) appId.id() << 16) | groupId;
for (Device d : deviceService.getDevices()) {
for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
if ((flowEntry.id().value() >>> 32) == toLookUp) {
matches.add(flowEntry);
}
}
}
return matches;
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class VirtualNetworkFlowRuleManager method applyFlowRules.
@Override
public void applyFlowRules(FlowRule... flowRules) {
FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
for (FlowRule flowRule : flowRules) {
builder.add(flowRule);
}
apply(builder.build());
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleCodecTest method decodeInstructionsFlowTest.
/**
* Checks that a rule with one of each instruction type decodes properly.
*
* @throws IOException if the resource cannot be processed
*/
@Test
public void decodeInstructionsFlowTest() throws Exception {
FlowRule rule = getRule("instructions-flow.json");
checkCommonData(rule);
rule.treatment().allInstructions().forEach(instruction -> {
String subType;
if (instruction.type() == Instruction.Type.L0MODIFICATION) {
subType = ((L0ModificationInstruction) instruction).subtype().name();
} else if (instruction.type() == Instruction.Type.L2MODIFICATION) {
subType = ((L2ModificationInstruction) instruction).subtype().name();
} else if (instruction.type() == Instruction.Type.L3MODIFICATION) {
subType = ((L3ModificationInstruction) instruction).subtype().name();
} else if (instruction.type() == Instruction.Type.L4MODIFICATION) {
subType = ((L4ModificationInstruction) instruction).subtype().name();
} else {
subType = "";
}
instructions.put(instruction.type().name() + "/" + subType, instruction);
});
assertThat(rule.treatment().allInstructions().size(), is(23));
Instruction instruction;
instruction = getInstruction(Instruction.Type.OUTPUT, "");
assertThat(instruction.type(), is(Instruction.Type.OUTPUT));
assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_SRC.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("12:34:56:78:90:12")));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_DST.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("98:76:54:32:01:00")));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_ID.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(), is((short) 22));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PCP.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(), is((byte) 1));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_LABEL.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction).label().toInt(), is(MplsLabel.MAX_MPLS));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_POP.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_POP.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PUSH.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction).tunnelId(), is(100L));
instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_SRC.name());
assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.4")));
instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_DST.name());
assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.3")));
instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_SRC.name());
assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.2")));
instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_DST.name());
assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.1")));
instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_FLABEL.name());
assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction).flowLabel(), is(8));
instruction = getInstruction(Instruction.Type.L0MODIFICATION, L0ModificationInstruction.L0SubType.OCH.name());
assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
L0ModificationInstruction.ModOchSignalInstruction och = (L0ModificationInstruction.ModOchSignalInstruction) instruction;
assertThat(och.lambda().spacingMultiplier(), is(4));
assertThat(och.lambda().slotGranularity(), is(8));
assertThat(och.lambda().gridType(), is(GridType.DWDM));
assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_DST.name());
assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40001));
instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_SRC.name());
assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40002));
instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_DST.name());
assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40003));
instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_SRC.name());
assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40004));
}
Aggregations