blob: b8f1fd910d5b88330b33641e5aa4c726b5b3d381 [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;
20import org.onosproject.net.behaviour.ExtensionResolver;
21import org.onosproject.net.driver.AbstractHandlerBehaviour;
22import org.onosproject.net.flow.instructions.ExtensionInstruction;
23import org.onosproject.net.flow.instructions.ExtensionType;
24import org.onosproject.openflow.controller.ExtensionInterpreter;
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.OFOxmTunnelIpv4Dst;
31import org.projectfloodlight.openflow.types.IPv4Address;
32
33/**
34 * Interpreter for Nicira OpenFlow extensions.
35 */
36public class NiciraExtensionInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionInterpreter, ExtensionResolver {
38
39 @Override
40 public boolean supported(ExtensionType extensionType) {
Satish K854eac12015-11-21 12:23:49 +053041 if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070042 return true;
43 }
Satish K854eac12015-11-21 12:23:49 +053044 if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080045 return true;
46 }
Jonathan Hart3c259162015-10-21 21:31:19 -070047 return false;
48 }
49
50 @Override
51 public OFAction mapInstruction(OFFactory factory, ExtensionInstruction extensionInstruction) {
52 ExtensionType type = extensionInstruction.type();
53 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) {
54 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionInstruction;
55 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
56 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
57 }
BitOhenryb53ac6c2015-11-16 20:58:58 +080058 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) {
59 // TODO this will be implemented later
60 }
Jonathan Hart3c259162015-10-21 21:31:19 -070061 return null;
62 }
63
64 @Override
65 public ExtensionInstruction mapAction(OFAction action) {
66 if (action.getType().equals(OFActionType.SET_FIELD)) {
67 OFActionSetField setFieldAction = (OFActionSetField) action;
68 OFOxm<?> oxm = setFieldAction.getField();
69 switch (oxm.getMatchField().id) {
70 case TUNNEL_IPV4_DST:
71 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
72 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
73 default:
74 throw new UnsupportedOperationException(
75 "Driver does not support extension type " + oxm.getMatchField().id);
76 }
77 }
78 return null;
79 }
80
81 @Override
82 public ExtensionInstruction getExtensionInstruction(ExtensionType type) {
83 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) {
84 return new NiciraSetTunnelDst();
85 }
BitOhenryb53ac6c2015-11-16 20:58:58 +080086 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) {
87 return new NiciraResubmit();
88 }
Jonathan Hart3c259162015-10-21 21:31:19 -070089 throw new UnsupportedOperationException(
90 "Driver does not support extension type " + type.toString());
91 }
92}