blob: 35f4c1ba709bd86848a12b695c3196b5cb14b9c2 [file] [log] [blame]
yjimmyycfcb0532016-07-11 16:03:48 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
yjimmyycfcb0532016-07-11 16:03:48 -07003 *
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
17package org.onosproject.driver.extensions;
18
19import org.onosproject.net.driver.AbstractHandlerBehaviour;
20import org.onosproject.net.flow.instructions.ExtensionTreatment;
21import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
22import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
23import org.projectfloodlight.openflow.protocol.OFActionType;
24import org.projectfloodlight.openflow.protocol.OFFactory;
25import org.projectfloodlight.openflow.protocol.action.OFAction;
26import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
27import org.projectfloodlight.openflow.protocol.action.OFActionOplinkAtt;
28import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
29import org.projectfloodlight.openflow.types.U32;
30
31/**
32 * Interpreter for Oplink OpenFlow treatment extensions.
33 */
34public 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}