blob: b6c786c0e075896b686e39df536c8fb411010b3e [file] [log] [blame]
Jonathan Hart3c259162015-10-21 21:31:19 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package org.onosproject.driver.extensions;
18
19import org.onlab.packet.Ip4Address;
alshabib880b6442015-11-23 22:13:04 -080020import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
Jonathan Hart3c259162015-10-21 21:31:19 -070021import org.onosproject.net.driver.AbstractHandlerBehaviour;
alshabib880b6442015-11-23 22:13:04 -080022import org.onosproject.net.flow.instructions.ExtensionTreatment;
23import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Jonathan Hart3c259162015-10-21 21:31:19 -070025import org.projectfloodlight.openflow.protocol.OFActionType;
26import org.projectfloodlight.openflow.protocol.OFFactory;
27import org.projectfloodlight.openflow.protocol.action.OFAction;
28import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
29import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
30import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
31import org.projectfloodlight.openflow.types.IPv4Address;
32
33/**
34 * Interpreter for Nicira OpenFlow extensions.
35 */
alshabib880b6442015-11-23 22:13:04 -080036public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
Jonathan Hart3c259162015-10-21 21:31:19 -070038
39 @Override
alshabib880b6442015-11-23 22:13:04 -080040 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
41 if (extensionTreatmentType.equals(
42 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070043 return true;
44 }
alshabib880b6442015-11-23 22:13:04 -080045 if (extensionTreatmentType.equals(
46 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080047 return true;
48 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053049 if (extensionTreatmentType.equals(
50 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
51 return true;
52 }
BitOhenry74dd7e12015-12-01 09:07:19 +080053 if (extensionTreatmentType.equals(
54 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
55 return true;
56 }
Jonathan Hart3c259162015-10-21 21:31:19 -070057 return false;
58 }
59
60 @Override
alshabib880b6442015-11-23 22:13:04 -080061 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
62 ExtensionTreatmentType type = extensionTreatment.type();
63 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
64 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -070065 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
66 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
67 }
alshabib880b6442015-11-23 22:13:04 -080068 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080069 // TODO this will be implemented later
70 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053071 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
72 // TODO this will be implemented later
73 }
BitOhenry74dd7e12015-12-01 09:07:19 +080074 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
75 // TODO this will be implemented later
76 }
Jonathan Hart3c259162015-10-21 21:31:19 -070077 return null;
78 }
79
80 @Override
alshabib880b6442015-11-23 22:13:04 -080081 public ExtensionTreatment mapAction(OFAction action) {
Jonathan Hart3c259162015-10-21 21:31:19 -070082 if (action.getType().equals(OFActionType.SET_FIELD)) {
83 OFActionSetField setFieldAction = (OFActionSetField) action;
84 OFOxm<?> oxm = setFieldAction.getField();
85 switch (oxm.getMatchField().id) {
86 case TUNNEL_IPV4_DST:
87 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
88 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
89 default:
90 throw new UnsupportedOperationException(
91 "Driver does not support extension type " + oxm.getMatchField().id);
92 }
93 }
94 return null;
95 }
96
97 @Override
alshabib880b6442015-11-23 22:13:04 -080098 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
99 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700100 return new NiciraSetTunnelDst();
101 }
alshabib880b6442015-11-23 22:13:04 -0800102 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +0800103 return new NiciraResubmit();
104 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530105 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
106 return new NiciraSetNshSpi();
107 }
BitOhenry74dd7e12015-12-01 09:07:19 +0800108 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
109 return new NiciraResubmitTable();
110 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700111 throw new UnsupportedOperationException(
112 "Driver does not support extension type " + type.toString());
113 }
114}