blob: aca0c97b574e87b5092a5f9109f82bf1eab98cbd [file] [log] [blame]
Charles Chan14967c22015-12-07 11:11:50 -08001/*
2 * Copyright 2016 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.VlanId;
20import org.onosproject.net.behaviour.ExtensionSelectorResolver;
21import org.onosproject.net.driver.AbstractHandlerBehaviour;
22import org.onosproject.net.flow.criteria.ExtensionSelector;
23import org.onosproject.net.flow.criteria.ExtensionSelectorType;
24import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
25import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
26import org.projectfloodlight.openflow.protocol.OFFactory;
27import org.projectfloodlight.openflow.protocol.match.MatchField;
28import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
29import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
30import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVidMasked;
31import org.projectfloodlight.openflow.types.OFVlanVidMatch;
32import org.projectfloodlight.openflow.types.VlanVid;
33
34/**
35 * Interpreter for OFDPA OpenFlow selector extensions.
36 */
37public class OfdpaExtensionSelectorInterpreter extends AbstractHandlerBehaviour
38 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
39
40 @Override
41 public boolean supported(ExtensionSelectorType extensionSelectorType) {
42 if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
43 return true;
44 }
45 return false;
46 }
47
48 @Override
49 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
50 ExtensionSelectorType type = extensionSelector.type();
51 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
52 VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId();
53 // Special VLAN 0x0000/0x1FFF required by OFDPA
Charles Chanbe8aea42016-02-24 12:04:47 -080054 if (vlanId.equals(VlanId.NONE)) {
55 OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000);
Charles Chan14967c22015-12-07 11:11:50 -080056 OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF);
57 return factory.oxms().vlanVidMasked(vid, mask);
58 // Normal case
59 } else if (vlanId.equals(VlanId.ANY)) {
60 return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
Charles Chan14967c22015-12-07 11:11:50 -080061 } else {
62 return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort())));
63 }
64 }
65 throw new UnsupportedOperationException(
66 "Unexpected ExtensionSelector: " + extensionSelector.toString());
67 }
68
69 @Override
70 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
71 VlanId vlanId;
72
73 if (oxm.getMatchField().equals(MatchField.VLAN_VID)) {
74 if (oxm.isMasked()) {
75 OFVlanVidMatch vid = ((OFOxmVlanVidMasked) oxm).getValue();
76 OFVlanVidMatch mask = ((OFOxmVlanVidMasked) oxm).getMask();
77
78 if (vid.equals(OFVlanVidMatch.ofRawVid((short) 0))) {
Charles Chanbe8aea42016-02-24 12:04:47 -080079 vlanId = VlanId.NONE;
Charles Chan14967c22015-12-07 11:11:50 -080080 } else if (vid.equals(OFVlanVidMatch.PRESENT) &&
81 mask.equals(OFVlanVidMatch.PRESENT)) {
82 vlanId = VlanId.ANY;
83 } else {
84 vlanId = VlanId.vlanId(vid.getVlan());
85 }
86 } else {
87 OFVlanVidMatch vid = ((OFOxmVlanVid) oxm).getValue();
88
89 if (!vid.isPresentBitSet()) {
90 vlanId = VlanId.NONE;
91 } else {
92 vlanId = VlanId.vlanId(vid.getVlan());
93 }
94 }
95 return new OfdpaMatchVlanVid(vlanId);
96 }
97 throw new UnsupportedOperationException(
98 "Unexpected OXM: " + oxm.toString());
99 }
100
101 @Override
102 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
103 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
104 return new OfdpaMatchVlanVid();
105 }
106 throw new UnsupportedOperationException(
107 "Driver does not support extension type " + type.toString());
108 }
109}