blob: b36423714cfec0ade6d8c54dd7045f6a6059ee72 [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/**
Jonathan Hart26a8d952015-12-02 15:16:35 -080034 * Interpreter for Nicira OpenFlow treatment extensions.
Jonathan Hart3c259162015-10-21 21:31:19 -070035 */
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 Mandaab5a7362015-12-02 01:10:01 +053049 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
50 return true;
51 }
52 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
53 return true;
54 }
55 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
56 return true;
57 }
58 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
59 return true;
60 }
61 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
62 return true;
63 }
64 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053065 return true;
66 }
BitOhenry74dd7e12015-12-01 09:07:19 +080067 if (extensionTreatmentType.equals(
68 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
69 return true;
70 }
samueljcc4a527ed2015-12-03 13:59:49 +080071 if (extensionTreatmentType.equals(
72 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
73 return true;
74 }
75 if (extensionTreatmentType.equals(
76 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
77 return true;
78 }
79 if (extensionTreatmentType.equals(
80 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
81 return true;
82 }
83 if (extensionTreatmentType.equals(
84 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
85 return true;
86 }
Jonathan Hart3c259162015-10-21 21:31:19 -070087 return false;
88 }
89
90 @Override
alshabib880b6442015-11-23 22:13:04 -080091 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
92 ExtensionTreatmentType type = extensionTreatment.type();
93 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
94 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -070095 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
96 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
97 }
alshabib880b6442015-11-23 22:13:04 -080098 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +080099 NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
100 return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(),
101 resubmit.table());
BitOhenryb53ac6c2015-11-16 20:58:58 +0800102 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530103 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
104 // TODO this will be implemented later
105 }
BitOhenry74dd7e12015-12-01 09:07:19 +0800106 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800107 NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
108 return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(),
109 resubmitTable.table());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530110 }
111 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
112 // TODO this will be implemented later
113 }
114 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
115 // TODO this will be implemented later
116 }
117 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
118 // TODO this will be implemented later
119 }
120 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
121 // TODO this will be implemented later
122 }
123 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
124 // TODO this will be implemented later
125 }
samueljcc4a527ed2015-12-03 13:59:49 +0800126 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
127 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
128 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
129 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
130 // TODO this will be implemented later
131 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700132 return null;
133 }
134
135 @Override
alshabib880b6442015-11-23 22:13:04 -0800136 public ExtensionTreatment mapAction(OFAction action) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700137 if (action.getType().equals(OFActionType.SET_FIELD)) {
138 OFActionSetField setFieldAction = (OFActionSetField) action;
139 OFOxm<?> oxm = setFieldAction.getField();
140 switch (oxm.getMatchField().id) {
141 case TUNNEL_IPV4_DST:
142 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
143 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
144 default:
145 throw new UnsupportedOperationException(
146 "Driver does not support extension type " + oxm.getMatchField().id);
147 }
148 }
149 return null;
150 }
151
152 @Override
alshabib880b6442015-11-23 22:13:04 -0800153 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
154 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700155 return new NiciraSetTunnelDst();
156 }
alshabib880b6442015-11-23 22:13:04 -0800157 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +0800158 return new NiciraResubmit();
159 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530160 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
161 return new NiciraResubmitTable();
162 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530163 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
164 return new NiciraSetNshSpi();
165 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530166 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
167 return new NiciraSetNshSi();
168 }
169 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())
170 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())
171 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())
172 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
173 return new NiciraSetNshContextHeader(type);
BitOhenry74dd7e12015-12-01 09:07:19 +0800174 }
samueljcc4a527ed2015-12-03 13:59:49 +0800175 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
176 return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
177 }
178 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
179 return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
180 }
181 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
182 return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
183 }
184 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
185 return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
186 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700187 throw new UnsupportedOperationException(
188 "Driver does not support extension type " + type.toString());
189 }
190}