use of org.onosproject.net.flow.instructions.L4ModificationInstruction in project onos by opennetworkinglab.
the class EncodeInstructionCodecHelper method encodeL4.
/**
* Encode a L4 modification instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodeL4(ObjectNode result) {
L4ModificationInstruction l4Instruction = (L4ModificationInstruction) instruction;
result.put(InstructionCodec.SUBTYPE, l4Instruction.subtype().name());
switch(l4Instruction.subtype()) {
case TCP_DST:
case TCP_SRC:
final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt());
break;
case UDP_DST:
case UDP_SRC:
final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt());
break;
default:
log.info("Cannot convert L4 subtype of {}", l4Instruction.subtype());
break;
}
}
use of org.onosproject.net.flow.instructions.L4ModificationInstruction 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));
}
use of org.onosproject.net.flow.instructions.L4ModificationInstruction in project onos by opennetworkinglab.
the class GroupModBuilder method buildL4Modification.
protected OFAction buildL4Modification(Instruction i) {
L4ModificationInstruction l4m = (L4ModificationInstruction) i;
L4ModificationInstruction.ModTransportPortInstruction tp;
OFOxm<?> oxm = null;
switch(l4m.subtype()) {
case TCP_SRC:
tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
oxm = factory.oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
break;
case TCP_DST:
tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
oxm = factory.oxms().tcpDst(TransportPort.of(tp.port().toInt()));
break;
case UDP_SRC:
tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
oxm = factory.oxms().udpSrc(TransportPort.of(tp.port().toInt()));
break;
case UDP_DST:
tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
oxm = factory.oxms().udpDst(TransportPort.of(tp.port().toInt()));
break;
default:
log.warn("Unimplemented action type {}.", l4m.subtype());
break;
}
if (oxm != null) {
return factory.actions().buildSetField().setField(oxm).build();
}
return null;
}
use of org.onosproject.net.flow.instructions.L4ModificationInstruction in project onos by opennetworkinglab.
the class HPPipelineV3 method tableIdForForwardingObjective.
@Override
protected int tableIdForForwardingObjective(TrafficSelector selector, TrafficTreatment treatment) {
boolean hardwareProcess = true;
log.debug("HP V3 Driver - Evaluating the ForwardingObjective for proper TableID");
// Check criteria supported in hardware
for (Criterion criterion : selector.criteria()) {
if (!this.hardwareCriteria.contains(criterion.type())) {
log.warn("HP V3 Driver - criterion {} only supported in SOFTWARE", criterion.type());
hardwareProcess = false;
break;
}
// HP3800 does not support hardware match on ETH_TYPE of value TYPE_VLAN
if (criterion.type() == Criterion.Type.ETH_TYPE) {
if (((EthTypeCriterion) criterion).ethType().toShort() == Ethernet.TYPE_VLAN) {
log.warn("HP V3 Driver - ETH_TYPE == VLAN (0x8100) is only supported in software");
hardwareProcess = false;
break;
}
}
}
// If criteria can be processed in hardware, then check treatment
if (hardwareProcess) {
for (Instruction instruction : treatment.allInstructions()) {
// Check if the instruction type is contained in the hardware instruction
if (!this.hardwareInstructions.contains(instruction.type())) {
log.warn("HP V3 Driver - instruction {} only supported in SOFTWARE", instruction.type());
hardwareProcess = false;
break;
}
/**
* If output is CONTROLLER_PORT the flow entry could be installed in hardware
* but is anyway processed in software because OPENFLOW header has to be added
*/
if (instruction.type() == Instruction.Type.OUTPUT) {
if (((Instructions.OutputInstruction) instruction).port() == PortNumber.CONTROLLER) {
log.warn("HP V3 Driver - Forwarding to CONTROLLER only supported in software");
hardwareProcess = false;
break;
}
}
// Check if the specific L2MODIFICATION.subtype is supported in hardware
if (instruction.type() == Instruction.Type.L2MODIFICATION) {
if (!this.hardwareInstructionsL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
log.warn("HP V3 Driver - L2MODIFICATION.subtype {} only supported in SOFTWARE", ((L2ModificationInstruction) instruction).subtype());
hardwareProcess = false;
break;
}
}
// Check if the specific L3MODIFICATION.subtype is supported in hardware
if (instruction.type() == Instruction.Type.L3MODIFICATION) {
if (!this.hardwareInstructionsL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
log.warn("HP V3 Driver - L3MODIFICATION.subtype {} only supported in SOFTWARE", ((L3ModificationInstruction) instruction).subtype());
hardwareProcess = false;
break;
}
}
// Check if the specific L4MODIFICATION.subtype is supported in hardware
if (instruction.type() == Instruction.Type.L4MODIFICATION) {
if (!this.hardwareInstructionsL4mod.contains(((L4ModificationInstruction) instruction).subtype())) {
log.warn("HP V3 Driver - L4MODIFICATION.subtype {} only supported in SOFTWARE", ((L4ModificationInstruction) instruction).subtype());
hardwareProcess = false;
break;
}
}
// TODO --- check if all the buckets contains one and only one output action
if (instruction.type() == Instruction.Type.GROUP) {
boolean groupInstalled = false;
GroupId groupId = ((Instructions.GroupInstruction) instruction).groupId();
Iterable<Group> groupsOnDevice = groupService.getGroups(deviceId);
for (Group group : groupsOnDevice) {
if ((group.state() == Group.GroupState.ADDED) && (group.id().equals(groupId))) {
groupInstalled = true;
if (group.type() != Group.Type.ALL) {
log.warn("HP V3 Driver - group type {} only supported in SOFTWARE", group.type().toString());
hardwareProcess = false;
}
break;
}
}
if (!groupInstalled) {
log.warn("HP V3 Driver - referenced group is not installed on the device.");
hardwareProcess = false;
}
}
}
}
if (hardwareProcess) {
log.warn("HP V3 Driver - This flow rule is supported in HARDWARE");
return HP_HARDWARE_TABLE;
} else {
// TODO: create a specific flow in table 100 to redirect selected traffic on table 200
log.warn("HP V3 Driver - This flow rule is only supported in SOFTWARE");
return HP_SOFTWARE_TABLE;
}
}
use of org.onosproject.net.flow.instructions.L4ModificationInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer13 method buildL4Modification.
protected OFAction buildL4Modification(Instruction i) {
L4ModificationInstruction l4m = (L4ModificationInstruction) i;
ModTransportPortInstruction tp;
OFOxm<?> oxm = null;
switch(l4m.subtype()) {
case TCP_SRC:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
break;
case TCP_DST:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().tcpDst(TransportPort.of(tp.port().toInt()));
break;
case UDP_SRC:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().udpSrc(TransportPort.of(tp.port().toInt()));
break;
case UDP_DST:
tp = (ModTransportPortInstruction) l4m;
oxm = factory().oxms().udpDst(TransportPort.of(tp.port().toInt()));
break;
default:
log.warn("Unimplemented action type {}.", l4m.subtype());
break;
}
if (oxm != null) {
return factory().actions().buildSetField().setField(oxm).build();
}
return null;
}
Aggregations