@Override public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { if (action.getType().equals(OFActionType.SET_FIELD)) { OFActionSetField setFieldAction = (OFActionSetField) action; OFOxm<?> oxm = setFieldAction.getField(); switch (oxm.getMatchField().id) { case VLAN_VID: OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm; return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid())); default: throw new UnsupportedOperationException( "Driver does not support extension type " + oxm.getMatchField().id); } } throw new UnsupportedOperationException( "Unexpected OFAction: " + action.toString()); }
public static void serializeFeaturesReply(OFFeaturesReply fr, JsonGenerator jGen) throws IOException, JsonProcessingException { /* Common to All OF Versions */ jGen.writeStringField("capabilities", fr.getCapabilities().toString()); jGen.writeStringField("dpid", fr.getDatapathId().toString()); jGen.writeNumberField("buffers", fr.getNBuffers()); jGen.writeNumberField("tables", fr.getNTables()); jGen.writeStringField("version", fr.getVersion().toString()); if (fr.getVersion().compareTo(OFVersion.OF_13) < 0) { // OF1.3+ break this out into port_config serializePortDesc(fr.getPorts(), jGen); } if (fr.getVersion().compareTo(OFVersion.OF_10) == 0) { String actions = "["; for (OFActionType action : fr.getActions()) { actions = actions + action.toString() + ", "; } actions = actions.substring(0, actions.length() - 2); // remove ending space+comma actions = actions + "]"; jGen.writeStringField("actions", actions); } }
/** * @param dpid * @param buffers * @param tables * @param capabilities * @param actions * @param ports * @param manufacturerDescription * @param hardwareDescription * @param softwareDescription * @param serialNumber * @param datapathDescription */ @JsonCreator public SwitchSyncRepresentation( @JsonProperty("dpid") DatapathId dpid, @JsonProperty("buffers") int buffers, @JsonProperty("tables") byte tables, @JsonProperty("capabilities") Set<OFCapabilities> capabilities, @JsonProperty("actions") Set<OFActionType> actions, @JsonProperty("ports") List<SyncedPort> ports, @JsonProperty("manufacturerDescription") String manufacturerDescription, @JsonProperty("hardwareDescription") String hardwareDescription, @JsonProperty("softwareDescription") String softwareDescription, @JsonProperty("serialNumber") String serialNumber, @JsonProperty("datapathDescription") String datapathDescription) { this.dpid = dpid; this.buffers = buffers; this.tables = tables; this.capabilities = capabilities; this.actions = actions; this.ports = ports; this.manufacturerDescription = manufacturerDescription; this.hardwareDescription = hardwareDescription; this.softwareDescription = softwareDescription; this.serialNumber = serialNumber; this.datapathDescription = datapathDescription; }
@JsonIgnore public OFFeaturesReply getFeaturesReply(OFFactory factory) { /** * FIXME Icky work around; if a null actions got written to storage * then fake up an empty one so the builder() doesn't throw * a NPE. Need to root cause why someone would write a null actions. * This code will all be removed shortly -- needed to unblock BVS team. */ Set<OFActionType> workAroundActions; if (actions != null) workAroundActions = actions; else workAroundActions = Collections.<OFActionType> emptySet(); OFFeaturesReply featuresReply = factory.buildFeaturesReply() .setXid(0) .setDatapathId(dpid) .setNBuffers(buffers) .setNTables(tables) .setCapabilities(capabilities) .setActions(workAroundActions) .setPorts(toOFPortDescList(factory, ports)) .build(); return featuresReply; }
protected void sendOFGroupModDelMemberMsg(IOFSwitch sw, OFPort destPort) { /* removes member port form the group*/ OFBucket ofb = multicastGroup.removeMemberOFBucket(sw.getId(), destPort); /* prepares a modify object sends it to the switch */ pushOFModifyGroup(sw); long queueId = -1; for (OFAction ofa: ofb.getActions()){ if (ofa.getType() == OFActionType.SET_QUEUE){ OFActionSetQueue ofas = (OFActionSetQueue) ofa; queueId = ofas.getQueueId(); } } /* removes queue using OVSDBContext on the switch */ OVSDBContext ovsdbContext = mcObject.ovsdbChannelMap.get(sw.getId()); ovsdbContext.deleteQueueOnPort(destPort, (int)queueId); }
/** * Applies all applicable FlowMods from a list of given FlowMods to the given Ethernet packet. The wrapperMessage is necessary for FlowMods that match on the InPort. * * @param flowMods The list of flowmods to apply. * @param original The packet to apply them to. * @param wrapperMessage The PakcetIn message that caused this. Needed for FlowMods that match on the InPort. * @return The modified packet. */ public static Ethernet applyFlowMods(final List<OFFlowMod> flowMods, Ethernet original, OFPacketIn wrapperMessage) { OFFlowMod matchingFlowMod = getFirstMatchingFlowMod(flowMods, original, wrapperMessage); Ethernet modified = (Ethernet) original.clone(); List<OFFlowMod> appliedFlowMods = new ArrayList<>(); while (matchingFlowMod != null && !appliedFlowMods.contains(matchingFlowMod)) { modified = (Ethernet) modified.clone(); for (OFAction action : matchingFlowMod.getActions()) { if (action.getType() == OFActionType.SET_TP_SRC) { ((TCP) modified.getPayload().getPayload()).setSourcePort((short) ((OFActionSetTpSrc) action).getTpPort().getPort()); } else if (action.getType() == OFActionType.SET_TP_DST) { ((TCP) modified.getPayload().getPayload()).setDestinationPort((short) ((OFActionSetTpDst) action).getTpPort().getPort()); } // TODO support more actions } appliedFlowMods.add(matchingFlowMod); matchingFlowMod = getFirstMatchingFlowMod(flowMods, modified, wrapperMessage); } return modified; }
public void serializeActions(Set<OFActionType> actions, JsonGenerator jGen) throws IOException, JsonProcessingException { if ( null == actions) jGen.writeStringField("actions","null"); else{ jGen.writeFieldName("actions"); jGen.writeStartArray(); for(OFActionType action : actions){ jGen.writeString(action.toString()); } jGen.writeEndArray(); } }
public void setUpFeaturesReply() { portDesc = factory.buildPortDesc() .setName("Eth1") .setPortNo(OFPort.of(1)) .build(); featuresReply = factory.buildFeaturesReply() .setDatapathId(DatapathId.of(0x42L)) .setNBuffers(1) .setNTables((short)1) .setCapabilities(EnumSet.<OFCapabilities>of(OFCapabilities.FLOW_STATS, OFCapabilities.TABLE_STATS)) .setActions(EnumSet.<OFActionType>of(OFActionType.SET_VLAN_PCP)) .setPorts(ImmutableList.<OFPortDesc>of(portDesc)) .build(); }
@Override OFFeaturesReply getFeaturesReply() { OFPortDesc portDesc = factory.buildPortDesc() .setName("Eth1") .setPortNo(OFPort.of(1)) .build(); return factory.buildFeaturesReply() .setDatapathId(dpid) .setNBuffers(1) .setNTables((short)1) .setCapabilities(EnumSet.<OFCapabilities>of(OFCapabilities.FLOW_STATS, OFCapabilities.TABLE_STATS)) .setActions(EnumSet.<OFActionType>of(OFActionType.SET_VLAN_PCP)) .setPorts(ImmutableList.<OFPortDesc>of(portDesc)) .build(); }