use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.
the class ConnectedDevicesRuleGeneratorTest method checkInstructionsOf15.
protected void checkInstructionsOf15(Instructions instructions, MeterId meterId) {
assertEquals(2, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) first;
assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
Action second = instructions.getApplyActions().get(1);
assertTrue(second instanceof MeterAction);
MeterAction meterAction = (MeterAction) second;
assertEquals(meterId, meterAction.getMeterId());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
}
use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.
the class UniCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
sw = buildSwitch("OF_15", Sets.newHashSet(METERS, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(2, match.size());
checkMatch(match);
// Check flow command has correct instructions for OF 1.5
Instructions instructions = flowCommandData.getInstructions();
assertEquals(3, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof MeterAction);
MeterAction meterAction = (MeterAction) first;
assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
checkPortOutAction(instructions.getApplyActions().get(1));
checkSetFieldAction(instructions.getApplyActions().get(2));
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
}
use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.
the class ArpPostIngressVxlanRuleGeneratorTest method checkInstructionsOf15.
@Override
protected void checkInstructionsOf15(Instructions instructions, MeterId meterId) {
assertEquals(3, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PopVxlanAction);
PopVxlanAction popVxlanAction = (PopVxlanAction) first;
assertEquals(ActionType.POP_VXLAN_NOVIFLOW, popVxlanAction.getType());
Action second = instructions.getApplyActions().get(1);
assertTrue(second instanceof PortOutAction);
PortOutAction portOutAction = (PortOutAction) second;
assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
Action third = instructions.getApplyActions().get(2);
assertTrue(third instanceof MeterAction);
MeterAction meterAction = (MeterAction) third;
assertEquals(meterId, meterAction.getMeterId());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
}
use of org.openkilda.rulemanager.action.MeterAction 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()));
}
}
use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
sw = buildSwitch("OF_15", Sets.newHashSet(NOVIFLOW_PUSH_POP_VXLAN, METERS, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
checkMatch(flowCommandData.getMatch());
// Check flow command has correct instructions for OF 1.5
Instructions instructions = flowCommandData.getInstructions();
assertEquals(4, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof PopVxlanAction);
PopVxlanAction popVxlanAction = (PopVxlanAction) first;
assertEquals(ActionType.POP_VXLAN_NOVIFLOW, popVxlanAction.getType());
Action second = instructions.getApplyActions().get(1);
assertTrue(second instanceof PortOutAction);
PortOutAction sendToControllerAction = (PortOutAction) second;
assertEquals(SpecialPortType.CONTROLLER, sendToControllerAction.getPortNumber().getPortType());
Action third = instructions.getApplyActions().get(3);
assertTrue(third instanceof MeterAction);
MeterAction meterAction = (MeterAction) third;
assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
}
Aggregations