blob: 5ac9cf3c4d63171928bf6d96da199f4e5eeb5f87 [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;
Pier Ventre6f630052016-10-18 09:58:41 -070022import org.onosproject.net.behaviour.ExtensionSelectorResolver;
23import org.onosproject.net.driver.AbstractHandlerBehaviour;
24import org.onosproject.net.flow.criteria.ExtensionSelector;
25import org.onosproject.net.flow.criteria.ExtensionSelectorType;
26import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
27import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
28import org.projectfloodlight.openflow.protocol.OFFactory;
29import org.projectfloodlight.openflow.protocol.match.MatchField;
30import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Pier Ventre9cf536b2016-10-21 13:30:18 -070031import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port;
Pier Ventre6f630052016-10-18 09:58:41 -070032import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid;
Pier Ventre6f630052016-10-18 09:58:41 -070033import org.projectfloodlight.openflow.types.U16;
Pier Ventre9cf536b2016-10-21 13:30:18 -070034import org.projectfloodlight.openflow.types.U32;
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070035import org.slf4j.Logger;
36
37import static org.slf4j.LoggerFactory.getLogger;
Pier Ventre6f630052016-10-18 09:58:41 -070038
39/**
40 * Interpreter for OFDPA3 OpenFlow selector extensions.
41 */
42public class Ofdpa3ExtensionSelectorInterpreter extends AbstractHandlerBehaviour
43 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
44
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070045 private final Logger log = getLogger(getClass());
46
Pier Ventre6f630052016-10-18 09:58:41 -070047 @Override
48 public boolean supported(ExtensionSelectorType extensionSelectorType) {
Charles Chand1172632017-03-15 17:33:09 -070049 if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -070050 return true;
Pier Ventre9cf536b2016-10-21 13:30:18 -070051 } else if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
52 return true;
Pier Ventre6f630052016-10-18 09:58:41 -070053 }
54 return false;
55 }
56
57 @Override
58 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
59 ExtensionSelectorType type = extensionSelector.type();
Charles Chand1172632017-03-15 17:33:09 -070060 if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -070061 VlanId vlanId = ((Ofdpa3MatchOvid) extensionSelector).vlanId();
62 if (vlanId.equals(VlanId.NONE)) {
63 throw new UnsupportedOperationException(
64 "Unexpected ExtensionSelector: " + extensionSelector.toString());
65 } else if (vlanId.equals(VlanId.ANY)) {
66 throw new UnsupportedOperationException(
67 "Unexpected ExtensionSelector: " + extensionSelector.toString());
68 } else {
69 short mask = (short) 0x1000;
70 short oVid = (short) (mask | vlanId.toShort());
71 return factory.oxms().ofdpaOvid(U16.ofRaw(oVid));
72 }
Pier Ventre9cf536b2016-10-21 13:30:18 -070073 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
74 int mplsL2Port = ((Ofdpa3MatchMplsL2Port) extensionSelector).mplsL2Port();
75 /*
76 * 0x0000XXXX UNI Interface.
77 * 0x0002XXXX NNI Interface
78 */
79 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
80 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
81 return factory.oxms().ofdpaMplsL2Port(U32.ofRaw(mplsL2Port));
82 }
83 throw new UnsupportedOperationException(
84 "Unexpected ExtensionSelector: " + extensionSelector.toString());
Pier Ventre6f630052016-10-18 09:58:41 -070085 }
86 throw new UnsupportedOperationException(
87 "Unexpected ExtensionSelector: " + extensionSelector.toString());
88 }
89
90 @Override
91 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
Charles Chand1172632017-03-15 17:33:09 -070092 if (oxm.getMatchField().equals(MatchField.OFDPA_OVID)) {
Pier Ventre6f630052016-10-18 09:58:41 -070093 VlanId vlanId;
94 if (oxm.isMasked()) {
95 throw new UnsupportedOperationException(
96 "Unexpected OXM: " + oxm.toString());
97 } else {
98 OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm);
99 short mask = (short) 0x0FFF;
100 short oVid = (short) (mask & ovid.getValue().getRaw());
101 vlanId = VlanId.vlanId(oVid);
102 }
103 return new Ofdpa3MatchOvid(vlanId);
Pier Ventre9cf536b2016-10-21 13:30:18 -0700104 } else if (oxm.getMatchField().equals(MatchField.OFDPA_MPLS_L2_PORT)) {
105 Integer mplsL2Port;
106 /*
107 * Supported but not used for now.
108 */
109 if (oxm.isMasked()) {
110 throw new UnsupportedOperationException(
111 "Unexpected OXM: " + oxm.toString());
112 } else {
113 OFOxmOfdpaMplsL2Port mplsl2port = ((OFOxmOfdpaMplsL2Port) oxm);
114 mplsL2Port = mplsl2port.getValue().getRaw();
115 /*
116 * 0x0000XXXX UNI Interface.
117 * 0x0002XXXX NNI Interface
118 */
119 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
120 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
121 return new Ofdpa3MatchMplsL2Port(mplsL2Port);
122 }
123 throw new UnsupportedOperationException(
124 "Unexpected OXM: " + oxm.toString());
125 }
Pier Ventre6f630052016-10-18 09:58:41 -0700126 }
127 throw new UnsupportedOperationException(
128 "Unexpected OXM: " + oxm.toString());
129 }
130
131 @Override
132 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
Charles Chand1172632017-03-15 17:33:09 -0700133 if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Pier Ventre6f630052016-10-18 09:58:41 -0700134 return new Ofdpa3MatchOvid();
Pier Ventre9cf536b2016-10-21 13:30:18 -0700135 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
136 return new Ofdpa3MatchMplsL2Port();
Pier Ventre6f630052016-10-18 09:58:41 -0700137 }
138 throw new UnsupportedOperationException(
139 "Driver does not support extension type " + type.toString());
140 }
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700141
142 @Override
143 public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) {
144 // TODO
145 log.warn("The encode method of Ofdpa3ExtensionSelectorInterpreter hasn't been implemented");
146 return null;
147 }
148
149 @Override
150 public ExtensionSelector decode(ObjectNode json, CodecContext context) {
151 // TODO
152 log.warn("The decode method of Ofdpa3ExtensionSelectorInterpreter hasn't been implemented");
153 return null;
154 }
Pier Ventre6f630052016-10-18 09:58:41 -0700155}