use of org.projectfloodlight.openflow.protocol.action.OFActionExperimenter in project onos by opennetworkinglab.
the class Ofdpa3ExtensionTreatmentInterpreter method mapAction.
@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 OFDPA_MPLS_TYPE:
OFOxmOfdpaMplsType mplsType = (OFOxmOfdpaMplsType) oxm;
return new Ofdpa3SetMplsType(mplsType.getValue().getRaw());
case OFDPA_OVID:
OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm);
short mask = (short) 0x0FFF;
short oVid = (short) (mask & ovid.getValue().getRaw());
VlanId vlanId = VlanId.vlanId(oVid);
return new Ofdpa3SetOvid(vlanId);
case OFDPA_MPLS_L2_PORT:
OFOxmOfdpaMplsL2Port mplsl2Port = ((OFOxmOfdpaMplsL2Port) oxm);
Integer mplsL2Port = mplsl2Port.getValue().getRaw();
if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) || (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
return new Ofdpa3SetMplsL2Port(mplsL2Port);
}
break;
case OFDPA_QOS_INDEX:
OFOxmOfdpaQosIndex qosindex = ((OFOxmOfdpaQosIndex) oxm);
Integer qosIndex = (int) qosindex.getValue().getRaw();
if (qosIndex >= 0 && qosIndex <= 255) {
return new Ofdpa3SetQosIndex(qosIndex);
}
break;
case OFDPA_ALLOW_VLAN_TRANSLATION:
OFOxmOfdpaAllowVlanTranslation allowVlanTranslation = (OFOxmOfdpaAllowVlanTranslation) oxm;
Byte allowVlan = allowVlanTranslation.getValue().getRaw();
if ((allowVlan == 0) || (allowVlan == 1)) {
return new OfdpaSetAllowVlanTranslation(allowVlan);
}
break;
default:
throw new UnsupportedOperationException("Driver does not support extension type " + oxm.getMatchField().id);
}
} else if (action.getType().equals(OFActionType.EXPERIMENTER)) {
OFActionExperimenter experimenter = (OFActionExperimenter) action;
if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_OFDPA) {
OFActionOfdpa ofdpa = (OFActionOfdpa) experimenter;
switch(ofdpa.getExpType()) {
case SUB_TYPE_PUSH_L2_HEADER:
return new Ofdpa3PushL2Header();
case SUB_TYPE_POP_L2_HEADER:
return new Ofdpa3PopL2Header();
case SUB_TYPE_PUSH_CW:
return new Ofdpa3PushCw();
case SUB_TYPE_POP_CW:
return new Ofdpa3PopCw();
default:
throw new UnsupportedOperationException("Unexpected OFAction: " + action.toString());
}
} else if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_ONF) {
OFActionOnf onf = (OFActionOnf) experimenter;
switch(onf.getExpType()) {
case SUB_TYPE_COPY_FIELD:
return new Ofdpa3CopyField(((OFActionOnfCopyField) onf).getNBits(), ((OFActionOnfCopyField) onf).getSrcOffset(), ((OFActionOnfCopyField) onf).getDstOffset(), (int) ((OFActionOnfCopyField) onf).getSrc(), (int) ((OFActionOnfCopyField) onf).getDst());
default:
throw new UnsupportedOperationException("Unexpected OFAction: " + action.toString());
}
}
throw new UnsupportedOperationException("Unexpected OFAction: " + action.toString());
}
throw new UnsupportedOperationException("Unexpected OFAction: " + action.toString());
}
use of org.projectfloodlight.openflow.protocol.action.OFActionExperimenter in project onos by opennetworkinglab.
the class FlowEntryBuilder method configureTreatmentBuilder.
/**
* Configures traffic treatment builder with a given collection of actions.
*
* @param actions a set of OpenFlow actions
* @param builder traffic treatment builder
* @param driverHandler driver handler
* @param deviceId device identifier
* @return configured traffic treatment builder
*/
public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions, TrafficTreatment.Builder builder, DriverHandler driverHandler, DeviceId deviceId) {
ExtensionTreatmentInterpreter interpreter;
if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
} else {
interpreter = null;
}
for (OFAction act : actions) {
switch(act.getType()) {
case OUTPUT:
OFActionOutput out = (OFActionOutput) act;
builder.setOutput(PortNumber.portNumber(out.getPort().getPortNumber()));
break;
case SET_VLAN_VID:
OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
break;
case SET_VLAN_PCP:
OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
builder.setVlanPcp(pcp.getVlanPcp().getValue());
break;
case SET_DL_DST:
OFActionSetDlDst dldst = (OFActionSetDlDst) act;
builder.setEthDst(MacAddress.valueOf(dldst.getDlAddr().getLong()));
break;
case SET_DL_SRC:
OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
builder.setEthSrc(MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
break;
case SET_NW_DST:
OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
IPv4Address di = nwdst.getNwAddr();
builder.setIpDst(Ip4Address.valueOf(di.getInt()));
break;
case SET_NW_SRC:
OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
IPv4Address si = nwsrc.getNwAddr();
builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
break;
case EXPERIMENTER:
OFActionExperimenter exp = (OFActionExperimenter) act;
if (exp.getExperimenter() == 0x80005A06 || exp.getExperimenter() == 0x748771) {
OFActionCircuit ct = (OFActionCircuit) exp;
CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
builder.add(Instructions.modL0Lambda(Lambda.ochSignal(lookupGridType(circuitSignalID.getGridType()), lookupChannelSpacing(circuitSignalID.getChannelSpacing()), circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
} else if (interpreter != null) {
builder.extension(interpreter.mapAction(exp), deviceId);
} else {
log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
}
break;
case SET_FIELD:
OFActionSetField setField = (OFActionSetField) act;
handleSetField(builder, setField, driverHandler, deviceId);
break;
case POP_MPLS:
OFActionPopMpls popMpls = (OFActionPopMpls) act;
builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
break;
case PUSH_MPLS:
builder.pushMpls();
break;
case COPY_TTL_IN:
builder.copyTtlIn();
break;
case COPY_TTL_OUT:
builder.copyTtlOut();
break;
case DEC_MPLS_TTL:
builder.decMplsTtl();
break;
case DEC_NW_TTL:
builder.decNwTtl();
break;
case GROUP:
OFActionGroup group = (OFActionGroup) act;
builder.group(new GroupId(group.getGroup().getGroupNumber()));
break;
case SET_QUEUE:
OFActionSetQueue setQueue = (OFActionSetQueue) act;
builder.setQueue(setQueue.getQueueId());
break;
case ENQUEUE:
OFActionEnqueue enqueue = (OFActionEnqueue) act;
builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
break;
case STRIP_VLAN:
case POP_VLAN:
builder.popVlan();
break;
case PUSH_VLAN:
OFActionPushVlan pushVlan = (OFActionPushVlan) act;
builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
break;
case METER:
OFActionMeter actionMeter = (OFActionMeter) act;
builder.meter(MeterId.meterId(actionMeter.getMeterId()));
break;
case SET_TP_DST:
case SET_TP_SRC:
case POP_PBB:
case PUSH_PBB:
case SET_MPLS_LABEL:
case SET_MPLS_TC:
case SET_MPLS_TTL:
case SET_NW_ECN:
case SET_NW_TOS:
case SET_NW_TTL:
default:
log.warn("Action type {} not yet implemented.", act.getType());
}
}
return builder;
}
use of org.projectfloodlight.openflow.protocol.action.OFActionExperimenter in project onos by opennetworkinglab.
the class NiciraExtensionTreatmentInterpreter method mapAction.
@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 TUNNEL_IPV4_DST:
OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
case NSP:
OFOxmNsp nsp = (OFOxmNsp) oxm;
return new NiciraSetNshSpi(NshServicePathId.of((nsp.getValue().getRaw())));
case NSI:
OFOxmNsi nsi = (OFOxmNsi) oxm;
return new NiciraSetNshSi(NshServiceIndex.of((nsi.getValue().getRaw())));
case NSH_C1:
OFOxmNshC1 nshC1 = (OFOxmNshC1) oxm;
return new NiciraSetNshContextHeader(NshContextHeader.of((nshC1.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type());
case NSH_C2:
OFOxmNshC2 nshC2 = (OFOxmNshC2) oxm;
return new NiciraSetNshContextHeader(NshContextHeader.of((nshC2.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type());
case NSH_C3:
OFOxmNshC3 nshC3 = (OFOxmNshC3) oxm;
return new NiciraSetNshContextHeader(NshContextHeader.of((nshC3.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type());
case NSH_C4:
OFOxmNshC4 nshC4 = (OFOxmNshC4) oxm;
return new NiciraSetNshContextHeader(NshContextHeader.of((nshC4.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type());
case NSH_MDTYPE:
OFOxmNshMdtype nshMdType = (OFOxmNshMdtype) oxm;
return new NiciraNshMdType((nshMdType.getValue().getRaw()));
case NSH_NP:
OFOxmNshNp nshNp = (OFOxmNshNp) oxm;
return new NiciraNshNp((nshNp.getValue().getRaw()));
case ENCAP_ETH_SRC:
OFOxmEncapEthSrc encapEthSrc = (OFOxmEncapEthSrc) oxm;
return new NiciraEncapEthSrc(org.onlab.packet.MacAddress.valueOf((encapEthSrc.getValue().getBytes())));
case ENCAP_ETH_DST:
OFOxmEncapEthDst encapEthDst = (OFOxmEncapEthDst) oxm;
return new NiciraEncapEthDst(org.onlab.packet.MacAddress.valueOf((encapEthDst.getValue().getBytes())));
case ENCAP_ETH_TYPE:
OFOxmEncapEthType encapEthType = (OFOxmEncapEthType) oxm;
return new NiciraEncapEthType((encapEthType.getValue().getRaw()));
case TUN_GPE_NP:
OFOxmTunGpeNp tunGpeNp = (OFOxmTunGpeNp) oxm;
return new NiciraTunGpeNp((tunGpeNp.getValue().getRaw()));
default:
throw new UnsupportedOperationException("Driver does not support extension type " + oxm.getMatchField().id);
}
}
if (action.getType().equals(OFActionType.EXPERIMENTER)) {
OFActionExperimenter experimenter = (OFActionExperimenter) action;
if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_NICIRA) {
OFActionNicira nicira = (OFActionNicira) experimenter;
switch(nicira.getSubtype()) {
case SUB_TYPE_MOVE:
OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira;
switch(Long.valueOf(moveAction.getSrc()).intValue()) {
case SRC_ARP_SHA:
return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
case SRC_ETH:
return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
case SRC_IP:
return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
case SRC_ARP_SPA:
return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
case NSH_C1:
return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1();
case NSH_C2:
if (Long.valueOf(moveAction.getDst()).intValue() == TUN_ID) {
return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId();
}
return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2();
case NSH_C3:
return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3();
case NSH_C4:
return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4();
case TUN_IPV4_DST:
return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst();
case TUN_ID:
return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId();
default:
throw new UnsupportedOperationException("Driver does not support move from " + moveAction.getSrc() + " to " + moveAction.getDst() + "of length " + moveAction.getNBits());
}
case SUB_TYPE_RESUBMIT:
OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira;
return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort()));
case SUB_TYPE_PUSH_NSH:
return new NiciraPushNsh();
case SUB_TYPE_POP_NSH:
return new NiciraPopNsh();
case SUB_TYPE_RESUBMIT_TABLE:
OFActionNiciraResubmitTable resubmitTable = (OFActionNiciraResubmitTable) nicira;
return new NiciraResubmitTable(PortNumber.portNumber(resubmitTable.getInPort()), resubmitTable.getTable());
case SUB_TYPE_CT:
OFActionNiciraCt ctAction = (OFActionNiciraCt) nicira;
List<OFAction> actions = ctAction.getActions();
List<ExtensionTreatment> extensionActions = new ArrayList<>();
for (OFAction act : actions) {
OFActionExperimenter ctExperimenter = (OFActionExperimenter) act;
if (Long.valueOf(ctExperimenter.getExperimenter()).intValue() == TYPE_NICIRA) {
OFActionNicira actionNicira = (OFActionNicira) ctExperimenter;
switch(actionNicira.getSubtype()) {
case SUB_TYPE_LOAD:
OFActionNiciraLoad loadAction = (OFActionNiciraLoad) actionNicira;
extensionActions.add(new NiciraLoad(loadAction.getOfsNbits(), loadAction.getDst(), loadAction.getValue().getValue()));
break;
case SUB_TYPE_NAT:
OFActionNiciraNat natAction = (OFActionNiciraNat) actionNicira;
int portMin = 0;
int portMax = 0;
IpAddress ipAddressMin = IpAddress.valueOf(0);
IpAddress ipAddressMax = IpAddress.valueOf(0);
// FIXME: we need to get ipv6 and port from list<ipv4> temporarily,
// becase loxi don't know how to arrange these data to corresonding field.
IPv4Address[] arrays = (IPv4Address[]) natAction.getIpv4Range().toArray(new IPv4Address[0]);
int index = 0;
if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MIN) != 0) {
ipAddressMin = IpAddress.valueOf(arrays[index++].toString());
}
if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MAX) != 0) {
ipAddressMax = IpAddress.valueOf(arrays[index++].toString());
}
if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MIN) != 0) {
byte[] bytes = Bytes.concat(arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes());
ipAddressMin = IpAddress.valueOf(IpAddress.Version.INET6, bytes);
}
if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MAX) != 0) {
byte[] bytes = Bytes.concat(arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes());
ipAddressMax = IpAddress.valueOf(IpAddress.Version.INET6, bytes);
}
if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MIN) != 0) {
portMin = arrays[index].getInt() >> 16 & 0x0000ffff;
}
if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MAX) != 0) {
portMax = arrays[index].getInt() & 0x0000ffff;
}
NiciraNat natTreatment = new NiciraNat(natAction.getFlags(), natAction.getRangePresent(), portMin, portMax, ipAddressMin, ipAddressMax);
extensionActions.add(natTreatment);
break;
default:
throw new UnsupportedOperationException("Driver does not support nested" + " in ct action extension subtype " + actionNicira.getSubtype());
}
}
}
return new NiciraCt(ctAction.getFlags(), ctAction.getZoneSrc(), ctAction.getZone(), ctAction.getRecircTable(), ctAction.getAlg(), extensionActions);
case SUB_TYPE_CT_CLEAR:
return new NiciraCtClear();
case SUB_TYPE_LOAD:
OFActionNiciraLoad loadAction = (OFActionNiciraLoad) nicira;
return new NiciraLoad(loadAction.getOfsNbits(), loadAction.getDst(), loadAction.getValue().getValue());
default:
throw new UnsupportedOperationException("Driver does not support extension subtype " + nicira.getSubtype());
}
}
}
return null;
}
Aggregations