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