use of org.openkilda.rulemanager.action.PushVlanAction in project open-kilda by telstra.
the class Server42FlowRttOutputVlanRuleGeneratorTest method shouldBuildCorrectRuleForOf13.
@Test
public void shouldBuildCorrectRuleForOf13() {
Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(1, commands.size());
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
assertTrue(flowCommandData.getDependsOn().isEmpty());
assertEquals(new Cookie(SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(SERVER_42_FLOW_RTT_OUTPUT_VLAN_PRIORITY, flowCommandData.getPriority());
Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(sw.getSwitchId().toMacAddressAsLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_PORT).build(), FieldMatch.builder().field(Field.UDP_DST).value(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT).build());
assertEquals(expectedMatch, flowCommandData.getMatch());
List<Action> expectedApplyActions = Lists.newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(Utils.SERVER_42_VLAN).build(), SetFieldAction.builder().field(Field.ETH_SRC).value(sw.getSwitchId().toMacAddressAsLong()).build(), SetFieldAction.builder().field(Field.ETH_DST).value(Utils.SERVER_42_MAC_ADDRESS.toLong()).build(), CopyFieldAction.builder().oxmSrcHeader(OpenFlowOxms.NOVIFLOW_TX_TIMESTAMP).oxmDstHeader(OpenFlowOxms.NOVIFLOW_UDP_PAYLOAD_OFFSET).srcOffset(0).dstOffset(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).numberOfBits(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).build(), new PortOutAction(new PortNumber(Utils.SERVER_42_PORT)));
Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
use of org.openkilda.rulemanager.action.PushVlanAction in project open-kilda by telstra.
the class IngressMirrorRuleGeneratorTest method oneSwitchFlowFullPortRuleTest.
@Test
public void oneSwitchFlowFullPortRuleTest() {
Flow flow = buildFlow(MULTI_TABLE_ONE_SWITCH_PATH, 0, 0, OUTER_VLAN_ID_2, 0);
IngressMirrorRuleGenerator generator = buildGenerator(MULTI_TABLE_ONE_SWITCH_PATH, flow, VLAN_ENCAPSULATION);
List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
assertEquals(2, commands.size());
FlowSpeakerData ingressCommand = getCommand(FlowSpeakerData.class, commands);
GroupSpeakerData groupCommand = getCommand(GroupSpeakerData.class, commands);
Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build());
List<Action> expectedIngressActions = newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_2).build(), new GroupAction(GROUP_ID));
assertIngressCommand(ingressCommand, Priority.MIRROR_DEFAULT_FLOW_PRIORITY, INGRESS, expectedIngressMatch, expectedIngressActions, null, groupCommand.getUuid());
Set<Action> expectedFlowBucketActions = newHashSet(new PortOutAction(new PortNumber(PORT_NUMBER_2)));
assertGroupCommand(groupCommand, expectedFlowBucketActions);
}
use of org.openkilda.rulemanager.action.PushVlanAction in project open-kilda by telstra.
the class MultiTableIngressRuleGeneratorTest method buildTransformActionsOneSwitchSingleVlanInDoubleVlanOutTest.
@Test
public void buildTransformActionsOneSwitchSingleVlanInDoubleVlanOutTest() {
Flow flow = buildFlow(ONE_SWITCH_PATH, OUTER_VLAN_ID_1, 0, OUTER_VLAN_ID_2, INNER_VLAN_ID_2);
MultiTableIngressRuleGenerator generator = buildGenerator(ONE_SWITCH_PATH, flow, VLAN_ENCAPSULATION);
List<Action> transformActions = generator.buildTransformActions(0, FEATURES);
List<Action> expectedActions = newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(INNER_VLAN_ID_2).build(), new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_2).build());
assertEquals(expectedActions, transformActions);
}
use of org.openkilda.rulemanager.action.PushVlanAction in project open-kilda by telstra.
the class MultiTableIngressRuleGeneratorTest method buildTransformActionsOneSwitchFullPortInDoubleVlanOutTest.
@Test
public void buildTransformActionsOneSwitchFullPortInDoubleVlanOutTest() {
Flow flow = buildFlow(ONE_SWITCH_PATH, 0, 0, OUTER_VLAN_ID_2, INNER_VLAN_ID_2);
MultiTableIngressRuleGenerator generator = buildGenerator(ONE_SWITCH_PATH, flow, VLAN_ENCAPSULATION);
List<Action> transformActions = generator.buildTransformActions(0, FEATURES);
List<Action> expectedActions = newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(INNER_VLAN_ID_2).build(), new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_2).build());
assertEquals(expectedActions, transformActions);
}
use of org.openkilda.rulemanager.action.PushVlanAction in project open-kilda by telstra.
the class OfInstructionsConverter method convertToRuleManagerAction.
/**
* Converts action.
*/
public Action convertToRuleManagerAction(OFAction action) {
switch(action.getType()) {
case PUSH_VLAN:
return new PushVlanAction();
case POP_VLAN:
return new PopVlanAction();
case METER:
OFActionMeter meterAction = (OFActionMeter) action;
MeterId meterId = new MeterId(meterAction.getMeterId());
return new MeterAction(meterId);
case GROUP:
OFActionGroup groupAction = (OFActionGroup) action;
GroupId groupId = new GroupId(groupAction.getGroup().getGroupNumber());
return new GroupAction(groupId);
case OUTPUT:
OFActionOutput outputAction = (OFActionOutput) action;
PortNumber portNumber = convertPort(outputAction.getPort());
return new PortOutAction(portNumber);
case EXPERIMENTER:
if (action instanceof OFActionNoviflowPushVxlanTunnel) {
OFActionNoviflowPushVxlanTunnel pushNoviVxlan = (OFActionNoviflowPushVxlanTunnel) action;
return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_NOVIFLOW).vni((int) pushNoviVxlan.getVni()).srcMacAddress(convertMac(pushNoviVxlan.getEthSrc())).dstMacAddress(convertMac(pushNoviVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Dst())).udpSrc(pushNoviVxlan.getUdpSrc()).build();
} else if (action instanceof OFActionKildaPushVxlanField) {
OFActionKildaPushVxlanField pushKildaVxlan = (OFActionKildaPushVxlanField) action;
return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_OVS).vni((int) pushKildaVxlan.getVni()).srcMacAddress(convertMac(pushKildaVxlan.getEthSrc())).dstMacAddress(convertMac(pushKildaVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Dst())).udpSrc(pushKildaVxlan.getUdpSrc()).build();
} else if (action instanceof OFActionNoviflowCopyField) {
OFActionNoviflowCopyField copyField = (OFActionNoviflowCopyField) action;
return CopyFieldAction.builder().numberOfBits(copyField.getNBits()).srcOffset(copyField.getSrcOffset()).dstOffset(copyField.getDstOffset()).oxmSrcHeader(convertOxmHeader(copyField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(copyField.getOxmDstHeader())).build();
} else if (action instanceof OFActionNoviflowSwapField) {
OFActionNoviflowSwapField swapField = (OFActionNoviflowSwapField) action;
return SwapFieldAction.builder().type(ActionType.NOVI_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
} else if (action instanceof OFActionKildaSwapField) {
OFActionKildaSwapField swapField = (OFActionKildaSwapField) action;
return SwapFieldAction.builder().type(ActionType.KILDA_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
} else if (action instanceof OFActionNoviflowPopVxlanTunnel) {
return new PopVxlanAction(ActionType.POP_VXLAN_NOVIFLOW);
} else if (action instanceof OFActionKildaPopVxlanField) {
return new PopVxlanAction(ActionType.POP_VXLAN_OVS);
} else {
throw new IllegalStateException(format("Unknown experimenter action %s", action.getType()));
}
case SET_FIELD:
OFActionSetField setFieldAction = (OFActionSetField) action;
return convertOxm(setFieldAction.getField());
case SET_VLAN_VID:
OFActionSetVlanVid setVlanVid = (OFActionSetVlanVid) action;
return SetFieldAction.builder().field(Field.VLAN_VID).value(setVlanVid.getVlanVid().getVlan()).build();
default:
throw new IllegalStateException(format("Unknown action type %s", action.getType()));
}
}
Aggregations