use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class SwitchManager method installOuterVlanMatchSharedFlow.
@Override
public void installOuterVlanMatchSharedFlow(SwitchId switchId, String flowId, FlowSharedSegmentCookie cookie) throws SwitchOperationException {
IOFSwitch sw = lookupSwitch(DatapathId.of(switchId.toLong()));
OFFactory of = sw.getOFFactory();
RoutingMetadata metadata = RoutingMetadata.builder().outerVlanId(cookie.getVlanId()).build(featureDetectorService.detectSwitch(sw));
ImmutableList<OFInstruction> instructions = ImmutableList.of(of.instructions().applyActions(ImmutableList.of(of.actions().popVlan())), of.instructions().writeMetadata(metadata.getValue(), metadata.getMask()), of.instructions().gotoTable(TableId.of(SwitchManager.INGRESS_TABLE_ID)));
OFFlowMod flow = prepareFlowModBuilder(of, cookie.getValue(), FLOW_PRIORITY, PRE_INGRESS_TABLE_ID).setMatch(of.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(cookie.getPortNumber())).setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(cookie.getVlanId())).build()).setInstructions(instructions).build();
pushFlow(sw, flowId, flow);
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class UnicastVerificationVxlanRuleGenerator method buildUnicastVerificationRuleVxlan.
private OFFlowMod buildUnicastVerificationRuleVxlan(IOFSwitch sw, Set<SwitchFeature> features, long cookie, OFInstructionMeter meter, ArrayList<OFAction> actionList) {
OFFactory ofFactory = sw.getOFFactory();
if (features.contains(NOVIFLOW_PUSH_POP_VXLAN)) {
actionList.add(ofFactory.actions().noviflowPopVxlanTunnel());
} else {
actionList.add(ofFactory.actions().kildaPopVxlanField());
}
actionList.add(actionSendToController(sw.getOFFactory()));
MacAddress macAddress = convertDpIdToMac(sw.getId());
actionList.add(actionSetDstMac(sw.getOFFactory(), macAddress));
List<OFInstruction> instructions = new ArrayList<>(2);
if (meter != null) {
instructions.add(meter);
}
instructions.add(ofFactory.instructions().applyActions(actionList));
MacAddress srcMac = MacAddress.of(kildaCore.getConfig().getFlowPingMagicSrcMacAddress());
Match.Builder builder = sw.getOFFactory().buildMatch();
builder.setMasked(MatchField.ETH_SRC, srcMac, MacAddress.NO_MASK);
builder.setMasked(MatchField.ETH_DST, macAddress, MacAddress.NO_MASK);
builder.setExact(MatchField.ETH_TYPE, EthType.IPv4);
builder.setExact(MatchField.IP_PROTO, IpProtocol.UDP);
builder.setExact(MatchField.UDP_SRC, TransportPort.of(STUB_VXLAN_UDP_SRC));
return prepareFlowModBuilder(ofFactory, cookie, VERIFICATION_RULE_VXLAN_PRIORITY, INPUT_TABLE_ID).setInstructions(instructions).setMatch(builder.build()).build();
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class OfInstructionsConverterTest method convertInstructionsTest.
@Test
public void convertInstructionsTest() {
OFFactory factory = new OFFactoryVer13();
Instructions instructions = Instructions.builder().goToTable(OfTable.PRE_INGRESS).goToMeter(new MeterId(2)).writeMetadata(new OfMetadata(123, 234)).applyActions(buildActions()).build();
List<OFInstruction> actual = OfInstructionsConverter.INSTANCE.convertInstructions(instructions, factory);
assertEquals(4, actual.size());
assertTrue(actual.contains(factory.instructions().gotoTable(TableId.of(1))));
assertTrue(actual.contains(factory.instructions().buildMeter().setMeterId(2).build()));
assertTrue(actual.contains(factory.instructions().buildWriteMetadata().setMetadata(U64.of(123)).setMetadataMask(U64.of(234)).build()));
OFInstructionApplyActions applyActionsInstruction = (OFInstructionApplyActions) actual.get(3);
assertEquals(12, applyActionsInstruction.getActions().size());
List<OFAction> expectedActions = buildActions(factory);
assertTrue(applyActionsInstruction.getActions().containsAll(expectedActions));
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction 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;
}
Aggregations