blob: 1d64c3192823d8a567b31fcaf7eccbb0c5f494af [file] [log] [blame]
Charles Chan14967c22015-12-07 11:11:50 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Charles Chan14967c22015-12-07 11:11:50 -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 */
Charles Chan14967c22015-12-07 11:11:50 -080016package org.onosproject.driver.extensions;
17
18import org.onlab.packet.VlanId;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070019import org.onosproject.net.PortNumber;
Charles Chan14967c22015-12-07 11:11:50 -080020import 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;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070029import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaActsetOutput;
30import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation;
Charles Chan14967c22015-12-07 11:11:50 -080031import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
32import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVidMasked;
33import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070034import org.projectfloodlight.openflow.types.U32;
35import org.projectfloodlight.openflow.types.U8;
Charles Chan14967c22015-12-07 11:11:50 -080036import org.projectfloodlight.openflow.types.VlanVid;
37
38/**
39 * Interpreter for OFDPA OpenFlow selector extensions.
40 */
41public class OfdpaExtensionSelectorInterpreter extends AbstractHandlerBehaviour
42 implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
43
44 @Override
45 public boolean supported(ExtensionSelectorType extensionSelectorType) {
46 if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
47 return true;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070048 } else if (extensionSelectorType.equals(
49 ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
50 return true;
51 } else if (extensionSelectorType.equals(
52 ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
53 return true;
Charles Chan14967c22015-12-07 11:11:50 -080054 }
55 return false;
56 }
57
58 @Override
59 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
60 ExtensionSelectorType type = extensionSelector.type();
61 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
62 VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId();
63 // Special VLAN 0x0000/0x1FFF required by OFDPA
Charles Chanbe8aea42016-02-24 12:04:47 -080064 if (vlanId.equals(VlanId.NONE)) {
65 OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000);
Charles Chan14967c22015-12-07 11:11:50 -080066 OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF);
67 return factory.oxms().vlanVidMasked(vid, mask);
68 // Normal case
69 } else if (vlanId.equals(VlanId.ANY)) {
70 return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
Charles Chan14967c22015-12-07 11:11:50 -080071 } else {
72 return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort())));
73 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070074 } else if (type.equals(
75 ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
76 PortNumber port = ((OfdpaMatchActsetOutput) extensionSelector).port();
77 return factory.oxms().ofdpaActsetOutput(U32.of(port.toLong()));
78 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
79
80 Short allowVlanTranslation =
81 ((OfdpaMatchAllowVlanTranslation) extensionSelector).allowVlanTranslation();
82
83 return factory.oxms().ofdpaAllowVlanTranslation(U8.of(allowVlanTranslation));
Charles Chan14967c22015-12-07 11:11:50 -080084 }
85 throw new UnsupportedOperationException(
86 "Unexpected ExtensionSelector: " + extensionSelector.toString());
87 }
88
89 @Override
90 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
91 VlanId vlanId;
92
93 if (oxm.getMatchField().equals(MatchField.VLAN_VID)) {
94 if (oxm.isMasked()) {
95 OFVlanVidMatch vid = ((OFOxmVlanVidMasked) oxm).getValue();
96 OFVlanVidMatch mask = ((OFOxmVlanVidMasked) oxm).getMask();
97
98 if (vid.equals(OFVlanVidMatch.ofRawVid((short) 0))) {
Charles Chanbe8aea42016-02-24 12:04:47 -080099 vlanId = VlanId.NONE;
Charles Chan14967c22015-12-07 11:11:50 -0800100 } else if (vid.equals(OFVlanVidMatch.PRESENT) &&
101 mask.equals(OFVlanVidMatch.PRESENT)) {
102 vlanId = VlanId.ANY;
103 } else {
104 vlanId = VlanId.vlanId(vid.getVlan());
105 }
106 } else {
107 OFVlanVidMatch vid = ((OFOxmVlanVid) oxm).getValue();
108
109 if (!vid.isPresentBitSet()) {
110 vlanId = VlanId.NONE;
111 } else {
112 vlanId = VlanId.vlanId(vid.getVlan());
113 }
114 }
115 return new OfdpaMatchVlanVid(vlanId);
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700116 } else if (oxm.getMatchField().equals(MatchField.OFDPA_ACTSET_OUTPUT)) {
117 U32 portNumberU32 = ((OFOxmOfdpaActsetOutput) oxm).getValue();
118 PortNumber portNumber = PortNumber.portNumber(portNumberU32.getValue());
119 return new OfdpaMatchActsetOutput(portNumber);
120 } else if (oxm.getMatchField().equals(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION)) {
121 U8 value = ((OFOxmOfdpaAllowVlanTranslation) oxm).getValue();
122 return new OfdpaMatchAllowVlanTranslation(value.getValue());
Charles Chan14967c22015-12-07 11:11:50 -0800123 }
124 throw new UnsupportedOperationException(
125 "Unexpected OXM: " + oxm.toString());
126 }
127
128 @Override
129 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
130 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
131 return new OfdpaMatchVlanVid();
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700132 } else if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
133 return new OfdpaMatchActsetOutput();
134 } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
135 return new OfdpaMatchAllowVlanTranslation();
Charles Chan14967c22015-12-07 11:11:50 -0800136 }
137 throw new UnsupportedOperationException(
138 "Driver does not support extension type " + type.toString());
139 }
140}