blob: 4bd1aa53a233fbfc3e2ee4445a86a9be47671ae4 [file] [log] [blame]
Jonathan Hart26a8d952015-12-02 15:16:35 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053031import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType;
32import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi;
33import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp;
34import org.projectfloodlight.openflow.types.U16;
35import org.projectfloodlight.openflow.types.U32;
36import org.projectfloodlight.openflow.types.U8;
Jonathan Hart26a8d952015-12-02 15:16:35 -080037
38/**
39 * Interpreter for Nicira OpenFlow selector extensions.
40 */
41public class NiciraExtensionSelectorInterpreter
42 extends AbstractHandlerBehaviour
43 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
44
45 @Override
46 public boolean supported(ExtensionSelectorType extensionSelectorType) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +053047 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
48 return true;
49 }
50 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
51 return true;
52 }
53 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
54 return true;
55 }
56 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) {
57 return true;
58 }
59 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) {
60 return true;
61 }
62 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
63 return true;
64 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +053065 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE
66 .type())) {
67 return true;
68 }
Jonathan Hart26a8d952015-12-02 15:16:35 -080069 return false;
70 }
71
72 @Override
73 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +053074 ExtensionSelectorType type = extensionSelector.type();
Phaneendra Manda8db7d092016-06-04 00:17:24 +053075
Phaneendra Mandaefb38752015-12-04 00:43:38 +053076 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +053077 NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector;
78 return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId()));
Phaneendra Mandaefb38752015-12-04 00:43:38 +053079 }
80 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +053081 NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector;
82 return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex()));
83 }
84 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
85 NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector;
86 return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType()));
Phaneendra Mandaefb38752015-12-04 00:43:38 +053087 }
88 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
89 // TODO
90 }
91 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) {
92 // TODO
93 }
94 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) {
95 // TODO
96 }
97 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
98 // TODO
99 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800100 return null;
101 }
102
103 @Override
104 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530105
106 if (oxm.getMatchField() == MatchField.NSP) {
107 OFOxmNsp oxmField = (OFOxmNsp) oxm;
108 return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw()));
109 }
110 if (oxm.getMatchField() == MatchField.NSI) {
111 OFOxmNsi oxmField = (OFOxmNsi) oxm;
112 return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw()));
113 }
114 if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) {
115 OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm;
116 return new NiciraMatchEncapEthType(oxmField.getValue().getRaw());
117 }
118
Jonathan Hart26a8d952015-12-02 15:16:35 -0800119 return null;
120 }
121
122 @Override
123 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
Phaneendra Mandaefb38752015-12-04 00:43:38 +0530124 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
125 return new NiciraMatchNshSpi();
126 }
127 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
128 return new NiciraMatchNshSi();
129 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530130 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
131 return new NiciraMatchEncapEthType();
132 }
Phaneendra Mandaefb38752015-12-04 00:43:38 +0530133 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())
134 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())
135 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())
136 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
137 return new NiciraMatchNshContextHeader(type);
138 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800139 return null;
140 }
Jian Lidab72562016-04-12 14:10:32 -0700141
142 @Override
143 public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) {
144 // TODO
145 return null;
146 }
147
148 @Override
149 public ExtensionSelector decode(ObjectNode json, CodecContext context) {
150 // TODO
151 return null;
152 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800153}