2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.driver.extensions;
19 import org.onlab.packet.Ip4Address;
20 import org.onosproject.net.behaviour.ExtensionResolver;
21 import org.onosproject.net.driver.AbstractHandlerBehaviour;
22 import org.onosproject.net.flow.instructions.ExtensionInstruction;
23 import org.onosproject.net.flow.instructions.ExtensionType;
24 import org.onosproject.openflow.controller.ExtensionInterpreter;
25 import org.projectfloodlight.openflow.protocol.OFActionType;
26 import org.projectfloodlight.openflow.protocol.OFFactory;
27 import org.projectfloodlight.openflow.protocol.action.OFAction;
28 import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
29 import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
30 import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
31 import org.projectfloodlight.openflow.types.IPv4Address;
34 * Interpreter for Nicira OpenFlow extensions.
36 public class NiciraExtensionInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionInterpreter, ExtensionResolver {
40 public boolean supported(ExtensionType extensionType) {
41 if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST)) {
49 public OFAction mapInstruction(OFFactory factory, ExtensionInstruction extensionInstruction) {
50 ExtensionType type = extensionInstruction.type();
51 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) {
52 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionInstruction;
53 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
54 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
60 public ExtensionInstruction mapAction(OFAction action) {
61 if (action.getType().equals(OFActionType.SET_FIELD)) {
62 OFActionSetField setFieldAction = (OFActionSetField) action;
63 OFOxm<?> oxm = setFieldAction.getField();
64 switch (oxm.getMatchField().id) {
66 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
67 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
69 throw new UnsupportedOperationException(
70 "Driver does not support extension type " + oxm.getMatchField().id);
77 public ExtensionInstruction getExtensionInstruction(ExtensionType type) {
78 if (type.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) {
79 return new NiciraSetTunnelDst();
81 throw new UnsupportedOperationException(
82 "Driver does not support extension type " + type.toString());