blob: 7b070c568d33a1a65061a73168ab104df724ee5d [file] [log] [blame]
Charles Chan14967c22015-12-07 11:11:50 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Charles Chan14967c22015-12-07 11:11:50 -08003 *
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.onlab.packet.VlanId;
20import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
21import org.onosproject.net.driver.AbstractHandlerBehaviour;
22import org.onosproject.net.flow.instructions.ExtensionTreatment;
23import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
25import org.projectfloodlight.openflow.protocol.OFActionType;
26import org.projectfloodlight.openflow.protocol.OFFactory;
27import org.projectfloodlight.openflow.protocol.action.OFAction;
28import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
29import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
30import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid;
31import org.projectfloodlight.openflow.types.OFVlanVidMatch;
32
33/**
34 * Interpreter for OFDPA OpenFlow treatment extensions.
35 */
Charles Chana5bb4a12016-12-09 13:50:45 -080036public class OfdpaExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
Charles Chan14967c22015-12-07 11:11:50 -080037 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 Liffef5002016-04-04 23:27:37 -070061 public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
Charles Chan14967c22015-12-07 11:11:50 -080062 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}