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 | */ |
| 16 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
| 19 | import org.onlab.packet.VlanId; |
| 20 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 21 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 22 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 24 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
| 25 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 26 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 27 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 28 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 29 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 30 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid; |
| 31 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
| 32 | |
| 33 | /** |
| 34 | * Interpreter for OFDPA OpenFlow treatment extensions. |
| 35 | */ |
Charles Chan | a5bb4a1 | 2016-12-09 13:50:45 -0800 | [diff] [blame] | 36 | public class OfdpaExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 37 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
| 38 | @Override |
| 39 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 40 | if (extensionTreatmentType.equals( |
| 41 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { |
| 42 | return true; |
| 43 | } |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 49 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 50 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { |
| 51 | VlanId vlanId = ((OfdpaSetVlanVid) extensionTreatment).vlanId(); |
| 52 | // NOTE: OFDPA requires isPresent bit set to zero. |
| 53 | OFVlanVidMatch match = OFVlanVidMatch.ofRawVid(vlanId.toShort()); |
| 54 | return factory.actions().setField(factory.oxms().vlanVid(match)); |
| 55 | } |
| 56 | throw new UnsupportedOperationException( |
| 57 | "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); |
| 58 | } |
| 59 | |
| 60 | @Override |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 61 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 62 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 63 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 64 | OFOxm<?> oxm = setFieldAction.getField(); |
| 65 | switch (oxm.getMatchField().id) { |
| 66 | case VLAN_VID: |
| 67 | OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm; |
| 68 | return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid())); |
| 69 | default: |
| 70 | throw new UnsupportedOperationException( |
| 71 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 72 | } |
| 73 | } |
| 74 | throw new UnsupportedOperationException( |
| 75 | "Unexpected OFAction: " + action.toString()); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 80 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { |
| 81 | return new OfdpaSetVlanVid(); |
| 82 | } |
| 83 | throw new UnsupportedOperationException( |
| 84 | "Driver does not support extension type " + type.toString()); |
| 85 | } |
| 86 | } |