blob: 9053216627ac7969520063b5cbf9d7b56231dad0 [file] [log] [blame]
Jonathan Hart26a8d952015-12-02 15:16:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hart26a8d952015-12-02 15:16:35 -08003 *
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
Jian Lidab72562016-04-12 14:10:32 -070019import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053021import org.onosproject.net.NshServiceIndex;
22import org.onosproject.net.NshServicePathId;
Jonathan Hart26a8d952015-12-02 15:16:35 -080023import org.onosproject.net.behaviour.ExtensionSelectorResolver;
24import org.onosproject.net.driver.AbstractHandlerBehaviour;
25import org.onosproject.net.flow.criteria.ExtensionSelector;
26import org.onosproject.net.flow.criteria.ExtensionSelectorType;
27import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
28import org.projectfloodlight.openflow.protocol.OFFactory;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053029import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hart26a8d952015-12-02 15:16:35 -080030import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Frank Wang5733c382017-03-28 10:15:18 +080031import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackMark;
32import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackStateMasked;
33import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackZone;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053034import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType;
35import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi;
36import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp;
37import org.projectfloodlight.openflow.types.U16;
38import org.projectfloodlight.openflow.types.U32;
39import org.projectfloodlight.openflow.types.U8;
Jonathan Hart26a8d952015-12-02 15:16:35 -080040
41/**
42 * Interpreter for Nicira OpenFlow selector extensions.
43 */
44public class NiciraExtensionSelectorInterpreter
45 extends AbstractHandlerBehaviour
46 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
47
48 @Override
49 public boolean supported(ExtensionSelectorType extensionSelectorType) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +053050 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
51 return true;
52 }
53 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
54 return true;
55 }
56 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
57 return true;
58 }
59 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) {
60 return true;
61 }
62 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) {
63 return true;
64 }
65 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
66 return true;
67 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +053068 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE
69 .type())) {
70 return true;
71 }
Frank Wang5733c382017-03-28 10:15:18 +080072 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE
73 .type())) {
74 return true;
75 }
76 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE
77 .type())) {
78 return true;
79 }
80 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK
81 .type())) {
82 return true;
83 }
84 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_LABEL
85 .type())) {
86 return true;
87 }
Jonathan Hart26a8d952015-12-02 15:16:35 -080088 return false;
89 }
90
91 @Override
92 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +053093 ExtensionSelectorType type = extensionSelector.type();
Phaneendra Manda8db7d092016-06-04 00:17:24 +053094
Phaneendra Mandaefb38752015-12-04 00:43:38 +053095 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +053096 NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector;
97 return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId()));
Phaneendra Mandaefb38752015-12-04 00:43:38 +053098 }
99 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530100 NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector;
101 return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex()));
102 }
103 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
104 NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector;
105 return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType()));
Phaneendra Mandaefb38752015-12-04 00:43:38 +0530106 }
107 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
108 // TODO
109 }
110 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) {
111 // TODO
112 }
113 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) {
114 // TODO
115 }
116 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
117 // TODO
118 }
Frank Wang5733c382017-03-28 10:15:18 +0800119
120 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
121 NiciraMatchCtState niciraMatchCtState = (NiciraMatchCtState) extensionSelector;
122 return factory.oxms().conntrackStateMasked(U32.of(niciraMatchCtState.ctState()),
123 U32.of(niciraMatchCtState.ctStateMask()));
124 }
125 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
126 NiciraMatchCtZone niciraMatchCtZone = (NiciraMatchCtZone) extensionSelector;
127 return factory.oxms().conntrackZone(U16.of(niciraMatchCtZone.ctZone()));
128 }
129 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
130 NiciraMatchCtMark niciraMatchCtMark = (NiciraMatchCtMark) extensionSelector;
131 return factory.oxms().conntrackMark(U32.of(niciraMatchCtMark.ctMark()));
132 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800133 return null;
134 }
135
136 @Override
137 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530138
139 if (oxm.getMatchField() == MatchField.NSP) {
140 OFOxmNsp oxmField = (OFOxmNsp) oxm;
141 return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw()));
142 }
143 if (oxm.getMatchField() == MatchField.NSI) {
144 OFOxmNsi oxmField = (OFOxmNsi) oxm;
145 return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw()));
146 }
147 if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) {
148 OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm;
149 return new NiciraMatchEncapEthType(oxmField.getValue().getRaw());
150 }
Frank Wang5733c382017-03-28 10:15:18 +0800151 if (oxm.getMatchField() == MatchField.CONNTRACK_STATE) {
152 OFOxmConntrackStateMasked oxmField = (OFOxmConntrackStateMasked) oxm;
153 return new NiciraMatchCtState(oxmField.getValue().getRaw(), oxmField.getMask().getRaw());
154 }
155 if (oxm.getMatchField() == MatchField.CONNTRACK_ZONE) {
156 OFOxmConntrackZone oxmField = (OFOxmConntrackZone) oxm;
157 return new NiciraMatchCtZone(oxmField.getValue().getRaw());
158 }
159 if (oxm.getMatchField() == MatchField.CONNTRACK_MARK) {
160 OFOxmConntrackMark oxmField = (OFOxmConntrackMark) oxm;
161 return new NiciraMatchCtMark(oxmField.getValue().getRaw());
162 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800163 return null;
164 }
165
166 @Override
167 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +0530168 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
169 return new NiciraMatchNshSpi();
170 }
171 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
172 return new NiciraMatchNshSi();
173 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530174 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
175 return new NiciraMatchEncapEthType();
176 }
Phaneendra Mandaefb38752015-12-04 00:43:38 +0530177 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())
178 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())
179 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())
180 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
181 return new NiciraMatchNshContextHeader(type);
182 }
Frank Wang5733c382017-03-28 10:15:18 +0800183 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
184 return new NiciraMatchCtState();
185 }
186 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
187 return new NiciraMatchCtZone();
188 }
189 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
190 return new NiciraMatchCtMark();
191 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800192 return null;
193 }
Jian Lidab72562016-04-12 14:10:32 -0700194
195 @Override
196 public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) {
197 // TODO
198 return null;
199 }
200
201 @Override
202 public ExtensionSelector decode(ObjectNode json, CodecContext context) {
203 // TODO
204 return null;
205 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800206}