Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Thomas Vachuska | 95caba3 | 2016-04-04 10:42:05 -0700 | [diff] [blame] | 16 | package org.onosproject.provider.of.flow.util; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
Ray Milkey | 84d5a29 | 2016-02-22 14:04:01 -0800 | [diff] [blame] | 20 | import org.onlab.packet.EthType; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 21 | import org.onlab.packet.Ip4Address; |
| 22 | import org.onlab.packet.Ip4Prefix; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 23 | import org.onlab.packet.Ip6Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 24 | import org.onlab.packet.Ip6Prefix; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 26 | import org.onlab.packet.MplsLabel; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 27 | import org.onlab.packet.TpPort; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 28 | import org.onlab.packet.VlanId; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 29 | import org.onosproject.core.GroupId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 31 | import org.onosproject.net.Lambda; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 32 | import org.onosproject.net.OduSignalId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.PortNumber; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 34 | import org.onosproject.net.driver.DefaultDriverData; |
| 35 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 36 | import org.onosproject.net.driver.Driver; |
| 37 | import org.onosproject.net.driver.DriverHandler; |
| 38 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 40 | import org.onosproject.net.flow.DefaultFlowRule; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 43 | import org.onosproject.net.flow.FlowEntry; |
| 44 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
| 45 | import org.onosproject.net.flow.FlowRule; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 46 | import org.onosproject.net.flow.StatTriggerField; |
| 47 | import org.onosproject.net.flow.StatTriggerFlag; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.flow.TrafficSelector; |
| 49 | import org.onosproject.net.flow.TrafficTreatment; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes; |
Sho SHIMIZU | 9553bb8 | 2015-06-30 16:02:45 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.instructions.Instructions; |
cansu.toprak | 409289d | 2017-10-27 10:04:05 +0300 | [diff] [blame] | 52 | import org.onosproject.net.meter.MeterId; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 53 | import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 54 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 55 | import org.onosproject.provider.of.flow.impl.NewAdaptiveFlowStatsCollector; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 56 | import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| 59 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.protocol.OFObject; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.protocol.OFOxsList; |
| 63 | import org.projectfloodlight.openflow.protocol.OFStatTriggerFlags; |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.protocol.OFVersion; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 65 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 66 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 67 | import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 68 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.action.OFActionGroup; |
cansu.toprak | 409289d | 2017-10-27 10:04:05 +0300 | [diff] [blame] | 70 | import org.projectfloodlight.openflow.protocol.action.OFActionMeter; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 71 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 72 | import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls; |
Konstantinos Kanonakis | 9215ff2 | 2016-11-04 13:28:11 -0500 | [diff] [blame] | 73 | import org.projectfloodlight.openflow.protocol.action.OFActionPushVlan; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 74 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; |
| 75 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 76 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst; |
| 78 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc; |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 79 | import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 80 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; |
| 81 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 82 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 83 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 84 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 85 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionStatTrigger; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 86 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 89 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 90 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Yafit Hadar | 4cc65f7 | 2016-02-10 11:23:06 +0200 | [diff] [blame] | 91 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.protocol.oxs.OFOxs; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 93 | import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 95 | import org.projectfloodlight.openflow.types.IPv4Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 96 | import org.projectfloodlight.openflow.types.IPv6Address; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.types.Masked; |
Pier Ventre | 23f7867 | 2016-11-15 08:46:34 -0800 | [diff] [blame] | 98 | import org.projectfloodlight.openflow.types.OFBooleanValue; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 99 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 100 | import org.projectfloodlight.openflow.types.OduSignalID; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 101 | import org.projectfloodlight.openflow.types.TransportPort; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 102 | import org.projectfloodlight.openflow.types.U32; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 103 | import org.projectfloodlight.openflow.types.U64; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 104 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 105 | import org.projectfloodlight.openflow.types.VlanPcp; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 106 | import org.slf4j.Logger; |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 107 | import org.slf4j.LoggerFactory; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 108 | |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 109 | import java.util.List; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 110 | import java.util.Map; |
| 111 | import java.util.Set; |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 112 | |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 113 | import static java.util.concurrent.TimeUnit.NANOSECONDS; |
| 114 | import static java.util.concurrent.TimeUnit.SECONDS; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 115 | import static org.onosproject.net.flow.StatTriggerField.*; |
| 116 | import static org.onosproject.net.flow.StatTriggerField.IDLE_TIME; |
| 117 | import static org.onosproject.net.flow.StatTriggerFlag.ONLY_FIRST; |
| 118 | import static org.onosproject.net.flow.StatTriggerFlag.PERIODIC; |
alshabib | 44852fb | 2016-04-15 15:56:51 -0700 | [diff] [blame] | 119 | import static org.onosproject.net.flow.criteria.Criteria.*; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 120 | import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda; |
| 121 | import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId; |
alshabib | 44852fb | 2016-04-15 15:56:51 -0700 | [diff] [blame] | 122 | import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 123 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 124 | public class FlowEntryBuilder { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 125 | private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 126 | |
| 127 | private final OFFlowStatsEntry stat; |
| 128 | private final OFFlowRemoved removed; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 129 | private final OFFlowMod flowMod; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 130 | private final OFFlowLightweightStatsEntry lightWeightStat; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 131 | |
| 132 | private final Match match; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 133 | |
Jonathan Hart | 67fc097 | 2015-03-19 15:21:20 -0700 | [diff] [blame] | 134 | // All actions are contained in an OFInstruction. For OF1.0 |
| 135 | // the instruction type is apply instruction (immediate set in ONOS speak) |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 136 | private final List<OFInstruction> instructions; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 137 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 138 | private final DeviceId deviceId; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 139 | |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 140 | public enum FlowType { STAT, LIGHTWEIGHT_STAT, REMOVED, MOD } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 141 | |
| 142 | private final FlowType type; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 143 | |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 144 | private DriverHandler driverHandler; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 145 | |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 146 | // NewAdaptiveFlowStatsCollector for AdaptiveFlowSampling mode, |
| 147 | // null is not AFM mode, namely SimpleStatsCollector mode |
| 148 | private NewAdaptiveFlowStatsCollector afsc; |
| 149 | |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 150 | public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverHandler driverHandler) { |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 151 | this.stat = entry; |
| 152 | this.match = entry.getMatch(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 153 | this.instructions = getInstructions(entry); |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 154 | this.deviceId = deviceId; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 155 | this.removed = null; |
| 156 | this.flowMod = null; |
| 157 | this.type = FlowType.STAT; |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 158 | this.driverHandler = driverHandler; |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 159 | this.afsc = null; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 160 | this.lightWeightStat = null; |
| 161 | } |
| 162 | |
| 163 | public FlowEntryBuilder(DeviceId deviceId, OFFlowLightweightStatsEntry lightWeightStat, |
| 164 | DriverService driverService) { |
| 165 | this.stat = null; |
| 166 | this.match = lightWeightStat.getMatch(); |
| 167 | this.instructions = null; |
| 168 | this.deviceId = deviceId; |
| 169 | this.removed = null; |
| 170 | this.flowMod = null; |
| 171 | this.type = FlowType.LIGHTWEIGHT_STAT; |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 172 | this.driverHandler = getDriver(deviceId, driverService); |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 173 | this.afsc = null; |
| 174 | this.lightWeightStat = lightWeightStat; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 177 | public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverHandler driverHandler) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 178 | this.match = removed.getMatch(); |
| 179 | this.removed = removed; |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 180 | this.deviceId = deviceId; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 181 | this.instructions = null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 182 | this.stat = null; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 183 | this.flowMod = null; |
| 184 | this.type = FlowType.REMOVED; |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 185 | this.driverHandler = driverHandler; |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 186 | this.afsc = null; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 187 | this.lightWeightStat = null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 190 | public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverHandler driverHandler) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 191 | this.match = fm.getMatch(); |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 192 | this.deviceId = deviceId; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 193 | this.instructions = getInstructions(fm); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 194 | this.type = FlowType.MOD; |
| 195 | this.flowMod = fm; |
| 196 | this.stat = null; |
| 197 | this.removed = null; |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 198 | this.driverHandler = driverHandler; |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 199 | this.afsc = null; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 200 | this.lightWeightStat = null; |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 201 | } |
| 202 | |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 203 | public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) { |
| 204 | this(deviceId, entry, getDriver(deviceId, driverService)); |
| 205 | } |
| 206 | |
| 207 | public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) { |
| 208 | this(deviceId, removed, getDriver(deviceId, driverService)); |
| 209 | } |
| 210 | |
| 211 | public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) { |
| 212 | this(deviceId, fm, getDriver(deviceId, driverService)); |
| 213 | } |
| 214 | |
Sangsik Yoon | b1b823f | 2016-05-16 18:55:39 +0900 | [diff] [blame] | 215 | public FlowEntryBuilder withSetAfsc(NewAdaptiveFlowStatsCollector afsc) { |
| 216 | this.afsc = afsc; |
| 217 | return this; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 218 | } |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 219 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 220 | public FlowEntry build(FlowEntryState... state) { |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 221 | try { |
| 222 | switch (this.type) { |
| 223 | case STAT: |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 224 | return createFlowEntryFromStat(); |
| 225 | case LIGHTWEIGHT_STAT: |
| 226 | return createFlowEntryFromLightweightStat(); |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 227 | case REMOVED: |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 228 | return createFlowEntryForFlowRemoved(); |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 229 | case MOD: |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 230 | return createFlowEntryForFlowMod(state); |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 231 | default: |
| 232 | log.error("Unknown flow type : {}", this.type); |
| 233 | return null; |
| 234 | } |
| 235 | } catch (UnsupportedOperationException e) { |
| 236 | log.warn("Error building flow entry", e); |
| 237 | return null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 238 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 239 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 242 | private FlowEntry createFlowEntryFromStat() { |
| 243 | |
| 244 | FlowRule.Builder builder = DefaultFlowRule.builder() |
| 245 | .forDevice(deviceId) |
| 246 | .withSelector(buildSelector()) |
| 247 | .withTreatment(buildTreatment()) |
| 248 | .withPriority(stat.getPriority()) |
| 249 | .withIdleTimeout(stat.getIdleTimeout()) |
| 250 | .withCookie(stat.getCookie().getValue()); |
| 251 | if (stat.getVersion() != OFVersion.OF_10) { |
| 252 | builder.forTable(stat.getTableId().getValue()); |
| 253 | } |
| 254 | if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) { |
| 255 | if (afsc != null) { |
| 256 | FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(stat.getDurationSec()); |
| 257 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 258 | SECONDS.toNanos(stat.getDurationSec()) |
| 259 | + stat.getDurationNsec(), NANOSECONDS, |
| 260 | liveType, |
| 261 | stat.getPacketCount().getValue(), |
| 262 | stat.getByteCount().getValue()); |
| 263 | } else { |
| 264 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 265 | stat.getDurationSec(), |
| 266 | stat.getPacketCount().getValue(), |
| 267 | stat.getByteCount().getValue()); |
| 268 | } |
| 269 | } |
| 270 | FlowStatParser statParser = new FlowStatParser(stat.getStats()); |
| 271 | if (afsc != null && statParser.isDurationReceived()) { |
| 272 | FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration()); |
| 273 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 274 | SECONDS.toNanos(statParser.getDuration()) |
| 275 | + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS, |
| 276 | liveType, |
| 277 | statParser.getPacketCount(), |
| 278 | statParser.getByteCount()); |
| 279 | } else { |
| 280 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 281 | statParser.getDuration(), |
| 282 | statParser.getPacketCount(), |
| 283 | statParser.getByteCount()); |
| 284 | } |
| 285 | |
| 286 | } |
| 287 | |
Yuta HIGUCHI | e7e71a8 | 2018-05-18 16:36:43 -0700 | [diff] [blame] | 288 | private FlowEntry createFlowEntryForFlowMod(FlowEntryState...state) { |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 289 | FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; |
| 290 | FlowRule.Builder builder = DefaultFlowRule.builder() |
| 291 | .forDevice(deviceId) |
| 292 | .withSelector(buildSelector()) |
| 293 | .withTreatment(buildTreatment()) |
| 294 | .withPriority(flowMod.getPriority()) |
| 295 | .withIdleTimeout(flowMod.getIdleTimeout()) |
| 296 | .withCookie(flowMod.getCookie().getValue()); |
| 297 | if (flowMod.getVersion() != OFVersion.OF_10) { |
| 298 | builder.forTable(flowMod.getTableId().getValue()); |
| 299 | } |
| 300 | |
| 301 | if (afsc != null) { |
| 302 | FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE; |
| 303 | return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0); |
| 304 | } else { |
| 305 | return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | private FlowEntry createFlowEntryForFlowRemoved() { |
| 310 | FlowRule.Builder builder = DefaultFlowRule.builder() |
| 311 | .forDevice(deviceId) |
| 312 | .withSelector(buildSelector()) |
| 313 | .withPriority(removed.getPriority()) |
| 314 | .withIdleTimeout(removed.getIdleTimeout()) |
| 315 | .withCookie(removed.getCookie().getValue()) |
| 316 | .withReason(FlowRule.FlowRemoveReason.parseShort((short) removed.getReason().ordinal())); |
| 317 | |
| 318 | if (removed.getVersion() != OFVersion.OF_10) { |
| 319 | builder.forTable(removed.getTableId().getValue()); |
| 320 | } |
| 321 | if (removed.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) { |
| 322 | if (afsc != null) { |
| 323 | FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(removed.getDurationSec()); |
| 324 | return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED, |
| 325 | SECONDS.toNanos(removed.getDurationSec()) |
| 326 | + removed.getDurationNsec(), NANOSECONDS, |
| 327 | liveType, |
| 328 | removed.getPacketCount().getValue(), |
| 329 | removed.getByteCount().getValue()); |
| 330 | } else { |
| 331 | return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED, |
| 332 | removed.getDurationSec(), |
| 333 | removed.getPacketCount().getValue(), |
| 334 | removed.getByteCount().getValue()); |
| 335 | } |
| 336 | } |
| 337 | FlowStatParser statParser = new FlowStatParser(removed.getStats()); |
| 338 | if (afsc != null && statParser.isDurationReceived()) { |
| 339 | FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration()); |
| 340 | return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED, |
| 341 | SECONDS.toNanos(statParser.getDuration()) |
| 342 | + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS, |
| 343 | liveType, |
| 344 | statParser.getPacketCount(), |
| 345 | statParser.getByteCount()); |
| 346 | } else { |
| 347 | return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED, |
| 348 | statParser.getDuration(), |
| 349 | statParser.getPacketCount(), |
| 350 | statParser.getByteCount()); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | private FlowEntry createFlowEntryFromLightweightStat() { |
| 355 | FlowRule.Builder builder = DefaultFlowRule.builder() |
| 356 | .forDevice(deviceId) |
| 357 | .withSelector(buildSelector()) |
| 358 | .withPriority(lightWeightStat.getPriority()) |
| 359 | .withIdleTimeout(0) |
| 360 | .withCookie(0); |
| 361 | FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats()); |
| 362 | builder.forTable(lightWeightStat.getTableId().getValue()); |
| 363 | if (afsc != null && flowLightweightStatParser.isDurationReceived()) { |
| 364 | FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration()); |
| 365 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 366 | SECONDS.toNanos(flowLightweightStatParser.getDuration()) |
| 367 | + flowLightweightStatParser.getDuration(), NANOSECONDS, |
| 368 | liveType, |
| 369 | flowLightweightStatParser.getPacketCount(), |
| 370 | flowLightweightStatParser.getByteCount()); |
| 371 | } else { |
| 372 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 373 | flowLightweightStatParser.getDuration(), |
| 374 | flowLightweightStatParser.getPacketCount(), |
| 375 | flowLightweightStatParser.getByteCount()); |
| 376 | } |
| 377 | } |
| 378 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 379 | private List<OFInstruction> getInstructions(OFFlowMod entry) { |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 380 | switch (entry.getVersion()) { |
| 381 | case OF_10: |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 382 | return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions() |
| 383 | .applyActions( |
| 384 | entry.getActions())); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 385 | case OF_11: |
| 386 | case OF_12: |
| 387 | case OF_13: |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 388 | case OF_14: |
| 389 | case OF_15: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 390 | return entry.getInstructions(); |
| 391 | default: |
| 392 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 393 | } |
| 394 | return Lists.newLinkedList(); |
| 395 | } |
| 396 | |
| 397 | private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) { |
| 398 | switch (entry.getVersion()) { |
| 399 | case OF_10: |
| 400 | return Lists.newArrayList( |
| 401 | OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions())); |
| 402 | case OF_11: |
| 403 | case OF_12: |
| 404 | case OF_13: |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 405 | case OF_14: |
| 406 | case OF_15: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 407 | return entry.getInstructions(); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 408 | default: |
| 409 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 410 | } |
| 411 | return Lists.newLinkedList(); |
| 412 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 413 | |
| 414 | private TrafficTreatment buildTreatment() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 415 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 416 | for (OFInstruction in : instructions) { |
| 417 | switch (in.getType()) { |
| 418 | case GOTO_TABLE: |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 419 | builder.transition(((int) ((OFInstructionGotoTable) in) |
| 420 | .getTableId().getValue())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 421 | break; |
| 422 | case WRITE_METADATA: |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 423 | OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in; |
| 424 | builder.writeMetadata(m.getMetadata().getValue(), |
| 425 | m.getMetadataMask().getValue()); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 426 | break; |
| 427 | case WRITE_ACTIONS: |
| 428 | builder.deferred(); |
| 429 | buildActions(((OFInstructionWriteActions) in).getActions(), |
| 430 | builder); |
| 431 | break; |
| 432 | case APPLY_ACTIONS: |
| 433 | builder.immediate(); |
| 434 | buildActions(((OFInstructionApplyActions) in).getActions(), |
| 435 | builder); |
| 436 | break; |
| 437 | case CLEAR_ACTIONS: |
| 438 | builder.wipeDeferred(); |
| 439 | break; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 440 | case STAT_TRIGGER: |
| 441 | OFInstructionStatTrigger statTrigger = (OFInstructionStatTrigger) in; |
| 442 | buildStatTrigger(statTrigger.getThresholds(), statTrigger.getFlags(), builder); |
| 443 | break; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 444 | case EXPERIMENTER: |
| 445 | break; |
| 446 | case METER: |
| 447 | break; |
| 448 | default: |
| 449 | log.warn("Unknown instructions type {}", in.getType()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | return builder.build(); |
| 454 | } |
| 455 | |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 456 | private TrafficTreatment.Builder buildStatTrigger(OFOxsList oxsList, |
| 457 | Set<OFStatTriggerFlags> flagsSet, |
| 458 | TrafficTreatment.Builder builder) { |
| 459 | Map<StatTriggerField, Long> statTriggerMap = Maps.newEnumMap(StatTriggerField.class); |
| 460 | for (OFOxs<?> ofOxs : oxsList) { |
| 461 | switch (ofOxs.getStatField().id) { |
| 462 | case DURATION: |
| 463 | U64 durationType = (U64) ofOxs.getValue(); |
| 464 | statTriggerMap.put(DURATION, durationType.getValue()); |
| 465 | break; |
| 466 | case FLOW_COUNT: |
| 467 | U32 flowCount = (U32) ofOxs.getValue(); |
| 468 | statTriggerMap.put(FLOW_COUNT, flowCount.getValue()); |
| 469 | break; |
| 470 | case PACKET_COUNT: |
| 471 | U64 packetCount = (U64) ofOxs.getValue(); |
| 472 | statTriggerMap.put(PACKET_COUNT, packetCount.getValue()); |
| 473 | break; |
| 474 | case BYTE_COUNT: |
| 475 | U64 byteCount = (U64) ofOxs.getValue(); |
| 476 | statTriggerMap.put(BYTE_COUNT, byteCount.getValue()); |
| 477 | break; |
| 478 | case IDLE_TIME: |
| 479 | U64 idleTime = (U64) ofOxs.getValue(); |
| 480 | statTriggerMap.put(IDLE_TIME, idleTime.getValue()); |
| 481 | break; |
| 482 | default: |
| 483 | log.warn("getStatField not supported {}", ofOxs.getStatField().id); |
| 484 | break; |
| 485 | } |
| 486 | } |
| 487 | StatTriggerFlag flag = null; |
| 488 | for (OFStatTriggerFlags flags : flagsSet) { |
| 489 | switch (flags) { |
| 490 | case PERIODIC: |
| 491 | flag = PERIODIC; |
| 492 | break; |
| 493 | case ONLY_FIRST: |
| 494 | flag = ONLY_FIRST; |
| 495 | break; |
| 496 | default: |
| 497 | log.warn("flag not supported {}", flags); |
| 498 | break; |
| 499 | } |
| 500 | } |
| 501 | if (!statTriggerMap.isEmpty() && flag != null) { |
| 502 | builder.add(Instructions.statTrigger(statTriggerMap, flag)); |
| 503 | } |
| 504 | return builder; |
| 505 | } |
| 506 | |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Configures traffic treatment builder with a given collection of actions. |
| 509 | * |
| 510 | * @param actions a set of OpenFlow actions |
| 511 | * @param builder traffic treatment builder |
| 512 | * @param driverHandler driver handler |
| 513 | * @param deviceId device identifier |
| 514 | * @return configured traffic treatment builder |
| 515 | */ |
| 516 | public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions, |
| 517 | TrafficTreatment.Builder builder, |
| 518 | DriverHandler driverHandler, |
| 519 | DeviceId deviceId) { |
| 520 | ExtensionTreatmentInterpreter interpreter; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 521 | if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 522 | interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 523 | } else { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 524 | interpreter = null; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 525 | } |
| 526 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 527 | for (OFAction act : actions) { |
| 528 | switch (act.getType()) { |
| 529 | case OUTPUT: |
| 530 | OFActionOutput out = (OFActionOutput) act; |
| 531 | builder.setOutput( |
| 532 | PortNumber.portNumber(out.getPort().getPortNumber())); |
| 533 | break; |
| 534 | case SET_VLAN_VID: |
| 535 | OFActionSetVlanVid vlan = (OFActionSetVlanVid) act; |
| 536 | builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())); |
| 537 | break; |
| 538 | case SET_VLAN_PCP: |
| 539 | OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act; |
| 540 | builder.setVlanPcp(pcp.getVlanPcp().getValue()); |
| 541 | break; |
| 542 | case SET_DL_DST: |
| 543 | OFActionSetDlDst dldst = (OFActionSetDlDst) act; |
| 544 | builder.setEthDst( |
| 545 | MacAddress.valueOf(dldst.getDlAddr().getLong())); |
| 546 | break; |
| 547 | case SET_DL_SRC: |
| 548 | OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act; |
| 549 | builder.setEthSrc( |
| 550 | MacAddress.valueOf(dlsrc.getDlAddr().getLong())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 551 | break; |
| 552 | case SET_NW_DST: |
| 553 | OFActionSetNwDst nwdst = (OFActionSetNwDst) act; |
| 554 | IPv4Address di = nwdst.getNwAddr(); |
| 555 | builder.setIpDst(Ip4Address.valueOf(di.getInt())); |
| 556 | break; |
| 557 | case SET_NW_SRC: |
| 558 | OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act; |
| 559 | IPv4Address si = nwsrc.getNwAddr(); |
| 560 | builder.setIpSrc(Ip4Address.valueOf(si.getInt())); |
| 561 | break; |
| 562 | case EXPERIMENTER: |
| 563 | OFActionExperimenter exp = (OFActionExperimenter) act; |
| 564 | if (exp.getExperimenter() == 0x80005A06 || |
| 565 | exp.getExperimenter() == 0x748771) { |
| 566 | OFActionCircuit ct = (OFActionCircuit) exp; |
Yafit Hadar | 4cc65f7 | 2016-02-10 11:23:06 +0200 | [diff] [blame] | 567 | CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue(); |
| 568 | builder.add(Instructions.modL0Lambda(Lambda.ochSignal( |
| 569 | lookupGridType(circuitSignalID.getGridType()), |
| 570 | lookupChannelSpacing(circuitSignalID.getChannelSpacing()), |
| 571 | circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth()))); |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 572 | } else if (interpreter != null) { |
| 573 | builder.extension(interpreter.mapAction(exp), deviceId); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 574 | } else { |
| 575 | log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); |
| 576 | } |
| 577 | break; |
| 578 | case SET_FIELD: |
| 579 | OFActionSetField setField = (OFActionSetField) act; |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 580 | handleSetField(builder, setField, driverHandler, deviceId); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 581 | break; |
| 582 | case POP_MPLS: |
| 583 | OFActionPopMpls popMpls = (OFActionPopMpls) act; |
Ray Milkey | 84d5a29 | 2016-02-22 14:04:01 -0800 | [diff] [blame] | 584 | builder.popMpls(new EthType(popMpls.getEthertype().getValue())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 585 | break; |
| 586 | case PUSH_MPLS: |
| 587 | builder.pushMpls(); |
| 588 | break; |
| 589 | case COPY_TTL_IN: |
| 590 | builder.copyTtlIn(); |
| 591 | break; |
| 592 | case COPY_TTL_OUT: |
| 593 | builder.copyTtlOut(); |
| 594 | break; |
| 595 | case DEC_MPLS_TTL: |
| 596 | builder.decMplsTtl(); |
| 597 | break; |
| 598 | case DEC_NW_TTL: |
| 599 | builder.decNwTtl(); |
| 600 | break; |
| 601 | case GROUP: |
| 602 | OFActionGroup group = (OFActionGroup) act; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 603 | builder.group(new GroupId(group.getGroup().getGroupNumber())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 604 | break; |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 605 | case SET_QUEUE: |
| 606 | OFActionSetQueue setQueue = (OFActionSetQueue) act; |
| 607 | builder.setQueue(setQueue.getQueueId()); |
| 608 | break; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 609 | case ENQUEUE: |
| 610 | OFActionEnqueue enqueue = (OFActionEnqueue) act; |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 611 | builder.setQueue(enqueue.getQueueId(), |
| 612 | PortNumber.portNumber(enqueue.getPort().getPortNumber())); |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 613 | break; |
Jonathan Hart | 67fc097 | 2015-03-19 15:21:20 -0700 | [diff] [blame] | 614 | case STRIP_VLAN: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 615 | case POP_VLAN: |
| 616 | builder.popVlan(); |
| 617 | break; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 618 | case PUSH_VLAN: |
Konstantinos Kanonakis | 9215ff2 | 2016-11-04 13:28:11 -0500 | [diff] [blame] | 619 | OFActionPushVlan pushVlan = (OFActionPushVlan) act; |
| 620 | builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue())); |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 621 | break; |
cansu.toprak | 409289d | 2017-10-27 10:04:05 +0300 | [diff] [blame] | 622 | case METER: |
| 623 | OFActionMeter actionMeter = (OFActionMeter) act; |
| 624 | builder.meter(MeterId.meterId(actionMeter.getMeterId())); |
| 625 | break; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 626 | case SET_TP_DST: |
| 627 | case SET_TP_SRC: |
| 628 | case POP_PBB: |
| 629 | case PUSH_PBB: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 630 | case SET_MPLS_LABEL: |
| 631 | case SET_MPLS_TC: |
| 632 | case SET_MPLS_TTL: |
| 633 | case SET_NW_ECN: |
| 634 | case SET_NW_TOS: |
| 635 | case SET_NW_TTL: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 636 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 637 | default: |
| 638 | log.warn("Action type {} not yet implemented.", act.getType()); |
| 639 | } |
| 640 | } |
| 641 | return builder; |
| 642 | } |
| 643 | |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 644 | private TrafficTreatment.Builder buildActions(List<OFAction> actions, |
| 645 | TrafficTreatment.Builder builder) { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 646 | return configureTreatmentBuilder(actions, builder, driverHandler, deviceId); |
| 647 | } |
| 648 | |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 649 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 650 | private static void handleSetField(TrafficTreatment.Builder builder, |
| 651 | OFActionSetField action, |
| 652 | DriverHandler driverHandler, |
| 653 | DeviceId deviceId) { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 654 | ExtensionTreatmentInterpreter treatmentInterpreter; |
| 655 | if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { |
| 656 | treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); |
| 657 | } else { |
| 658 | treatmentInterpreter = null; |
| 659 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 660 | OFOxm<?> oxm = action.getField(); |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 661 | switch (oxm.getMatchField().id) { |
| 662 | case VLAN_PCP: |
| 663 | @SuppressWarnings("unchecked") |
| 664 | OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm; |
| 665 | builder.setVlanPcp(vlanpcp.getValue().getValue()); |
| 666 | break; |
| 667 | case VLAN_VID: |
Charles Chan | 4211baa | 2016-04-20 17:10:40 -0700 | [diff] [blame] | 668 | if (treatmentInterpreter != null) { |
| 669 | try { |
| 670 | builder.extension(treatmentInterpreter.mapAction(action), deviceId); |
| 671 | break; |
| 672 | } catch (UnsupportedOperationException e) { |
| 673 | log.debug("Unsupported action extension; defaulting to native OF"); |
| 674 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 675 | } |
alshabib | 44852fb | 2016-04-15 15:56:51 -0700 | [diff] [blame] | 676 | @SuppressWarnings("unchecked") |
| 677 | OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm; |
| 678 | builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan())); |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 679 | break; |
| 680 | case ETH_DST: |
| 681 | @SuppressWarnings("unchecked") |
| 682 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst = |
| 683 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 684 | builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong())); |
| 685 | break; |
| 686 | case ETH_SRC: |
| 687 | @SuppressWarnings("unchecked") |
| 688 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc = |
| 689 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 690 | builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong())); |
| 691 | break; |
| 692 | case IPV4_DST: |
| 693 | @SuppressWarnings("unchecked") |
| 694 | OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm; |
| 695 | builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt())); |
| 696 | break; |
| 697 | case IPV4_SRC: |
| 698 | @SuppressWarnings("unchecked") |
| 699 | OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm; |
| 700 | builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt())); |
| 701 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 702 | case MPLS_LABEL: |
| 703 | @SuppressWarnings("unchecked") |
| 704 | OFOxm<U32> labelId = (OFOxm<U32>) oxm; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 705 | builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue())); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 706 | break; |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 707 | case MPLS_BOS: |
| 708 | @SuppressWarnings("unchecked") |
Pier Ventre | 23f7867 | 2016-11-15 08:46:34 -0800 | [diff] [blame] | 709 | OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm; |
| 710 | builder.setMplsBos(mplsBos.getValue().getValue()); |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 711 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 712 | case TUNNEL_ID: |
| 713 | @SuppressWarnings("unchecked") |
| 714 | OFOxm<U64> tunnelId = (OFOxm<U64>) oxm; |
| 715 | builder.setTunnelId(tunnelId.getValue().getValue()); |
| 716 | break; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 717 | case TCP_DST: |
| 718 | @SuppressWarnings("unchecked") |
| 719 | OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 720 | builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 721 | break; |
| 722 | case TCP_SRC: |
| 723 | @SuppressWarnings("unchecked") |
| 724 | OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 725 | builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 726 | break; |
| 727 | case UDP_DST: |
| 728 | @SuppressWarnings("unchecked") |
| 729 | OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 730 | builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 731 | break; |
| 732 | case UDP_SRC: |
| 733 | @SuppressWarnings("unchecked") |
| 734 | OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 735 | builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 736 | break; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 737 | case TUNNEL_IPV4_DST: |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 738 | case NSP: |
| 739 | case NSI: |
| 740 | case NSH_C1: |
| 741 | case NSH_C2: |
| 742 | case NSH_C3: |
| 743 | case NSH_C4: |
| 744 | case NSH_MDTYPE: |
| 745 | case NSH_NP: |
| 746 | case ENCAP_ETH_SRC: |
| 747 | case ENCAP_ETH_DST: |
| 748 | case ENCAP_ETH_TYPE: |
| 749 | case TUN_GPE_NP: |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 750 | if (treatmentInterpreter != null) { |
| 751 | try { |
| 752 | builder.extension(treatmentInterpreter.mapAction(action), deviceId); |
| 753 | } catch (UnsupportedOperationException e) { |
alshabib | 44852fb | 2016-04-15 15:56:51 -0700 | [diff] [blame] | 754 | log.debug(e.getMessage()); |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 755 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 756 | } |
| 757 | break; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 758 | case EXP_ODU_SIG_ID: |
| 759 | @SuppressWarnings("unchecked") |
| 760 | OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm; |
| 761 | OduSignalID oduSignalID = oduID.getValue(); |
| 762 | OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(), |
| 763 | oduSignalID.getTslen(), |
| 764 | oduSignalID.getTsmap()); |
| 765 | builder.add(modL1OduSignalId(oduSignalId)); |
| 766 | break; |
| 767 | case EXP_OCH_SIG_ID: |
| 768 | try { |
| 769 | @SuppressWarnings("unchecked") |
| 770 | OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm; |
| 771 | CircuitSignalID circuitSignalID = ochId.getValue(); |
| 772 | builder.add(modL0Lambda(Lambda.ochSignal( |
| 773 | lookupGridType(circuitSignalID.getGridType()), |
| 774 | lookupChannelSpacing(circuitSignalID.getChannelSpacing()), |
| 775 | circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth()))); |
| 776 | } catch (NoMappingFoundException e) { |
| 777 | log.warn(e.getMessage()); |
| 778 | break; |
| 779 | } |
| 780 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 781 | case ARP_OP: |
lishuai | 67574ce | 2016-05-12 16:39:59 +0800 | [diff] [blame] | 782 | @SuppressWarnings("unchecked") |
| 783 | OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop = |
| 784 | (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm; |
| 785 | builder.setArpOp((short) arpop.getValue().getOpcode()); |
| 786 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 787 | case ARP_SHA: |
lishuai | 67574ce | 2016-05-12 16:39:59 +0800 | [diff] [blame] | 788 | @SuppressWarnings("unchecked") |
| 789 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha = |
| 790 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 791 | builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong())); |
| 792 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 793 | case ARP_SPA: |
lishuai | 67574ce | 2016-05-12 16:39:59 +0800 | [diff] [blame] | 794 | @SuppressWarnings("unchecked") |
| 795 | OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm; |
| 796 | builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt())); |
| 797 | break; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 798 | case OFDPA_MPLS_TYPE: |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 799 | case OFDPA_OVID: |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 800 | case OFDPA_MPLS_L2_PORT: |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 801 | case OFDPA_ALLOW_VLAN_TRANSLATION: |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 802 | case OFDPA_QOS_INDEX: |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 803 | if (treatmentInterpreter != null) { |
| 804 | try { |
| 805 | builder.extension(treatmentInterpreter.mapAction(action), deviceId); |
| 806 | break; |
| 807 | } catch (UnsupportedOperationException e) { |
| 808 | log.warn("Unsupported action extension"); |
| 809 | } |
| 810 | } |
| 811 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 812 | case ARP_THA: |
| 813 | case ARP_TPA: |
| 814 | case BSN_EGR_PORT_GROUP_ID: |
| 815 | case BSN_GLOBAL_VRF_ALLOWED: |
| 816 | case BSN_IN_PORTS_128: |
| 817 | case BSN_L3_DST_CLASS_ID: |
| 818 | case BSN_L3_INTERFACE_CLASS_ID: |
| 819 | case BSN_L3_SRC_CLASS_ID: |
| 820 | case BSN_LAG_ID: |
| 821 | case BSN_TCP_FLAGS: |
| 822 | case BSN_UDF0: |
| 823 | case BSN_UDF1: |
| 824 | case BSN_UDF2: |
| 825 | case BSN_UDF3: |
| 826 | case BSN_UDF4: |
| 827 | case BSN_UDF5: |
| 828 | case BSN_UDF6: |
| 829 | case BSN_UDF7: |
| 830 | case BSN_VLAN_XLATE_PORT_GROUP_ID: |
| 831 | case BSN_VRF: |
| 832 | case ETH_TYPE: |
| 833 | case ICMPV4_CODE: |
| 834 | case ICMPV4_TYPE: |
| 835 | case ICMPV6_CODE: |
| 836 | case ICMPV6_TYPE: |
| 837 | case IN_PHY_PORT: |
| 838 | case IN_PORT: |
| 839 | case IPV6_DST: |
| 840 | case IPV6_FLABEL: |
| 841 | case IPV6_ND_SLL: |
| 842 | case IPV6_ND_TARGET: |
| 843 | case IPV6_ND_TLL: |
| 844 | case IPV6_SRC: |
| 845 | case IP_DSCP: |
| 846 | case IP_ECN: |
| 847 | case IP_PROTO: |
| 848 | case METADATA: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 849 | case MPLS_TC: |
| 850 | case OCH_SIGID: |
| 851 | case OCH_SIGID_BASIC: |
| 852 | case OCH_SIGTYPE: |
| 853 | case OCH_SIGTYPE_BASIC: |
| 854 | case SCTP_DST: |
| 855 | case SCTP_SRC: |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 856 | case EXP_ODU_SIGTYPE: |
| 857 | case EXP_OCH_SIGTYPE: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 858 | default: |
| 859 | log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id); |
| 860 | break; |
| 861 | } |
| 862 | } |
| 863 | |
Sho SHIMIZU | 6f1b09e | 2015-05-05 11:26:22 -0700 | [diff] [blame] | 864 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 865 | private TrafficSelector buildSelector() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 866 | MacAddress mac; |
| 867 | Ip4Prefix ip4Prefix; |
| 868 | Ip6Address ip6Address; |
| 869 | Ip6Prefix ip6Prefix; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 870 | Ip4Address ip; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 871 | |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 872 | ExtensionSelectorInterpreter selectorInterpreter; |
| 873 | if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) { |
| 874 | selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class); |
| 875 | } else { |
| 876 | selectorInterpreter = null; |
| 877 | } |
| 878 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 879 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 880 | for (MatchField<?> field : match.getMatchFields()) { |
| 881 | switch (field.id) { |
| 882 | case IN_PORT: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 883 | builder.matchInPort(PortNumber |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 884 | .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 885 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 886 | case IN_PHY_PORT: |
| 887 | builder.matchInPhyPort(PortNumber |
| 888 | .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber())); |
| 889 | break; |
| 890 | case METADATA: |
| 891 | long metadata = |
| 892 | match.get(MatchField.METADATA).getValue().getValue(); |
| 893 | builder.matchMetadata(metadata); |
| 894 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 895 | case ETH_DST: |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 896 | if (match.isPartiallyMasked(MatchField.ETH_DST)) { |
| 897 | Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 898 | match.getMasked(MatchField.ETH_DST); |
| 899 | builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), |
| 900 | MacAddress.valueOf(maskedMac.getMask().getLong())); |
| 901 | } else { |
| 902 | mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); |
| 903 | builder.matchEthDst(mac); |
| 904 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 905 | break; |
| 906 | case ETH_SRC: |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 907 | if (match.isPartiallyMasked(MatchField.ETH_SRC)) { |
| 908 | Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 909 | match.getMasked(MatchField.ETH_SRC); |
| 910 | builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), |
| 911 | MacAddress.valueOf(maskedMac.getMask().getLong())); |
| 912 | } else { |
| 913 | mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); |
| 914 | builder.matchEthSrc(mac); |
| 915 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 916 | break; |
| 917 | case ETH_TYPE: |
| 918 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 919 | builder.matchEthType((short) ethType); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 920 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 921 | case VLAN_VID: |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 922 | if (selectorInterpreter != null && |
| 923 | selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 924 | if (isOF13OrLater(match)) { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 925 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID); |
| 926 | builder.extension(selectorInterpreter.mapOxm(oxm), |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 927 | deviceId); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 928 | } else { |
| 929 | break; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 930 | } |
| 931 | } else { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 932 | VlanId vlanId = null; |
| 933 | if (match.isPartiallyMasked(MatchField.VLAN_VID)) { |
| 934 | Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID); |
| 935 | if (masked.getValue().equals(OFVlanVidMatch.PRESENT) |
| 936 | && masked.getMask().equals(OFVlanVidMatch.PRESENT)) { |
| 937 | vlanId = VlanId.ANY; |
| 938 | } |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 939 | } else { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 940 | if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) { |
| 941 | vlanId = VlanId.NONE; |
| 942 | } else { |
| 943 | vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); |
| 944 | } |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 945 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 946 | if (vlanId != null) { |
| 947 | builder.matchVlanId(vlanId); |
| 948 | } |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 949 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 950 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 951 | case VLAN_PCP: |
| 952 | byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue(); |
| 953 | builder.matchVlanPcp(vlanPcp); |
| 954 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 955 | case IP_DSCP: |
| 956 | byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue(); |
| 957 | builder.matchIPDscp(ipDscp); |
| 958 | break; |
| 959 | case IP_ECN: |
| 960 | byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue(); |
| 961 | builder.matchIPEcn(ipEcn); |
| 962 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 963 | case IP_PROTO: |
| 964 | short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber(); |
| 965 | builder.matchIPProtocol((byte) proto); |
| 966 | break; |
| 967 | case IPV4_SRC: |
| 968 | if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { |
| 969 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 970 | ip4Prefix = Ip4Prefix.valueOf( |
| 971 | maskedIp.getValue().getInt(), |
| 972 | maskedIp.getMask().asCidrMaskLength()); |
| 973 | } else { |
| 974 | ip4Prefix = Ip4Prefix.valueOf( |
| 975 | match.get(MatchField.IPV4_SRC).getInt(), |
| 976 | Ip4Prefix.MAX_MASK_LENGTH); |
| 977 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 978 | builder.matchIPSrc(ip4Prefix); |
| 979 | break; |
| 980 | case IPV4_DST: |
| 981 | if (match.isPartiallyMasked(MatchField.IPV4_DST)) { |
| 982 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 983 | ip4Prefix = Ip4Prefix.valueOf( |
| 984 | maskedIp.getValue().getInt(), |
| 985 | maskedIp.getMask().asCidrMaskLength()); |
| 986 | } else { |
| 987 | ip4Prefix = Ip4Prefix.valueOf( |
| 988 | match.get(MatchField.IPV4_DST).getInt(), |
| 989 | Ip4Prefix.MAX_MASK_LENGTH); |
| 990 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 991 | builder.matchIPDst(ip4Prefix); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 992 | break; |
| 993 | case TCP_SRC: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 994 | if (match.isPartiallyMasked(MatchField.TCP_SRC)) { |
| 995 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 996 | match.getMasked(MatchField.TCP_SRC); |
| 997 | builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 998 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 999 | } else { |
| 1000 | builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort())); |
| 1001 | } |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 1002 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1003 | case TCP_DST: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 1004 | if (match.isPartiallyMasked(MatchField.TCP_DST)) { |
| 1005 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 1006 | match.getMasked(MatchField.TCP_DST); |
| 1007 | builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 1008 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 1009 | } else { |
| 1010 | builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort())); |
| 1011 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1012 | break; |
| 1013 | case UDP_SRC: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 1014 | if (match.isPartiallyMasked(MatchField.UDP_SRC)) { |
| 1015 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 1016 | match.getMasked(MatchField.UDP_SRC); |
| 1017 | builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 1018 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 1019 | } else { |
| 1020 | builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort())); |
| 1021 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1022 | break; |
| 1023 | case UDP_DST: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 1024 | if (match.isPartiallyMasked(MatchField.UDP_DST)) { |
| 1025 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 1026 | match.getMasked(MatchField.UDP_DST); |
| 1027 | builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 1028 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 1029 | } else { |
| 1030 | builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort())); |
| 1031 | } |
Sho SHIMIZU | 6f1b09e | 2015-05-05 11:26:22 -0700 | [diff] [blame] | 1032 | break; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 1033 | case MPLS_LABEL: |
| 1034 | builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL) |
| 1035 | .getValue())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1036 | break; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 1037 | case MPLS_BOS: |
| 1038 | builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue()); |
| 1039 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1040 | case SCTP_SRC: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 1041 | if (match.isPartiallyMasked(MatchField.SCTP_SRC)) { |
| 1042 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 1043 | match.getMasked(MatchField.SCTP_SRC); |
| 1044 | builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 1045 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 1046 | } else { |
| 1047 | builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort())); |
| 1048 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1049 | break; |
| 1050 | case SCTP_DST: |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 1051 | if (match.isPartiallyMasked(MatchField.SCTP_DST)) { |
| 1052 | Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort = |
| 1053 | match.getMasked(MatchField.SCTP_DST); |
| 1054 | builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()), |
| 1055 | TpPort.tpPort(maskedPort.getMask().getPort())); |
| 1056 | } else { |
| 1057 | builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort())); |
| 1058 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1059 | break; |
| 1060 | case ICMPV4_TYPE: |
| 1061 | byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType(); |
| 1062 | builder.matchIcmpType(icmpType); |
| 1063 | break; |
| 1064 | case ICMPV4_CODE: |
| 1065 | byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode(); |
| 1066 | builder.matchIcmpCode(icmpCode); |
| 1067 | break; |
| 1068 | case IPV6_SRC: |
| 1069 | if (match.isPartiallyMasked(MatchField.IPV6_SRC)) { |
| 1070 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC); |
| 1071 | ip6Prefix = Ip6Prefix.valueOf( |
| 1072 | maskedIp.getValue().getBytes(), |
| 1073 | maskedIp.getMask().asCidrMaskLength()); |
| 1074 | } else { |
| 1075 | ip6Prefix = Ip6Prefix.valueOf( |
| 1076 | match.get(MatchField.IPV6_SRC).getBytes(), |
| 1077 | Ip6Prefix.MAX_MASK_LENGTH); |
| 1078 | } |
| 1079 | builder.matchIPv6Src(ip6Prefix); |
| 1080 | break; |
| 1081 | case IPV6_DST: |
| 1082 | if (match.isPartiallyMasked(MatchField.IPV6_DST)) { |
| 1083 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST); |
| 1084 | ip6Prefix = Ip6Prefix.valueOf( |
| 1085 | maskedIp.getValue().getBytes(), |
| 1086 | maskedIp.getMask().asCidrMaskLength()); |
| 1087 | } else { |
| 1088 | ip6Prefix = Ip6Prefix.valueOf( |
| 1089 | match.get(MatchField.IPV6_DST).getBytes(), |
| 1090 | Ip6Prefix.MAX_MASK_LENGTH); |
| 1091 | } |
| 1092 | builder.matchIPv6Dst(ip6Prefix); |
| 1093 | break; |
| 1094 | case IPV6_FLABEL: |
| 1095 | int flowLabel = |
| 1096 | match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue(); |
| 1097 | builder.matchIPv6FlowLabel(flowLabel); |
| 1098 | break; |
| 1099 | case ICMPV6_TYPE: |
| 1100 | byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue(); |
| 1101 | builder.matchIcmpv6Type(icmpv6type); |
| 1102 | break; |
| 1103 | case ICMPV6_CODE: |
| 1104 | byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue(); |
| 1105 | builder.matchIcmpv6Code(icmpv6code); |
| 1106 | break; |
| 1107 | case IPV6_ND_TARGET: |
| 1108 | ip6Address = |
| 1109 | Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes()); |
| 1110 | builder.matchIPv6NDTargetAddress(ip6Address); |
| 1111 | break; |
| 1112 | case IPV6_ND_SLL: |
| 1113 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong()); |
| 1114 | builder.matchIPv6NDSourceLinkLayerAddress(mac); |
| 1115 | break; |
| 1116 | case IPV6_ND_TLL: |
| 1117 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong()); |
| 1118 | builder.matchIPv6NDTargetLinkLayerAddress(mac); |
| 1119 | break; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 1120 | case IPV6_EXTHDR: |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 1121 | builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR) |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 1122 | .getValue()); |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 1123 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1124 | case OCH_SIGID: |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 1125 | CircuitSignalID sigId = match.get(MatchField.OCH_SIGID); |
| 1126 | builder.add(matchLambda(Lambda.ochSignal( |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 1127 | lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()), |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 1128 | sigId.getChannelNumber(), sigId.getSpectralWidth()) |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 1129 | )); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1130 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 1131 | case OCH_SIGTYPE: |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 1132 | U8 sigType = match.get(MatchField.OCH_SIGTYPE); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 1133 | builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue()))); |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 1134 | break; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 1135 | case EXP_OCH_SIG_ID: |
| 1136 | try { |
| 1137 | CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID); |
| 1138 | builder.add(matchLambda(Lambda.ochSignal( |
| 1139 | lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()), |
| 1140 | expSigId.getChannelNumber(), expSigId.getSpectralWidth()))); |
| 1141 | } catch (NoMappingFoundException e) { |
| 1142 | log.warn(e.getMessage()); |
| 1143 | break; |
| 1144 | } |
| 1145 | break; |
| 1146 | case EXP_OCH_SIGTYPE: |
| 1147 | try { |
| 1148 | U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE); |
| 1149 | builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue()))); |
| 1150 | } catch (NoMappingFoundException e) { |
| 1151 | log.warn(e.getMessage()); |
| 1152 | break; |
| 1153 | } |
| 1154 | break; |
| 1155 | case EXP_ODU_SIG_ID: |
| 1156 | OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(), |
| 1157 | match.get(MatchField.EXP_ODU_SIG_ID).getTslen(), |
| 1158 | match.get(MatchField.EXP_ODU_SIG_ID).getTsmap()); |
| 1159 | builder.add(matchOduSignalId(oduSignalId)); |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 1160 | break; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 1161 | case EXP_ODU_SIGTYPE: |
| 1162 | try { |
| 1163 | U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE); |
| 1164 | builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue()))); |
| 1165 | } catch (NoMappingFoundException e) { |
| 1166 | log.warn(e.getMessage()); |
| 1167 | break; |
| 1168 | } |
| 1169 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 1170 | case TUNNEL_ID: |
| 1171 | long tunnelId = match.get(MatchField.TUNNEL_ID).getValue(); |
| 1172 | builder.matchTunnelId(tunnelId); |
| 1173 | break; |
BitOhenry | b40129a | 2015-11-30 12:41:18 +0800 | [diff] [blame] | 1174 | case ARP_OP: |
| 1175 | int arpOp = match.get(MatchField.ARP_OP).getOpcode(); |
| 1176 | builder.matchArpOp(arpOp); |
| 1177 | break; |
BitOhenry | a331b18 | 2015-11-23 08:39:37 +0800 | [diff] [blame] | 1178 | case ARP_SHA: |
| 1179 | mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong()); |
| 1180 | builder.matchArpSha(mac); |
| 1181 | break; |
BitOhenry | 296b454 | 2015-11-24 08:41:58 +0800 | [diff] [blame] | 1182 | case ARP_SPA: |
| 1183 | ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt()); |
| 1184 | builder.matchArpSpa(ip); |
| 1185 | break; |
BitOhenry | 7643085 | 2015-11-20 19:04:49 +0800 | [diff] [blame] | 1186 | case ARP_THA: |
| 1187 | mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong()); |
| 1188 | builder.matchArpTha(mac); |
| 1189 | break; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 1190 | case ARP_TPA: |
| 1191 | ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt()); |
| 1192 | builder.matchArpTpa(ip); |
| 1193 | break; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1194 | case NSP: |
| 1195 | if (selectorInterpreter != null) { |
| 1196 | try { |
| 1197 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP); |
| 1198 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1199 | } catch (UnsupportedOperationException e) { |
| 1200 | log.debug(e.getMessage()); |
| 1201 | } |
| 1202 | } |
| 1203 | break; |
| 1204 | case NSI: |
| 1205 | if (selectorInterpreter != null) { |
| 1206 | try { |
| 1207 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI); |
| 1208 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1209 | } catch (UnsupportedOperationException e) { |
| 1210 | log.debug(e.getMessage()); |
| 1211 | } |
| 1212 | } |
| 1213 | break; |
| 1214 | case ENCAP_ETH_TYPE: |
| 1215 | if (selectorInterpreter != null) { |
| 1216 | try { |
| 1217 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE); |
| 1218 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1219 | } catch (UnsupportedOperationException e) { |
| 1220 | log.debug(e.getMessage()); |
| 1221 | } |
| 1222 | } |
| 1223 | break; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 1224 | case CONNTRACK_STATE: |
| 1225 | if (selectorInterpreter != null && |
| 1226 | selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) { |
| 1227 | try { |
| 1228 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE); |
| 1229 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1230 | } catch (UnsupportedOperationException e) { |
| 1231 | log.debug(e.getMessage()); |
| 1232 | } |
| 1233 | } |
| 1234 | break; |
| 1235 | case CONNTRACK_ZONE: |
| 1236 | if (selectorInterpreter != null && |
| 1237 | selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) { |
| 1238 | try { |
| 1239 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE); |
| 1240 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1241 | } catch (UnsupportedOperationException e) { |
| 1242 | log.debug(e.getMessage()); |
| 1243 | } |
| 1244 | } |
| 1245 | break; |
| 1246 | case CONNTRACK_MARK: |
| 1247 | if (selectorInterpreter != null && |
| 1248 | selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) { |
| 1249 | try { |
| 1250 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK); |
| 1251 | builder.extension(selectorInterpreter.mapOxm(oxm), deviceId); |
| 1252 | } catch (UnsupportedOperationException e) { |
| 1253 | log.debug(e.getMessage()); |
| 1254 | } |
| 1255 | } |
| 1256 | break; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 1257 | case OFDPA_OVID: |
| 1258 | if (selectorInterpreter != null && |
| 1259 | selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) { |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 1260 | if (isOF13OrLater(match)) { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 1261 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID); |
| 1262 | builder.extension(selectorInterpreter.mapOxm(oxm), |
| 1263 | deviceId); |
| 1264 | } else { |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | break; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 1269 | case OFDPA_MPLS_L2_PORT: |
| 1270 | if (selectorInterpreter != null && |
| 1271 | selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) { |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 1272 | if (isOF13OrLater(match)) { |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 1273 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT); |
| 1274 | builder.extension(selectorInterpreter.mapOxm(oxm), |
| 1275 | deviceId); |
| 1276 | } else { |
| 1277 | break; |
| 1278 | } |
| 1279 | } |
| 1280 | break; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 1281 | case OFDPA_ALLOW_VLAN_TRANSLATION: |
| 1282 | if (selectorInterpreter != null && |
| 1283 | selectorInterpreter.supported( |
| 1284 | ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) { |
| 1285 | if (isOF13OrLater(match)) { |
| 1286 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION); |
| 1287 | builder.extension(selectorInterpreter.mapOxm(oxm), |
| 1288 | deviceId); |
| 1289 | } else { |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | break; |
| 1294 | case OFDPA_ACTSET_OUTPUT: |
| 1295 | if (selectorInterpreter != null && |
| 1296 | selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) { |
| 1297 | if (isOF13OrLater(match)) { |
| 1298 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ACTSET_OUTPUT); |
| 1299 | builder.extension(selectorInterpreter.mapOxm(oxm), |
| 1300 | deviceId); |
| 1301 | } else { |
| 1302 | break; |
| 1303 | } |
| 1304 | } |
| 1305 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 1306 | case MPLS_TC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 1307 | default: |
| 1308 | log.warn("Match type {} not yet implemented.", field.id); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | return builder.build(); |
| 1312 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1313 | |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 1314 | /** |
| 1315 | * @param obj OpenFlow object to test |
| 1316 | * @return true if OFObject is OF_13 or later |
| 1317 | */ |
| 1318 | private static boolean isOF13OrLater(OFObject obj) { |
| 1319 | return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion; |
| 1320 | } |
| 1321 | |
Claudine Chiu | 20cbd45 | 2017-08-30 19:23:11 -0400 | [diff] [blame] | 1322 | /** |
| 1323 | * Retrieves the driver handler for the specified device. |
| 1324 | * |
| 1325 | * @param deviceId device identifier |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 1326 | * @param driverService service handle for the driver service |
Claudine Chiu | 20cbd45 | 2017-08-30 19:23:11 -0400 | [diff] [blame] | 1327 | * @return driver handler |
| 1328 | */ |
Rodrigo Duarte Sousa | e37d129 | 2017-08-29 17:01:24 -0300 | [diff] [blame] | 1329 | protected static DriverHandler getDriver(DeviceId deviceId, DriverService driverService) { |
Claudine Chiu | 20cbd45 | 2017-08-30 19:23:11 -0400 | [diff] [blame] | 1330 | Driver driver = driverService.getDriver(deviceId); |
| 1331 | DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1332 | return handler; |
| 1333 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 1334 | } |