/** * Create an OFFlowMod that can be passed to StaticEntryPusher. * * @param sw switch object * @param match match for the flow * @param meter meter for the flow * @param actions actions for the flow * @param cookie cookie for the flow * @param priority priority to set on the flow * @return {@link OFFlowMod} */ private OFFlowMod buildFlowMod(final IOFSwitch sw, final Match match, final OFInstructionMeter meter, final OFInstructionApplyActions actions, final long cookie, final int priority) { OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setBufferId(OFBufferId.NO_BUFFER); fmb.setCookie(U64.of(cookie)); fmb.setPriority(priority); List<OFInstruction> instructions = new ArrayList<>(2); if (meter != null) { // If no meter then no bandwidth limit instructions.add(meter); } if (actions != null) { // If no instruction then Drops packet instructions.add(actions); } if (match != null) { // If no then match everything fmb.setMatch(match); } return fmb.setInstructions(instructions).build(); }
/** * Adds the instructions to the list of OFInstructions in the OFFlowMod. Any pre-existing * instruction of the same type is replaced with OFInstruction inst. * @param fmb, the flow mod to append the instruction to * @param inst, the instuction to append */ public static void appendInstruction(OFFlowMod.Builder fmb, OFInstruction inst) { List<OFInstruction> newIl = new ArrayList<OFInstruction>(); List<OFInstruction> oldIl = fmb.getInstructions(); if (oldIl != null) { // keep any existing instructions that were added earlier newIl.addAll(fmb.getInstructions()); } for (OFInstruction i : newIl) { // remove any duplicates. Only one of each instruction. if (i.getType() == inst.getType()) { newIl.remove(i); } } newIl.add(inst); fmb.setInstructions(newIl); }
private List<OFInstruction> getInstructions(OFFlowMod entry) { switch (entry.getVersion()) { case OF_10: return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions() .applyActions( entry.getActions())); case OF_11: case OF_12: case OF_13: case OF_14: case OF_15: return entry.getInstructions(); default: log.warn("Unknown OF version {}", entry.getVersion()); } return Lists.newLinkedList(); }
private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) { switch (entry.getVersion()) { case OF_10: return Lists.newArrayList( OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions())); case OF_11: case OF_12: case OF_13: case OF_14: case OF_15: return entry.getInstructions(); default: log.warn("Unknown OF version {}", entry.getVersion()); } return Lists.newLinkedList(); }
private List<OFInstruction> getInstructions(OFFlowMod entry) { switch (entry.getVersion()) { case OF_10: return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions() .applyActions( entry.getActions())); case OF_11: case OF_12: case OF_13: return entry.getInstructions(); default: log.warn("Unknown OF version {}", entry.getVersion()); } return Lists.newLinkedList(); }
private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) { switch (entry.getVersion()) { case OF_10: return Lists.newArrayList( OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions())); case OF_11: case OF_12: case OF_13: return entry.getInstructions(); default: log.warn("Unknown OF version {}", entry.getVersion()); } return Lists.newLinkedList(); }
private TrafficTreatment buildTreatment() { TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); for (OFInstruction in : instructions) { switch (in.getType()) { case GOTO_TABLE: builder.transition(((int) ((OFInstructionGotoTable) in) .getTableId().getValue())); break; case WRITE_METADATA: OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in; builder.writeMetadata(m.getMetadata().getValue(), m.getMetadataMask().getValue()); break; case WRITE_ACTIONS: builder.deferred(); buildActions(((OFInstructionWriteActions) in).getActions(), builder); break; case APPLY_ACTIONS: builder.immediate(); buildActions(((OFInstructionApplyActions) in).getActions(), builder); break; case CLEAR_ACTIONS: builder.wipeDeferred(); break; case EXPERIMENTER: break; case METER: break; default: log.warn("Unknown instructions type {}", in.getType()); } } return builder.build(); }
/** * Sets the actions in fmb according to the sw version. * * @param fmb the FlowMod Builder that is being built * @param actions the actions to set * @param sw the switch that will receive the FlowMod */ public static void setActions(OFFlowMod.Builder fmb, List<OFAction> actions, IOFSwitch sw) { if (sw.getOFFactory().getVersion().compareTo(OFVersion.OF_11) >= 0) { // Instructions are used starting in OF 1.1 fmb.setInstructions(Collections.singletonList((OFInstruction) sw .getOFFactory().instructions().applyActions(actions))); } else { // OF 1.0 only supports actions fmb.setActions(actions); } }
@Override public void transformAndSendMsg(OFMessage msg, TableType type) { if (msg.getType() == OFType.FLOW_MOD) { OFFlowMod flowMod = (OFFlowMod) msg; OFFlowMod.Builder builder = flowMod.createBuilder(); List<OFInstruction> instructions = flowMod.getInstructions(); List<OFInstruction> newInstructions = Lists.newArrayList(); for (OFInstruction i : instructions) { if (i instanceof OFInstructionGotoTable) { OFInstructionGotoTable gotoTable = (OFInstructionGotoTable) i; TableType tid = TableType.values()[gotoTable.getTableId().getValue()]; newInstructions.add( gotoTable.createBuilder() .setTableId(getTableId(tid)).build()); } else { newInstructions.add(i); } } builder.setTableId(getTableId(type)); builder.setInstructions(newInstructions); OFMessage msgnew = builder.build(); channel.write(Collections.singletonList(msgnew)); log.trace("Installed {}", msgnew); } else { channel.write(Collections.singletonList(msg)); } }
@Override public OFFlowAdd buildFlowAdd() { Match match = buildMatch(); List<OFAction> deferredActions = buildActions(treatment.deferred()); List<OFAction> immediateActions = buildActions(treatment.immediate()); List<OFInstruction> instructions = Lists.newLinkedList(); if (immediateActions.size() > 0) { instructions.add(factory().instructions().applyActions(immediateActions)); } if (treatment.clearedDeferred()) { instructions.add(factory().instructions().clearActions()); } if (deferredActions.size() > 0) { instructions.add(factory().instructions().writeActions(deferredActions)); } if (treatment.tableTransition() != null) { instructions.add(buildTableGoto(treatment.tableTransition())); } long cookie = flowRule().id().value(); OFFlowAdd fm = factory().buildFlowAdd() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setInstructions(instructions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().type().ordinal())) .build(); return fm; }
@Override public OFFlowMod buildFlowMod() { Match match = buildMatch(); List<OFAction> deferredActions = buildActions(treatment.deferred()); List<OFAction> immediateActions = buildActions(treatment.immediate()); List<OFInstruction> instructions = Lists.newLinkedList(); if (immediateActions.size() > 0) { instructions.add(factory().instructions().applyActions(immediateActions)); } if (treatment.clearedDeferred()) { instructions.add(factory().instructions().clearActions()); } if (deferredActions.size() > 0) { instructions.add(factory().instructions().writeActions(deferredActions)); } if (treatment.tableTransition() != null) { instructions.add(buildTableGoto(treatment.tableTransition())); } long cookie = flowRule().id().value(); OFFlowMod fm = factory().buildFlowModify() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setInstructions(instructions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().type().ordinal())) .build(); return fm; }
private TrafficTreatment buildTreatment() { TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); // If this is a drop rule if (instructions.size() == 0) { builder.drop(); return builder.build(); } for (OFInstruction in : instructions) { switch (in.getType()) { case GOTO_TABLE: builder.transition(tableType); break; case WRITE_METADATA: break; case WRITE_ACTIONS: builder.deferred(); buildActions(((OFInstructionWriteActions) in).getActions(), builder); break; case APPLY_ACTIONS: builder.immediate(); buildActions(((OFInstructionApplyActions) in).getActions(), builder); break; case CLEAR_ACTIONS: builder.wipeDeferred(); break; case EXPERIMENTER: break; case METER: break; default: log.warn("Unknown instructions type {}", in.getType()); } } return builder.build(); }
public static List<OFAction> getActions(OFFlowStatsEntry e) { if(e.getVersion() == OFVersion.OF_10) { return e.getActions(); } else { for(OFInstruction i: e.getInstructions()) { if(i.getType() == OFInstructionType.APPLY_ACTIONS) { return ((OFInstructionApplyActions) i).getActions(); } } return ImmutableList.of(); } }
public static List<OFAction> getActions(OFFlowMod e) { if(e.getVersion() == OFVersion.OF_10) { return e.getActions(); } else { for(OFInstruction i: e.getInstructions()) { if(i.getType() == OFInstructionType.APPLY_ACTIONS) { return ((OFInstructionApplyActions) i).getActions(); } } return ImmutableList.of(); } }
@Override public OFFlowMod buildFlowAdd() { Match match = buildMatch(); List<OFAction> deferredActions = buildActions(treatment.deferred()); List<OFAction> immediateActions = buildActions(treatment.immediate()); List<OFInstruction> instructions = Lists.newLinkedList(); if (treatment.clearedDeferred()) { instructions.add(factory().instructions().clearActions()); } if (immediateActions.size() > 0) { instructions.add(factory().instructions().applyActions(immediateActions)); } if (deferredActions.size() > 0) { instructions.add(factory().instructions().writeActions(deferredActions)); } if (treatment.tableTransition() != null) { instructions.add(buildTableGoto(treatment.tableTransition())); } if (treatment.writeMetadata() != null) { instructions.add(buildMetadata(treatment.writeMetadata())); } if (treatment.metered() != null) { instructions.add(buildMeter(treatment.metered())); } long cookie = flowRule().id().value(); OFFlowAdd fm = factory().buildFlowAdd() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setInstructions(instructions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().tableId())) .build(); return fm; }
@Override public OFFlowMod buildFlowMod() { Match match = buildMatch(); List<OFAction> deferredActions = buildActions(treatment.deferred()); List<OFAction> immediateActions = buildActions(treatment.immediate()); List<OFInstruction> instructions = Lists.newLinkedList(); if (immediateActions.size() > 0) { instructions.add(factory().instructions().applyActions(immediateActions)); } if (treatment.clearedDeferred()) { instructions.add(factory().instructions().clearActions()); } if (deferredActions.size() > 0) { instructions.add(factory().instructions().writeActions(deferredActions)); } if (treatment.tableTransition() != null) { instructions.add(buildTableGoto(treatment.tableTransition())); } if (treatment.writeMetadata() != null) { instructions.add(buildMetadata(treatment.writeMetadata())); } if (treatment.metered() != null) { instructions.add(buildMeter(treatment.metered())); } long cookie = flowRule().id().value(); OFFlowMod fm = factory().buildFlowModify() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setInstructions(instructions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().tableId())) .build(); return fm; }
private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) { OFInstruction instruction = factory().instructions().gotoTable( TableId.of(i.tableId())); return instruction; }
private OFInstruction buildMetadata(Instructions.MetadataInstruction m) { OFInstruction instruction = factory().instructions().writeMetadata( U64.of(m.metadata()), U64.of(m.metadataMask())); return instruction; }