yjimmyy | cfcb053 | 2016-07-11 16:03:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
yjimmyy | cfcb053 | 2016-07-11 16:03:48 -0700 | [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.onosproject.net.driver.AbstractHandlerBehaviour; |
| 20 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 21 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 22 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
| 23 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 24 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 25 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 26 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 27 | import org.projectfloodlight.openflow.protocol.action.OFActionOplinkAtt; |
| 28 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 29 | import org.projectfloodlight.openflow.types.U32; |
| 30 | |
| 31 | /** |
| 32 | * Interpreter for Oplink OpenFlow treatment extensions. |
| 33 | */ |
| 34 | public class OplinkExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 35 | implements ExtensionTreatmentInterpreter { |
| 36 | |
| 37 | private static final long ATTENUATION_EXP = 0xff000088L; |
| 38 | |
| 39 | @Override |
| 40 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 41 | if (extensionTreatmentType.equals( |
| 42 | ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type())) { |
| 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 50 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 51 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type())) { |
| 52 | int att = ((OplinkAttenuation) extensionTreatment).getAttenuation(); |
| 53 | return factory.actions().oplinkAtt(factory.oxms().ochSigatt(U32.ofRaw(att))); |
| 54 | } |
| 55 | return null; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
| 60 | if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 61 | OFActionExperimenter actionExp = (OFActionExperimenter) action; |
| 62 | if (actionExp.getExperimenter() == ATTENUATION_EXP) { |
| 63 | OFActionOplinkAtt actionAtt = (OFActionOplinkAtt) action; |
| 64 | return new OplinkAttenuation(((OFOxm<U32>) actionAtt.getField()).getValue().getRaw()); |
| 65 | } |
| 66 | } |
| 67 | return null; |
| 68 | } |
| 69 | } |