Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 20 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 23 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
| 24 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 25 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 26 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 27 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 28 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 29 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsType; |
| 30 | import org.projectfloodlight.openflow.types.U16; |
| 31 | |
| 32 | /** |
| 33 | * Interpreter for OFDPA3 OpenFlow treatment extensions. |
| 34 | */ |
| 35 | public class Ofdpa3ExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 36 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
| 37 | @Override |
| 38 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 39 | if (extensionTreatmentType.equals( |
| 40 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 41 | return true; |
| 42 | } |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 48 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 49 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 50 | short mplsType = ((Ofdpa3SetMplsType) extensionTreatment).mplsType(); |
| 51 | return factory.actions().setField(factory.oxms().ofdpaMplsType( |
| 52 | U16.ofRaw(mplsType))); |
| 53 | } |
| 54 | throw new UnsupportedOperationException( |
| 55 | "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
| 60 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 61 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 62 | OFOxm<?> oxm = setFieldAction.getField(); |
| 63 | switch (oxm.getMatchField().id) { |
| 64 | case OFDPA_MPLS_TYPE: |
| 65 | OFOxmOfdpaMplsType mplsType = (OFOxmOfdpaMplsType) oxm; |
| 66 | return new Ofdpa3SetMplsType(mplsType.getValue().getRaw()); |
| 67 | default: |
| 68 | throw new UnsupportedOperationException( |
| 69 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 70 | } |
| 71 | } |
| 72 | throw new UnsupportedOperationException( |
| 73 | "Unexpected OFAction: " + action.toString()); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 78 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 79 | return new Ofdpa3SetMplsType(); |
| 80 | } |
| 81 | throw new UnsupportedOperationException( |
| 82 | "Driver does not support extension type " + type.toString()); |
| 83 | } |
| 84 | } |