Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -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 | */ |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 16 | package org.onosproject.driver.extensions; |
| 17 | |
| 18 | import org.onlab.packet.VlanId; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 19 | import org.onosproject.net.PortNumber; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 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; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaActsetOutput; |
| 30 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid; |
| 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVidMasked; |
| 33 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.types.U32; |
| 35 | import org.projectfloodlight.openflow.types.U8; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.types.VlanVid; |
| 37 | |
| 38 | /** |
| 39 | * Interpreter for OFDPA OpenFlow selector extensions. |
| 40 | */ |
| 41 | public 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 Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 48 | } 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 Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 54 | } |
| 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 Chan | be8aea4 | 2016-02-24 12:04:47 -0800 | [diff] [blame] | 64 | if (vlanId.equals(VlanId.NONE)) { |
| 65 | OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 66 | 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 Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 71 | } else { |
| 72 | return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort()))); |
| 73 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 74 | } 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 Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 84 | } |
| 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 Chan | be8aea4 | 2016-02-24 12:04:47 -0800 | [diff] [blame] | 99 | vlanId = VlanId.NONE; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 100 | } 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 Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 116 | } 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 Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 123 | } |
| 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 Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 132 | } 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 Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 136 | } |
| 137 | throw new UnsupportedOperationException( |
| 138 | "Driver does not support extension type " + type.toString()); |
| 139 | } |
| 140 | } |