Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [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 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.codec.CodecContext; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 21 | import org.onosproject.net.NshServiceIndex; |
| 22 | import org.onosproject.net.NshServicePathId; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [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.openflow.controller.ExtensionSelectorInterpreter; |
| 28 | import org.projectfloodlight.openflow.protocol.OFFactory; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackMark; |
| 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackStateMasked; |
| 33 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmConntrackZone; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType; |
| 35 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi; |
| 36 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp; |
| 37 | import org.projectfloodlight.openflow.types.U16; |
| 38 | import org.projectfloodlight.openflow.types.U32; |
| 39 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Interpreter for Nicira OpenFlow selector extensions. |
| 43 | */ |
| 44 | public class NiciraExtensionSelectorInterpreter |
| 45 | extends AbstractHandlerBehaviour |
| 46 | implements ExtensionSelectorInterpreter, ExtensionSelectorResolver { |
| 47 | |
| 48 | @Override |
| 49 | public boolean supported(ExtensionSelectorType extensionSelectorType) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 50 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
| 51 | return true; |
| 52 | } |
| 53 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
| 54 | return true; |
| 55 | } |
| 56 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { |
| 57 | return true; |
| 58 | } |
| 59 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) { |
| 60 | return true; |
| 61 | } |
| 62 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) { |
| 63 | return true; |
| 64 | } |
| 65 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 66 | return true; |
| 67 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 68 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE |
| 69 | .type())) { |
| 70 | return true; |
| 71 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 72 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE |
| 73 | .type())) { |
| 74 | return true; |
| 75 | } |
| 76 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE |
| 77 | .type())) { |
| 78 | return true; |
| 79 | } |
| 80 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK |
| 81 | .type())) { |
| 82 | return true; |
| 83 | } |
| 84 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_LABEL |
| 85 | .type())) { |
| 86 | return true; |
| 87 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 88 | return false; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 93 | ExtensionSelectorType type = extensionSelector.type(); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 94 | |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 95 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 96 | NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector; |
| 97 | return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId())); |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 98 | } |
| 99 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 100 | NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector; |
| 101 | return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex())); |
| 102 | } |
| 103 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) { |
| 104 | NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector; |
| 105 | return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType())); |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 106 | } |
| 107 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { |
| 108 | // TODO |
| 109 | } |
| 110 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) { |
| 111 | // TODO |
| 112 | } |
| 113 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) { |
| 114 | // TODO |
| 115 | } |
| 116 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 117 | // TODO |
| 118 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 119 | |
| 120 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) { |
| 121 | NiciraMatchCtState niciraMatchCtState = (NiciraMatchCtState) extensionSelector; |
| 122 | return factory.oxms().conntrackStateMasked(U32.of(niciraMatchCtState.ctState()), |
| 123 | U32.of(niciraMatchCtState.ctStateMask())); |
| 124 | } |
| 125 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) { |
| 126 | NiciraMatchCtZone niciraMatchCtZone = (NiciraMatchCtZone) extensionSelector; |
| 127 | return factory.oxms().conntrackZone(U16.of(niciraMatchCtZone.ctZone())); |
| 128 | } |
| 129 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) { |
| 130 | NiciraMatchCtMark niciraMatchCtMark = (NiciraMatchCtMark) extensionSelector; |
| 131 | return factory.oxms().conntrackMark(U32.of(niciraMatchCtMark.ctMark())); |
| 132 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 133 | return null; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public ExtensionSelector mapOxm(OFOxm<?> oxm) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 138 | |
| 139 | if (oxm.getMatchField() == MatchField.NSP) { |
| 140 | OFOxmNsp oxmField = (OFOxmNsp) oxm; |
| 141 | return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw())); |
| 142 | } |
| 143 | if (oxm.getMatchField() == MatchField.NSI) { |
| 144 | OFOxmNsi oxmField = (OFOxmNsi) oxm; |
| 145 | return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw())); |
| 146 | } |
| 147 | if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) { |
| 148 | OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm; |
| 149 | return new NiciraMatchEncapEthType(oxmField.getValue().getRaw()); |
| 150 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 151 | if (oxm.getMatchField() == MatchField.CONNTRACK_STATE) { |
| 152 | OFOxmConntrackStateMasked oxmField = (OFOxmConntrackStateMasked) oxm; |
| 153 | return new NiciraMatchCtState(oxmField.getValue().getRaw(), oxmField.getMask().getRaw()); |
| 154 | } |
| 155 | if (oxm.getMatchField() == MatchField.CONNTRACK_ZONE) { |
| 156 | OFOxmConntrackZone oxmField = (OFOxmConntrackZone) oxm; |
| 157 | return new NiciraMatchCtZone(oxmField.getValue().getRaw()); |
| 158 | } |
| 159 | if (oxm.getMatchField() == MatchField.CONNTRACK_MARK) { |
| 160 | OFOxmConntrackMark oxmField = (OFOxmConntrackMark) oxm; |
| 161 | return new NiciraMatchCtMark(oxmField.getValue().getRaw()); |
| 162 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 163 | return null; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 168 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
| 169 | return new NiciraMatchNshSpi(); |
| 170 | } |
| 171 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
| 172 | return new NiciraMatchNshSi(); |
| 173 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 174 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) { |
| 175 | return new NiciraMatchEncapEthType(); |
| 176 | } |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 177 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type()) |
| 178 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type()) |
| 179 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type()) |
| 180 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 181 | return new NiciraMatchNshContextHeader(type); |
| 182 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 183 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) { |
| 184 | return new NiciraMatchCtState(); |
| 185 | } |
| 186 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) { |
| 187 | return new NiciraMatchCtZone(); |
| 188 | } |
| 189 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) { |
| 190 | return new NiciraMatchCtMark(); |
| 191 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 192 | return null; |
| 193 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 194 | |
| 195 | @Override |
| 196 | public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) { |
| 197 | // TODO |
| 198 | return null; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public ExtensionSelector decode(ObjectNode json, CodecContext context) { |
| 203 | // TODO |
| 204 | return null; |
| 205 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 206 | } |