Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType; |
| 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi; |
| 33 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp; |
| 34 | import org.projectfloodlight.openflow.types.U16; |
| 35 | import org.projectfloodlight.openflow.types.U32; |
| 36 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Interpreter for Nicira OpenFlow selector extensions. |
| 40 | */ |
| 41 | public class NiciraExtensionSelectorInterpreter |
| 42 | extends AbstractHandlerBehaviour |
| 43 | implements ExtensionSelectorInterpreter, ExtensionSelectorResolver { |
| 44 | |
| 45 | @Override |
| 46 | public boolean supported(ExtensionSelectorType extensionSelectorType) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 47 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
| 48 | return true; |
| 49 | } |
| 50 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
| 51 | return true; |
| 52 | } |
| 53 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { |
| 54 | return true; |
| 55 | } |
| 56 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) { |
| 57 | return true; |
| 58 | } |
| 59 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) { |
| 60 | return true; |
| 61 | } |
| 62 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 63 | return true; |
| 64 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 65 | if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE |
| 66 | .type())) { |
| 67 | return true; |
| 68 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 69 | return false; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 74 | ExtensionSelectorType type = extensionSelector.type(); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 75 | |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 76 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 77 | NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector; |
| 78 | return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId())); |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 79 | } |
| 80 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 81 | NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector; |
| 82 | return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex())); |
| 83 | } |
| 84 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) { |
| 85 | NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector; |
| 86 | return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType())); |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 87 | } |
| 88 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { |
| 89 | // TODO |
| 90 | } |
| 91 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) { |
| 92 | // TODO |
| 93 | } |
| 94 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) { |
| 95 | // TODO |
| 96 | } |
| 97 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 98 | // TODO |
| 99 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 100 | return null; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public ExtensionSelector mapOxm(OFOxm<?> oxm) { |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 105 | |
| 106 | if (oxm.getMatchField() == MatchField.NSP) { |
| 107 | OFOxmNsp oxmField = (OFOxmNsp) oxm; |
| 108 | return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw())); |
| 109 | } |
| 110 | if (oxm.getMatchField() == MatchField.NSI) { |
| 111 | OFOxmNsi oxmField = (OFOxmNsi) oxm; |
| 112 | return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw())); |
| 113 | } |
| 114 | if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) { |
| 115 | OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm; |
| 116 | return new NiciraMatchEncapEthType(oxmField.getValue().getRaw()); |
| 117 | } |
| 118 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 119 | return null; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 124 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { |
| 125 | return new NiciraMatchNshSpi(); |
| 126 | } |
| 127 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { |
| 128 | return new NiciraMatchNshSi(); |
| 129 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 130 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) { |
| 131 | return new NiciraMatchEncapEthType(); |
| 132 | } |
Phaneendra Manda | efb3875 | 2015-12-04 00:43:38 +0530 | [diff] [blame] | 133 | if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type()) |
| 134 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type()) |
| 135 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type()) |
| 136 | || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { |
| 137 | return new NiciraMatchNshContextHeader(type); |
| 138 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 139 | return null; |
| 140 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 141 | |
| 142 | @Override |
| 143 | public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) { |
| 144 | // TODO |
| 145 | return null; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public ExtensionSelector decode(ObjectNode json, CodecContext context) { |
| 150 | // TODO |
| 151 | return null; |
| 152 | } |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 153 | } |