blob: a7f70f9835d7212e5f6b0c44e92abacfa15f13c8 [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 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053049 if (extensionTreatmentType.equals(
50 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
51 return true;
52 }
Jonathan Hart3c259162015-10-21 21:31:19 -070053 return false;
54 }
55
56 @Override
alshabib880b6442015-11-23 22:13:04 -080057 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
58 ExtensionTreatmentType type = extensionTreatment.type();
59 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
60 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -070061 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
62 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
63 }
alshabib880b6442015-11-23 22:13:04 -080064 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080065 // TODO this will be implemented later
66 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053067 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
68 // TODO this will be implemented later
69 }
Jonathan Hart3c259162015-10-21 21:31:19 -070070 return null;
71 }
72
73 @Override
alshabib880b6442015-11-23 22:13:04 -080074 public ExtensionTreatment mapAction(OFAction action) {
Jonathan Hart3c259162015-10-21 21:31:19 -070075 if (action.getType().equals(OFActionType.SET_FIELD)) {
76 OFActionSetField setFieldAction = (OFActionSetField) action;
77 OFOxm<?> oxm = setFieldAction.getField();
78 switch (oxm.getMatchField().id) {
79 case TUNNEL_IPV4_DST:
80 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
81 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
82 default:
83 throw new UnsupportedOperationException(
84 "Driver does not support extension type " + oxm.getMatchField().id);
85 }
86 }
87 return null;
88 }
89
90 @Override
alshabib880b6442015-11-23 22:13:04 -080091 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
92 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070093 return new NiciraSetTunnelDst();
94 }
alshabib880b6442015-11-23 22:13:04 -080095 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080096 return new NiciraResubmit();
97 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053098 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
99 return new NiciraSetNshSpi();
100 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700101 throw new UnsupportedOperationException(
102 "Driver does not support extension type " + type.toString());
103 }
104}