blob: 544888d2f812ee114e6d852f483ef78a7096dcdb [file] [log] [blame]
Jonathan Hart3c259162015-10-21 21:31:19 -07001/*
2 * Copyright 2015 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
17package org.onosproject.driver.extensions;
18
19import org.onlab.packet.Ip4Address;
alshabib880b6442015-11-23 22:13:04 -080020import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
Jonathan Hart3c259162015-10-21 21:31:19 -070021import org.onosproject.net.driver.AbstractHandlerBehaviour;
alshabib880b6442015-11-23 22:13:04 -080022import org.onosproject.net.flow.instructions.ExtensionTreatment;
23import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Jonathan Hart3c259162015-10-21 21:31:19 -070025import 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.OFOxmTunnelIpv4Dst;
31import org.projectfloodlight.openflow.types.IPv4Address;
32
33/**
34 * Interpreter for Nicira OpenFlow extensions.
35 */
alshabib880b6442015-11-23 22:13:04 -080036public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
Jonathan Hart3c259162015-10-21 21:31:19 -070038
39 @Override
alshabib880b6442015-11-23 22:13:04 -080040 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
41 if (extensionTreatmentType.equals(
42 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070043 return true;
44 }
alshabib880b6442015-11-23 22:13:04 -080045 if (extensionTreatmentType.equals(
46 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080047 return true;
48 }
Jonathan Hart3c259162015-10-21 21:31:19 -070049 return false;
50 }
51
52 @Override
alshabib880b6442015-11-23 22:13:04 -080053 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
54 ExtensionTreatmentType type = extensionTreatment.type();
55 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
56 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -070057 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
58 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
59 }
alshabib880b6442015-11-23 22:13:04 -080060 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080061 // TODO this will be implemented later
62 }
Jonathan Hart3c259162015-10-21 21:31:19 -070063 return null;
64 }
65
66 @Override
alshabib880b6442015-11-23 22:13:04 -080067 public ExtensionTreatment mapAction(OFAction action) {
Jonathan Hart3c259162015-10-21 21:31:19 -070068 if (action.getType().equals(OFActionType.SET_FIELD)) {
69 OFActionSetField setFieldAction = (OFActionSetField) action;
70 OFOxm<?> oxm = setFieldAction.getField();
71 switch (oxm.getMatchField().id) {
72 case TUNNEL_IPV4_DST:
73 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
74 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
75 default:
76 throw new UnsupportedOperationException(
77 "Driver does not support extension type " + oxm.getMatchField().id);
78 }
79 }
80 return null;
81 }
82
83 @Override
alshabib880b6442015-11-23 22:13:04 -080084 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
85 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070086 return new NiciraSetTunnelDst();
87 }
alshabib880b6442015-11-23 22:13:04 -080088 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080089 return new NiciraResubmit();
90 }
Jonathan Hart3c259162015-10-21 21:31:19 -070091 throw new UnsupportedOperationException(
92 "Driver does not support extension type " + type.toString());
93 }
94}