Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 21 | import org.onosproject.codec.CodecContext; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 23 | import org.onosproject.net.behaviour.ExtensionSelectorResolver; |
| 24 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 25 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
| 26 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
| 27 | import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes; |
| 28 | import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; |
| 29 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 30 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
| 31 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaActsetOutput; |
| 33 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 35 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.types.U16; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 37 | import org.projectfloodlight.openflow.types.U32; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.types.U8; |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 39 | import org.slf4j.Logger; |
| 40 | |
| 41 | import static org.slf4j.LoggerFactory.getLogger; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Interpreter for OFDPA3 OpenFlow selector extensions. |
| 45 | */ |
| 46 | public class Ofdpa3ExtensionSelectorInterpreter extends AbstractHandlerBehaviour |
| 47 | implements ExtensionSelectorInterpreter, ExtensionSelectorResolver { |
| 48 | |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 49 | private final Logger log = getLogger(getClass()); |
| 50 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 51 | @Override |
| 52 | public boolean supported(ExtensionSelectorType extensionSelectorType) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 53 | if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 54 | return true; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 55 | } else if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
| 56 | return true; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 57 | } 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 Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 63 | } |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { |
| 69 | ExtensionSelectorType type = extensionSelector.type(); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 70 | if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 71 | 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 Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 83 | } 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 Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 95 | } 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 Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 102 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 103 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 104 | throw new UnsupportedOperationException( |
| 105 | "Unexpected ExtensionSelector: " + extensionSelector.toString()); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public ExtensionSelector mapOxm(OFOxm<?> oxm) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 110 | if (oxm.getMatchField().equals(MatchField.OFDPA_OVID)) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 111 | 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 Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 122 | } 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 Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 144 | } 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 Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 151 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 152 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 153 | throw new UnsupportedOperationException( |
| 154 | "Unexpected OXM: " + oxm.toString()); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 159 | if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 160 | return new Ofdpa3MatchOvid(); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 161 | } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
| 162 | return new Ofdpa3MatchMplsL2Port(); |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 163 | } 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 Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 167 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 168 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 169 | throw new UnsupportedOperationException( |
| 170 | "Driver does not support extension type " + type.toString()); |
| 171 | } |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 172 | |
| 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 Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 186 | } |