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 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 34 | * Interpreter for Nicira OpenFlow treatment extensions. |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 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 | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 49 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 50 | return true; |
| 51 | } |
| 52 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 53 | return true; |
| 54 | } |
| 55 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 56 | return true; |
| 57 | } |
| 58 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 59 | return true; |
| 60 | } |
| 61 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 62 | return true; |
| 63 | } |
| 64 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 65 | return true; |
| 66 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 67 | if (extensionTreatmentType.equals( |
| 68 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 69 | return true; |
| 70 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 71 | if (extensionTreatmentType.equals( |
| 72 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 73 | return true; |
| 74 | } |
| 75 | if (extensionTreatmentType.equals( |
| 76 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 77 | return true; |
| 78 | } |
| 79 | if (extensionTreatmentType.equals( |
| 80 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 81 | return true; |
| 82 | } |
| 83 | if (extensionTreatmentType.equals( |
| 84 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 85 | return true; |
| 86 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | |
| 90 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 91 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 92 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 93 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 94 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 95 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 96 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 97 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 98 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 99 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 100 | return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), |
| 101 | resubmit.table()); |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 102 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 103 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 104 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 105 | return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), |
| 106 | resubmitTable.table()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 107 | } |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 108 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 109 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 110 | return factory.actions().niciraSetNsp(niciraNshSpi.nshSpi().servicePathId()); |
| 111 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 112 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 113 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 114 | return factory.actions().niciraSetNsp(niciraNshSi.nshSi().serviceIndex()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 115 | } |
| 116 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 117 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 118 | return factory.actions().niciraSetNshc1(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 119 | } |
| 120 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 121 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 122 | return factory.actions().niciraSetNshc2(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 123 | } |
| 124 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 125 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 126 | return factory.actions().niciraSetNshc3(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 127 | } |
| 128 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 129 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 130 | return factory.actions().niciraSetNshc4(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 131 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 132 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 133 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 134 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 135 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 136 | // TODO this will be implemented later |
| 137 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 138 | return null; |
| 139 | } |
| 140 | |
| 141 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 142 | public ExtensionTreatment mapAction(OFAction action) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 143 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 144 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 145 | OFOxm<?> oxm = setFieldAction.getField(); |
| 146 | switch (oxm.getMatchField().id) { |
| 147 | case TUNNEL_IPV4_DST: |
| 148 | OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm; |
| 149 | return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt())); |
| 150 | default: |
| 151 | throw new UnsupportedOperationException( |
| 152 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 153 | } |
| 154 | } |
| 155 | return null; |
| 156 | } |
| 157 | |
| 158 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 159 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 160 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 161 | return new NiciraSetTunnelDst(); |
| 162 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 163 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 164 | return new NiciraResubmit(); |
| 165 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 166 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 167 | return new NiciraResubmitTable(); |
| 168 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 169 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 170 | return new NiciraSetNshSpi(); |
| 171 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 172 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 173 | return new NiciraSetNshSi(); |
| 174 | } |
| 175 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type()) |
| 176 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type()) |
| 177 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type()) |
| 178 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 179 | return new NiciraSetNshContextHeader(type); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 180 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 181 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 182 | return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha(); |
| 183 | } |
| 184 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 185 | return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa(); |
| 186 | } |
| 187 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 188 | return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst(); |
| 189 | } |
| 190 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 191 | return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst(); |
| 192 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 193 | throw new UnsupportedOperationException( |
| 194 | "Driver does not support extension type " + type.toString()); |
| 195 | } |
| 196 | } |