use of org.projectfloodlight.openflow.protocol.action.OFActionSetField 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.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.
the class SwitchManagerTest method mockGetGroupsRequest.
private void mockGetGroupsRequest(List<Integer> groupIds) throws Exception {
List<OFGroupDescStatsEntry> meterConfigs = new ArrayList<>(groupIds.size());
for (Integer groupId : groupIds) {
OFBucket firstBucket = mock(OFBucket.class);
OFBucket secondBucket = mock(OFBucket.class);
OFActionSetField setDestMacAction = ofFactory.actions().buildSetField().setField(ofFactory.oxms().buildEthDst().setValue(convertDpIdToMac(dpid)).build()).build();
OFActionOutput sendToControllerAction = ofFactory.actions().output(OFPort.CONTROLLER, 0xFFFFFFFF);
TransportPort udpPort = TransportPort.of(LATENCY_PACKET_UDP_PORT);
OFActionSetField setUdpDstAction = ofFactory.actions().setField(ofFactory.oxms().udpDst(udpPort));
OFActionOutput sendInPortAction = ofFactory.actions().output(OFPort.IN_PORT, 0xFFFFFFFF);
expect(firstBucket.getActions()).andStubReturn(Lists.newArrayList(setDestMacAction, sendToControllerAction));
expect(secondBucket.getActions()).andStubReturn(Lists.newArrayList(setUdpDstAction, sendInPortAction));
OFGroupDescStatsEntry groupEntry = mock(OFGroupDescStatsEntry.class);
expect(groupEntry.getGroup()).andStubReturn(OFGroup.of(groupId));
expect(groupEntry.getBuckets()).andStubReturn(Lists.newArrayList(firstBucket, secondBucket));
replay(firstBucket, secondBucket, groupEntry);
meterConfigs.add(groupEntry);
}
OFGroupDescStatsReply statsReply = mock(OFGroupDescStatsReply.class);
expect(statsReply.getEntries()).andStubReturn(meterConfigs);
ListenableFuture<List<OFGroupDescStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
expect(iofSwitch.writeStatsRequest(isA(OFGroupDescStatsRequest.class))).andStubReturn(ofStatsFuture);
replay(statsReply, ofStatsFuture);
}
use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.
the class IngressServer42FlowInstallCommandTest method assertSetField.
private void assertSetField(OFAction action, Class<? extends OFOxm> type, Object value) {
assertEquals(OFActionType.SET_FIELD, action.getType());
OFActionSetField setFiledAction = (OFActionSetField) action;
assertTrue(type.isInstance(setFiledAction.getField()));
assertEquals(value, setFiledAction.getField().getValue());
}
use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.
the class FlowsResource method buildFlowInstructions.
private Map<String, Object> buildFlowInstructions(final List<OFInstruction> instructions) {
Map<String, Object> data = new HashMap<>();
for (OFInstruction instruction : instructions) {
Map<String, Object> instructionData = new HashMap<>();
OFInstructionType instructionType = instruction.getType();
switch(instructionType) {
case APPLY_ACTIONS:
for (OFAction action : ((OFInstructionApplyActions) instruction).getActions()) {
OFActionType actionType = action.getType();
switch(actionType) {
case // ver1.5
METER:
instructionData.put(actionType.toString(), ((OFActionMeter) action).getMeterId());
break;
case OUTPUT:
Optional.ofNullable(((OFActionOutput) action).getPort()).ifPresent(port -> instructionData.put(actionType.toString(), port.toString()));
break;
case POP_VLAN:
instructionData.put(actionType.toString(), null);
break;
case PUSH_VLAN:
Optional.ofNullable(((OFActionPushVlan) action).getEthertype()).ifPresent(ethType -> instructionData.put(actionType.toString(), ethType.toString()));
break;
case SET_FIELD:
OFOxm<?> setFieldAction = ((OFActionSetField) action).getField();
instructionData.put(actionType.toString(), String.format("%s->%s", setFieldAction.getValue(), setFieldAction.getMatchField().getName()));
break;
default:
instructionData.put(actionType.toString(), "could not parse");
break;
}
}
break;
case METER:
OFInstructionMeter action = ((OFInstructionMeter) instruction);
instructionData.put(instructionType.toString(), action.getMeterId());
break;
default:
instructionData.put(instructionType.toString(), "could not parse");
break;
}
data.put(instruction.getType().name(), instructionData);
}
return data;
}
use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.
the class IngressFlowLoopSegmentInstallCommandTest method assertSetField.
private void assertSetField(OFAction action, Class<? extends OFOxm> type, Object value) {
assertEquals(OFActionType.SET_FIELD, action.getType());
OFActionSetField setFiledAction = (OFActionSetField) action;
assertTrue(type.isInstance(setFiledAction.getField()));
assertEquals(value, setFiledAction.getField().getValue());
}
Aggregations