Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -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 | |
| 19 | import org.onlab.packet.VlanId; |
| 20 | import org.onosproject.net.behaviour.ExtensionSelectorResolver; |
| 21 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 22 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
| 23 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
| 24 | import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes; |
| 25 | import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; |
| 26 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 27 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
| 28 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.types.U16; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.types.U32; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Interpreter for OFDPA3 OpenFlow selector extensions. |
| 36 | */ |
| 37 | public class Ofdpa3ExtensionSelectorInterpreter extends AbstractHandlerBehaviour |
| 38 | implements ExtensionSelectorInterpreter, ExtensionSelectorResolver { |
| 39 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 40 | @Override |
| 41 | public boolean supported(ExtensionSelectorType extensionSelectorType) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 42 | if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 43 | return true; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 44 | } else if (extensionSelectorType.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
| 45 | return true; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { |
| 52 | ExtensionSelectorType type = extensionSelector.type(); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 53 | if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 54 | VlanId vlanId = ((Ofdpa3MatchOvid) extensionSelector).vlanId(); |
| 55 | if (vlanId.equals(VlanId.NONE)) { |
| 56 | throw new UnsupportedOperationException( |
| 57 | "Unexpected ExtensionSelector: " + extensionSelector.toString()); |
| 58 | } else if (vlanId.equals(VlanId.ANY)) { |
| 59 | throw new UnsupportedOperationException( |
| 60 | "Unexpected ExtensionSelector: " + extensionSelector.toString()); |
| 61 | } else { |
| 62 | short mask = (short) 0x1000; |
| 63 | short oVid = (short) (mask | vlanId.toShort()); |
| 64 | return factory.oxms().ofdpaOvid(U16.ofRaw(oVid)); |
| 65 | } |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 66 | } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
| 67 | int mplsL2Port = ((Ofdpa3MatchMplsL2Port) extensionSelector).mplsL2Port(); |
| 68 | /* |
| 69 | * 0x0000XXXX UNI Interface. |
| 70 | * 0x0002XXXX NNI Interface |
| 71 | */ |
| 72 | if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) || |
| 73 | (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) { |
| 74 | return factory.oxms().ofdpaMplsL2Port(U32.ofRaw(mplsL2Port)); |
| 75 | } |
| 76 | throw new UnsupportedOperationException( |
| 77 | "Unexpected ExtensionSelector: " + extensionSelector.toString()); |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 78 | } |
| 79 | throw new UnsupportedOperationException( |
| 80 | "Unexpected ExtensionSelector: " + extensionSelector.toString()); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public ExtensionSelector mapOxm(OFOxm<?> oxm) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 85 | if (oxm.getMatchField().equals(MatchField.OFDPA_OVID)) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 86 | VlanId vlanId; |
| 87 | if (oxm.isMasked()) { |
| 88 | throw new UnsupportedOperationException( |
| 89 | "Unexpected OXM: " + oxm.toString()); |
| 90 | } else { |
| 91 | OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm); |
| 92 | short mask = (short) 0x0FFF; |
| 93 | short oVid = (short) (mask & ovid.getValue().getRaw()); |
| 94 | vlanId = VlanId.vlanId(oVid); |
| 95 | } |
| 96 | return new Ofdpa3MatchOvid(vlanId); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 97 | } else if (oxm.getMatchField().equals(MatchField.OFDPA_MPLS_L2_PORT)) { |
| 98 | Integer mplsL2Port; |
| 99 | /* |
| 100 | * Supported but not used for now. |
| 101 | */ |
| 102 | if (oxm.isMasked()) { |
| 103 | throw new UnsupportedOperationException( |
| 104 | "Unexpected OXM: " + oxm.toString()); |
| 105 | } else { |
| 106 | OFOxmOfdpaMplsL2Port mplsl2port = ((OFOxmOfdpaMplsL2Port) oxm); |
| 107 | mplsL2Port = mplsl2port.getValue().getRaw(); |
| 108 | /* |
| 109 | * 0x0000XXXX UNI Interface. |
| 110 | * 0x0002XXXX NNI Interface |
| 111 | */ |
| 112 | if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) || |
| 113 | (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) { |
| 114 | return new Ofdpa3MatchMplsL2Port(mplsL2Port); |
| 115 | } |
| 116 | throw new UnsupportedOperationException( |
| 117 | "Unexpected OXM: " + oxm.toString()); |
| 118 | } |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 119 | } |
| 120 | throw new UnsupportedOperationException( |
| 121 | "Unexpected OXM: " + oxm.toString()); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 126 | if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 127 | return new Ofdpa3MatchOvid(); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 128 | } else if (type.equals(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
| 129 | return new Ofdpa3MatchMplsL2Port(); |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 130 | } |
| 131 | throw new UnsupportedOperationException( |
| 132 | "Driver does not support extension type " + type.toString()); |
| 133 | } |
| 134 | } |