2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onosproject.driver.extensions;
19 import org.onlab.packet.Ip4Address;
20 import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
21 import org.onosproject.net.driver.AbstractHandlerBehaviour;
22 import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
25 import org.projectfloodlight.openflow.protocol.OFActionType;
26 import org.projectfloodlight.openflow.protocol.OFFactory;
27 import org.projectfloodlight.openflow.protocol.action.OFAction;
28 import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
29 import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
30 import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
31 import org.projectfloodlight.openflow.types.IPv4Address;
34 * Interpreter for Nicira OpenFlow extensions.
36 public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
40 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
41 if (extensionTreatmentType.equals(
42 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
45 if (extensionTreatmentType.equals(
46 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
49 if (extensionTreatmentType.equals(
50 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
57 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
58 ExtensionTreatmentType type = extensionTreatment.type();
59 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
60 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
61 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
62 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
64 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
65 // TODO this will be implemented later
67 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
68 // TODO this will be implemented later
74 public ExtensionTreatment mapAction(OFAction action) {
75 if (action.getType().equals(OFActionType.SET_FIELD)) {
76 OFActionSetField setFieldAction = (OFActionSetField) action;
77 OFOxm<?> oxm = setFieldAction.getField();
78 switch (oxm.getMatchField().id) {
80 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
81 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
83 throw new UnsupportedOperationException(
84 "Driver does not support extension type " + oxm.getMatchField().id);
91 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
92 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
93 return new NiciraSetTunnelDst();
95 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
96 return new NiciraResubmit();
98 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
99 return new NiciraSetNshSpi();
101 throw new UnsupportedOperationException(
102 "Driver does not support extension type " + type.toString());