Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
| 19 | import org.onlab.packet.Ip4Address; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 20 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 21 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 22 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 24 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 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; |
| 32 | |
| 33 | /** |
| 34 | * Interpreter for Nicira OpenFlow extensions. |
| 35 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 36 | public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 37 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 38 | |
| 39 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 40 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 41 | if (extensionTreatmentType.equals( |
| 42 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 43 | return true; |
| 44 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 45 | if (extensionTreatmentType.equals( |
| 46 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 47 | return true; |
| 48 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame^] | 49 | if (extensionTreatmentType.equals( |
| 50 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 51 | return true; |
| 52 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 53 | return false; |
| 54 | } |
| 55 | |
| 56 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 57 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 61 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 62 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 63 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 64 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 65 | // TODO this will be implemented later |
| 66 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame^] | 67 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 68 | // TODO this will be implemented later |
| 69 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 70 | return null; |
| 71 | } |
| 72 | |
| 73 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 74 | public ExtensionTreatment mapAction(OFAction action) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 75 | 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 |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 91 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 92 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 93 | return new NiciraSetTunnelDst(); |
| 94 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 95 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 96 | return new NiciraResubmit(); |
| 97 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame^] | 98 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 99 | return new NiciraSetNshSpi(); |
| 100 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 101 | throw new UnsupportedOperationException( |
| 102 | "Driver does not support extension type " + type.toString()); |
| 103 | } |
| 104 | } |