blob: 1431ca13ec8f958fc03793abf9237a7a91a510cd [file] [log] [blame]
Pier Ventre6f630052016-10-18 09:58:41 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Pier Ventre6f630052016-10-18 09:58:41 -07003 *
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
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070019import com.fasterxml.jackson.databind.node.ObjectNode;
Pier Ventre6f630052016-10-18 09:58:41 -070020import org.onlab.packet.VlanId;
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070021import org.onosproject.codec.CodecContext;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070022import org.onosproject.net.PortNumber;
Pier Ventre6f630052016-10-18 09:58:41 -070023import 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.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
28import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
29import org.projectfloodlight.openflow.protocol.OFFactory;
30import org.projectfloodlight.openflow.protocol.match.MatchField;
31import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070032import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaActsetOutput;
33import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation;
Pier Ventre9cf536b2016-10-21 13:30:18 -070034import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port;
Pier Ventre6f630052016-10-18 09:58:41 -070035import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid;
Pier Ventre6f630052016-10-18 09:58:41 -070036import org.projectfloodlight.openflow.types.U16;
Pier Ventre9cf536b2016-10-21 13:30:18 -070037import org.projectfloodlight.openflow.types.U32;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070038import org.projectfloodlight.openflow.types.U8;
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070039import org.slf4j.Logger;
40
41import static org.slf4j.LoggerFactory.getLogger;
Pier Ventre6f630052016-10-18 09:58:41 -070042
43/**
44 * Interpreter for OFDPA3 OpenFlow selector extensions.
45 */
46public class Ofdpa3ExtensionSelectorInterpreter extends AbstractHandlerBehaviour
47 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
48
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070049 private final Logger log = getLogger(getClass());
50
Pier Ventre6f630052016-10-18 09:58:41 -070051 @Override
52 public boolean supported(ExtensionSelectorType extensionSelectorType) {
Charles Chand1172632017-03-15 17:33:09 -070053 if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -070054 return true;
Pier Ventre9cf536b2016-10-21 13:30:18 -070055 } else if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
56 return true;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070057 } else if (extensionSelectorType.equals(
58 ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
59 return true;
60 } else if (extensionSelectorType.equals(
61 ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
62 return true;
Pier Ventre6f630052016-10-18 09:58:41 -070063 }
64 return false;
65 }
66
67 @Override
68 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
69 ExtensionSelectorType type = extensionSelector.type();
Charles Chand1172632017-03-15 17:33:09 -070070 if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -070071 VlanId vlanId = ((Ofdpa3MatchOvid) extensionSelector).vlanId();
72 if (vlanId.equals(VlanId.NONE)) {
73 throw new UnsupportedOperationException(
74 "Unexpected ExtensionSelector: " + extensionSelector.toString());
75 } else if (vlanId.equals(VlanId.ANY)) {
76 throw new UnsupportedOperationException(
77 "Unexpected ExtensionSelector: " + extensionSelector.toString());
78 } else {
79 short mask = (short) 0x1000;
80 short oVid = (short) (mask | vlanId.toShort());
81 return factory.oxms().ofdpaOvid(U16.ofRaw(oVid));
82 }
Pier Ventre9cf536b2016-10-21 13:30:18 -070083 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
84 int mplsL2Port = ((Ofdpa3MatchMplsL2Port) extensionSelector).mplsL2Port();
85 /*
86 * 0x0000XXXX UNI Interface.
87 * 0x0002XXXX NNI Interface
88 */
89 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
90 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
91 return factory.oxms().ofdpaMplsL2Port(U32.ofRaw(mplsL2Port));
92 }
93 throw new UnsupportedOperationException(
94 "Unexpected ExtensionSelector: " + extensionSelector.toString());
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070095 } else if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
96 PortNumber port = ((OfdpaMatchActsetOutput) extensionSelector).port();
97 return factory.oxms().ofdpaActsetOutput(U32.of(port.toLong()));
98 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
99 Short allowVlanTranslation =
100 ((OfdpaMatchAllowVlanTranslation) extensionSelector).allowVlanTranslation();
101 return factory.oxms().ofdpaAllowVlanTranslation(U8.of(allowVlanTranslation));
Pier Ventre6f630052016-10-18 09:58:41 -0700102 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700103
Pier Ventre6f630052016-10-18 09:58:41 -0700104 throw new UnsupportedOperationException(
105 "Unexpected ExtensionSelector: " + extensionSelector.toString());
106 }
107
108 @Override
109 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
Charles Chand1172632017-03-15 17:33:09 -0700110 if (oxm.getMatchField().equals(MatchField.OFDPA_OVID)) {
Pier Ventre6f630052016-10-18 09:58:41 -0700111 VlanId vlanId;
112 if (oxm.isMasked()) {
113 throw new UnsupportedOperationException(
114 "Unexpected OXM: " + oxm.toString());
115 } else {
116 OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm);
117 short mask = (short) 0x0FFF;
118 short oVid = (short) (mask & ovid.getValue().getRaw());
119 vlanId = VlanId.vlanId(oVid);
120 }
121 return new Ofdpa3MatchOvid(vlanId);
Pier Ventre9cf536b2016-10-21 13:30:18 -0700122 } else if (oxm.getMatchField().equals(MatchField.OFDPA_MPLS_L2_PORT)) {
123 Integer mplsL2Port;
124 /*
125 * Supported but not used for now.
126 */
127 if (oxm.isMasked()) {
128 throw new UnsupportedOperationException(
129 "Unexpected OXM: " + oxm.toString());
130 } else {
131 OFOxmOfdpaMplsL2Port mplsl2port = ((OFOxmOfdpaMplsL2Port) oxm);
132 mplsL2Port = mplsl2port.getValue().getRaw();
133 /*
134 * 0x0000XXXX UNI Interface.
135 * 0x0002XXXX NNI Interface
136 */
137 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
138 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
139 return new Ofdpa3MatchMplsL2Port(mplsL2Port);
140 }
141 throw new UnsupportedOperationException(
142 "Unexpected OXM: " + oxm.toString());
143 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700144 } else if (oxm.getMatchField().equals(MatchField.OFDPA_ACTSET_OUTPUT)) {
145 U32 portNumberU32 = ((OFOxmOfdpaActsetOutput) oxm).getValue();
146 PortNumber portNumber = PortNumber.portNumber(portNumberU32.getValue());
147 return new OfdpaMatchActsetOutput(portNumber);
148 } else if (oxm.getMatchField().equals(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION)) {
149 U8 value = ((OFOxmOfdpaAllowVlanTranslation) oxm).getValue();
150 return new OfdpaMatchAllowVlanTranslation(value.getValue());
Pier Ventre6f630052016-10-18 09:58:41 -0700151 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700152
Pier Ventre6f630052016-10-18 09:58:41 -0700153 throw new UnsupportedOperationException(
154 "Unexpected OXM: " + oxm.toString());
155 }
156
157 @Override
158 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
Charles Chand1172632017-03-15 17:33:09 -0700159 if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -0700160 return new Ofdpa3MatchOvid();
Pier Ventre9cf536b2016-10-21 13:30:18 -0700161 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
162 return new Ofdpa3MatchMplsL2Port();
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700163 } else if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
164 return new OfdpaMatchActsetOutput();
165 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
166 return new OfdpaMatchAllowVlanTranslation();
Pier Ventre6f630052016-10-18 09:58:41 -0700167 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700168
Pier Ventre6f630052016-10-18 09:58:41 -0700169 throw new UnsupportedOperationException(
170 "Driver does not support extension type " + type.toString());
171 }
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700172
173 @Override
174 public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) {
175 // TODO
176 log.warn("The encode method of Ofdpa3ExtensionSelectorInterpreter hasn't been implemented");
177 return null;
178 }
179
180 @Override
181 public ExtensionSelector decode(ObjectNode json, CodecContext context) {
182 // TODO
183 log.warn("The decode method of Ofdpa3ExtensionSelectorInterpreter hasn't been implemented");
184 return null;
185 }
Pier Ventre6f630052016-10-18 09:58:41 -0700186}