Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.openflow.controller.impl; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ArrayListMultimap; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Multimap; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Modified; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Property; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Service; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 30 | import org.onosproject.core.CoreService; |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 31 | import org.onosproject.net.driver.DefaultDriverProviderService; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 32 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; |
| 34 | import org.onosproject.openflow.controller.Dpid; |
| 35 | import org.onosproject.openflow.controller.OpenFlowController; |
| 36 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
| 37 | import org.onosproject.openflow.controller.OpenFlowPacketContext; |
| 38 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 39 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
| 40 | import org.onosproject.openflow.controller.PacketListener; |
| 41 | import org.onosproject.openflow.controller.RoleState; |
| 42 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 43 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 44 | import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry; |
| 45 | import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 46 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
| 47 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 48 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 49 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
| 50 | import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.protocol.OFTableStatsEntry; |
| 52 | import org.projectfloodlight.openflow.protocol.OFTableStatsReply; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 53 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; |
| 54 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply; |
| 55 | import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry; |
| 56 | import org.projectfloodlight.openflow.protocol.OFGroupStatsReply; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 58 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
| 61 | import org.projectfloodlight.openflow.protocol.OFPortStatsReply; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 63 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 65 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 66 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 67 | import org.slf4j.Logger; |
| 68 | import org.slf4j.LoggerFactory; |
| 69 | |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 70 | import java.util.Collection; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 71 | import java.util.Collections; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 72 | import java.util.LinkedList; |
| 73 | import java.util.List; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 74 | import java.util.Set; |
| 75 | import java.util.concurrent.ConcurrentHashMap; |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame^] | 76 | import java.util.concurrent.ConcurrentMap; |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 77 | import java.util.concurrent.CopyOnWriteArraySet; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 78 | import java.util.concurrent.ExecutorService; |
| 79 | import java.util.concurrent.Executors; |
| 80 | import java.util.concurrent.locks.Lock; |
| 81 | import java.util.concurrent.locks.ReentrantLock; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 82 | import static org.onlab.util.Tools.groupedThreads; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 83 | |
| 84 | @Component(immediate = true) |
| 85 | @Service |
| 86 | public class OpenFlowControllerImpl implements OpenFlowController { |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 87 | private static final String APP_ID = "org.onosproject.openflow-base"; |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 88 | private static final String DEFAULT_OFPORT = "6633,6653"; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 89 | private static final int DEFAULT_WORKER_THREADS = 16; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 90 | |
| 91 | private static final Logger log = |
| 92 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); |
| 93 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 95 | protected CoreService coreService; |
| 96 | |
| 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 98 | protected DriverService driverService; |
| 99 | |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 100 | // References exists merely for sequencing purpose to assure drivers are loaded |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected DefaultDriverProviderService defaultDriverProviderService; |
| 103 | |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 105 | protected ComponentConfigService cfgService; |
| 106 | |
Brian O'Connor | e2a399e | 2015-09-22 15:32:50 -0700 | [diff] [blame] | 107 | @Property(name = "openflowPorts", value = DEFAULT_OFPORT, |
| 108 | label = "Port numbers (comma separated) used by OpenFlow protocol; default is 6633,6653") |
| 109 | private String openflowPorts = DEFAULT_OFPORT; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 110 | |
| 111 | @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS, |
| 112 | label = "Number of controller worker threads; default is 16") |
| 113 | private int workerThreads = DEFAULT_WORKER_THREADS; |
| 114 | |
Ray Milkey | 7ec0d1b | 2015-11-13 08:51:35 -0800 | [diff] [blame] | 115 | protected ExecutorService executorMsgs = |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 116 | Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d")); |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 117 | |
| 118 | private final ExecutorService executorBarrier = |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 119 | Executors.newFixedThreadPool(4, groupedThreads("onos/of", "event-barrier-%d")); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 120 | |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame^] | 121 | protected ConcurrentMap<Dpid, OpenFlowSwitch> connectedSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 122 | new ConcurrentHashMap<>(); |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame^] | 123 | protected ConcurrentMap<Dpid, OpenFlowSwitch> activeMasterSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 124 | new ConcurrentHashMap<>(); |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame^] | 125 | protected ConcurrentMap<Dpid, OpenFlowSwitch> activeEqualSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 126 | new ConcurrentHashMap<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 127 | |
| 128 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 129 | protected Set<OpenFlowSwitchListener> ofSwitchListener = new CopyOnWriteArraySet<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 130 | |
| 131 | protected Multimap<Integer, PacketListener> ofPacketListener = |
| 132 | ArrayListMultimap.create(); |
| 133 | |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 134 | protected Set<OpenFlowEventListener> ofEventListener = new CopyOnWriteArraySet<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 135 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 136 | protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats = |
| 137 | ArrayListMultimap.create(); |
| 138 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 139 | protected Multimap<Dpid, OFTableStatsEntry> fullTableStats = |
| 140 | ArrayListMultimap.create(); |
| 141 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 142 | protected Multimap<Dpid, OFGroupStatsEntry> fullGroupStats = |
| 143 | ArrayListMultimap.create(); |
| 144 | |
| 145 | protected Multimap<Dpid, OFGroupDescStatsEntry> fullGroupDescStats = |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 146 | ArrayListMultimap.create(); |
| 147 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 148 | protected Multimap<Dpid, OFPortStatsEntry> fullPortStats = |
| 149 | ArrayListMultimap.create(); |
| 150 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 151 | private final Controller ctrl = new Controller(); |
| 152 | |
| 153 | @Activate |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 154 | public void activate(ComponentContext context) { |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 155 | coreService.registerApplication(APP_ID, this::preDeactivate); |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 156 | cfgService.registerProperties(getClass()); |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 157 | ctrl.setConfigParams(context.getProperties()); |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 158 | ctrl.start(agent, driverService); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 161 | private void preDeactivate() { |
| 162 | // Close listening channel and all OF channels before deactivating |
| 163 | ctrl.stop(); |
| 164 | connectedSwitches.values().forEach(OpenFlowSwitch::disconnectSwitch); |
| 165 | } |
| 166 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 167 | @Deactivate |
| 168 | public void deactivate() { |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 169 | cfgService.unregisterProperties(getClass(), false); |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 170 | connectedSwitches.clear(); |
| 171 | activeMasterSwitches.clear(); |
| 172 | activeEqualSwitches.clear(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 175 | @Modified |
| 176 | public void modified(ComponentContext context) { |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 177 | ctrl.stop(); |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 178 | ctrl.setConfigParams(context.getProperties()); |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 179 | ctrl.start(agent, driverService); |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 180 | } |
| 181 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 182 | @Override |
| 183 | public Iterable<OpenFlowSwitch> getSwitches() { |
| 184 | return connectedSwitches.values(); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public Iterable<OpenFlowSwitch> getMasterSwitches() { |
| 189 | return activeMasterSwitches.values(); |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public Iterable<OpenFlowSwitch> getEqualSwitches() { |
| 194 | return activeEqualSwitches.values(); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public OpenFlowSwitch getSwitch(Dpid dpid) { |
| 199 | return connectedSwitches.get(dpid); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public OpenFlowSwitch getMasterSwitch(Dpid dpid) { |
| 204 | return activeMasterSwitches.get(dpid); |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | public OpenFlowSwitch getEqualSwitch(Dpid dpid) { |
| 209 | return activeEqualSwitches.get(dpid); |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void addListener(OpenFlowSwitchListener listener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 214 | if (!ofSwitchListener.contains(listener)) { |
| 215 | this.ofSwitchListener.add(listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void removeListener(OpenFlowSwitchListener listener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 221 | this.ofSwitchListener.remove(listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public void addPacketListener(int priority, PacketListener listener) { |
| 226 | ofPacketListener.put(priority, listener); |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void removePacketListener(PacketListener listener) { |
| 231 | ofPacketListener.values().remove(listener); |
| 232 | } |
| 233 | |
| 234 | @Override |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 235 | public void addEventListener(OpenFlowEventListener listener) { |
| 236 | ofEventListener.add(listener); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void removeEventListener(OpenFlowEventListener listener) { |
| 241 | ofEventListener.remove(listener); |
| 242 | } |
| 243 | |
| 244 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 245 | public void write(Dpid dpid, OFMessage msg) { |
| 246 | this.getSwitch(dpid).sendMsg(msg); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void processPacket(Dpid dpid, OFMessage msg) { |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 251 | Collection<OFFlowStatsEntry> flowStats; |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 252 | Collection<OFTableStatsEntry> tableStats; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 253 | Collection<OFGroupStatsEntry> groupStats; |
| 254 | Collection<OFGroupDescStatsEntry> groupDescStats; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 255 | Collection<OFPortStatsEntry> portStats; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 256 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 257 | switch (msg.getType()) { |
| 258 | case PORT_STATUS: |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 259 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 260 | l.portChanged(dpid, (OFPortStatus) msg); |
| 261 | } |
| 262 | break; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 263 | case FEATURES_REPLY: |
| 264 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 265 | l.switchChanged(dpid); |
| 266 | } |
| 267 | break; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 268 | case PACKET_IN: |
| 269 | OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext |
| 270 | .packetContextFromPacketIn(this.getSwitch(dpid), |
| 271 | (OFPacketIn) msg); |
| 272 | for (PacketListener p : ofPacketListener.values()) { |
| 273 | p.handlePacket(pktCtx); |
| 274 | } |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 275 | executorMsgs.submit(new OFMessageHandler(dpid, msg)); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 276 | break; |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 277 | // TODO: Consider using separate threadpool for sensitive messages. |
| 278 | // ie. Back to back error could cause us to starve. |
| 279 | case FLOW_REMOVED: |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 280 | executorMsgs.submit(new OFMessageHandler(dpid, msg)); |
| 281 | break; |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 282 | case ERROR: |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame^] | 283 | log.debug("Received error message from {}: {}", dpid, msg); |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 284 | executorMsgs.submit(new OFMessageHandler(dpid, msg)); |
| 285 | break; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 286 | case STATS_REPLY: |
| 287 | OFStatsReply reply = (OFStatsReply) msg; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 288 | switch (reply.getStatsType()) { |
| 289 | case PORT_DESC: |
| 290 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 291 | l.switchChanged(dpid); |
| 292 | } |
| 293 | break; |
| 294 | case FLOW: |
| 295 | flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply); |
| 296 | if (flowStats != null) { |
| 297 | OFFlowStatsReply.Builder rep = |
| 298 | OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); |
| 299 | rep.setEntries(Lists.newLinkedList(flowStats)); |
ssyoon90 | 30fbcd9 | 2015-08-17 10:42:07 +0900 | [diff] [blame] | 300 | rep.setXid(reply.getXid()); |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 301 | executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); |
| 302 | } |
| 303 | break; |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 304 | case TABLE: |
| 305 | tableStats = publishTableStats(dpid, (OFTableStatsReply) reply); |
| 306 | if (tableStats != null) { |
| 307 | OFTableStatsReply.Builder rep = |
| 308 | OFFactories.getFactory(msg.getVersion()).buildTableStatsReply(); |
| 309 | rep.setEntries(Lists.newLinkedList(tableStats)); |
| 310 | executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); |
| 311 | } |
| 312 | break; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 313 | case GROUP: |
| 314 | groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply); |
| 315 | if (groupStats != null) { |
| 316 | OFGroupStatsReply.Builder rep = |
| 317 | OFFactories.getFactory(msg.getVersion()).buildGroupStatsReply(); |
| 318 | rep.setEntries(Lists.newLinkedList(groupStats)); |
| 319 | rep.setXid(reply.getXid()); |
| 320 | executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); |
| 321 | } |
| 322 | break; |
| 323 | case GROUP_DESC: |
| 324 | groupDescStats = publishGroupDescStats(dpid, |
| 325 | (OFGroupDescStatsReply) reply); |
| 326 | if (groupDescStats != null) { |
| 327 | OFGroupDescStatsReply.Builder rep = |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 328 | OFFactories.getFactory(msg.getVersion()).buildGroupDescStatsReply(); |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 329 | rep.setEntries(Lists.newLinkedList(groupDescStats)); |
| 330 | rep.setXid(reply.getXid()); |
| 331 | executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); |
| 332 | } |
| 333 | break; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 334 | case PORT: |
| 335 | executorMsgs.submit(new OFMessageHandler(dpid, reply)); |
| 336 | break; |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 337 | case METER: |
| 338 | executorMsgs.submit(new OFMessageHandler(dpid, reply)); |
| 339 | break; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 340 | case EXPERIMENTER: |
| 341 | if (reply instanceof OFCalientFlowStatsReply) { |
| 342 | // Convert Calient flow statistics to regular flow stats |
| 343 | // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API |
| 344 | OFFlowStatsReply.Builder fsr = getSwitch(dpid).factory().buildFlowStatsReply(); |
| 345 | List<OFFlowStatsEntry> entries = new LinkedList<>(); |
| 346 | for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) { |
| 347 | |
| 348 | // Single instruction, i.e., output to port |
| 349 | OFActionOutput action = OFFactories |
| 350 | .getFactory(msg.getVersion()) |
| 351 | .actions() |
| 352 | .buildOutput() |
| 353 | .setPort(entry.getOutPort()) |
| 354 | .build(); |
| 355 | OFInstruction instruction = OFFactories |
| 356 | .getFactory(msg.getVersion()) |
| 357 | .instructions() |
| 358 | .applyActions(Collections.singletonList(action)); |
| 359 | OFFlowStatsEntry fs = getSwitch(dpid).factory().buildFlowStatsEntry() |
| 360 | .setMatch(entry.getMatch()) |
| 361 | .setTableId(entry.getTableId()) |
| 362 | .setDurationSec(entry.getDurationSec()) |
| 363 | .setDurationNsec(entry.getDurationNsec()) |
| 364 | .setPriority(entry.getPriority()) |
| 365 | .setIdleTimeout(entry.getIdleTimeout()) |
| 366 | .setHardTimeout(entry.getHardTimeout()) |
| 367 | .setFlags(entry.getFlags()) |
| 368 | .setCookie(entry.getCookie()) |
| 369 | .setInstructions(Collections.singletonList(instruction)) |
| 370 | .build(); |
| 371 | entries.add(fs); |
| 372 | } |
| 373 | fsr.setEntries(entries); |
| 374 | |
| 375 | flowStats = publishFlowStats(dpid, fsr.build()); |
| 376 | if (flowStats != null) { |
| 377 | OFFlowStatsReply.Builder rep = |
| 378 | OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); |
| 379 | rep.setEntries(Lists.newLinkedList(flowStats)); |
| 380 | executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); |
| 381 | } |
| 382 | } else { |
Michael Bunimovich | 1b45e1f | 2015-08-27 07:49:25 -0400 | [diff] [blame] | 383 | executorMsgs.submit(new OFMessageHandler(dpid, reply)); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 384 | } |
| 385 | break; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 386 | default: |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 387 | log.warn("Discarding unknown stats reply type {}", reply.getStatsType()); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 388 | break; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 389 | } |
| 390 | break; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 391 | case BARRIER_REPLY: |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 392 | executorBarrier.submit(new OFMessageHandler(dpid, msg)); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 393 | break; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 394 | case EXPERIMENTER: |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 395 | long experimenter = ((OFExperimenter) msg).getExperimenter(); |
| 396 | if (experimenter == 0x748771) { |
| 397 | // LINC-OE port stats |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 398 | OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; |
| 399 | OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus(); |
| 400 | OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc(); |
| 401 | portDesc.setPortNo(circuitPortStatus.getPortNo()) |
| 402 | .setHwAddr(circuitPortStatus.getHwAddr()) |
| 403 | .setName(circuitPortStatus.getName()) |
| 404 | .setConfig(circuitPortStatus.getConfig()) |
| 405 | .setState(circuitPortStatus.getState()); |
| 406 | portStatus.setReason(circuitPortStatus.getReason()).setDesc(portDesc.build()); |
| 407 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 408 | l.portChanged(dpid, portStatus.build()); |
| 409 | } |
| 410 | } else { |
| 411 | log.warn("Handling experimenter type {} not yet implemented", |
| 412 | ((OFExperimenter) msg).getExperimenter(), msg); |
| 413 | } |
| 414 | break; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 415 | default: |
| 416 | log.warn("Handling message type {} not yet implemented {}", |
| 417 | msg.getType(), msg); |
| 418 | } |
| 419 | } |
| 420 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 421 | private synchronized Collection<OFFlowStatsEntry> publishFlowStats(Dpid dpid, |
| 422 | OFFlowStatsReply reply) { |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 423 | //TODO: Get rid of synchronized |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 424 | fullFlowStats.putAll(dpid, reply.getEntries()); |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 425 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 426 | return fullFlowStats.removeAll(dpid); |
| 427 | } |
| 428 | return null; |
| 429 | } |
| 430 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 431 | private synchronized Collection<OFTableStatsEntry> publishTableStats(Dpid dpid, |
| 432 | OFTableStatsReply reply) { |
| 433 | //TODO: Get rid of synchronized |
| 434 | fullTableStats.putAll(dpid, reply.getEntries()); |
| 435 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 436 | return fullTableStats.removeAll(dpid); |
| 437 | } |
| 438 | return null; |
| 439 | } |
| 440 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 441 | private synchronized Collection<OFGroupStatsEntry> publishGroupStats(Dpid dpid, |
| 442 | OFGroupStatsReply reply) { |
| 443 | //TODO: Get rid of synchronized |
| 444 | fullGroupStats.putAll(dpid, reply.getEntries()); |
| 445 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 446 | return fullGroupStats.removeAll(dpid); |
| 447 | } |
| 448 | return null; |
| 449 | } |
| 450 | |
| 451 | private synchronized Collection<OFGroupDescStatsEntry> publishGroupDescStats(Dpid dpid, |
| 452 | OFGroupDescStatsReply reply) { |
| 453 | //TODO: Get rid of synchronized |
| 454 | fullGroupDescStats.putAll(dpid, reply.getEntries()); |
| 455 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 456 | return fullGroupDescStats.removeAll(dpid); |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 457 | } |
| 458 | return null; |
| 459 | } |
| 460 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 461 | private synchronized Collection<OFPortStatsEntry> publishPortStats(Dpid dpid, |
| 462 | OFPortStatsReply reply) { |
| 463 | fullPortStats.putAll(dpid, reply.getEntries()); |
| 464 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 465 | return fullPortStats.removeAll(dpid); |
| 466 | } |
| 467 | return null; |
| 468 | } |
| 469 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 470 | @Override |
| 471 | public void setRole(Dpid dpid, RoleState role) { |
Yuta HIGUCHI | 79cbd1c | 2014-10-02 16:57:57 -0700 | [diff] [blame] | 472 | final OpenFlowSwitch sw = getSwitch(dpid); |
| 473 | if (sw == null) { |
| 474 | log.debug("Switch not connected. Ignoring setRole({}, {})", dpid, role); |
| 475 | return; |
| 476 | } |
| 477 | sw.setRole(role); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Implementation of an OpenFlow Agent which is responsible for |
| 482 | * keeping track of connected switches and the state in which |
| 483 | * they are. |
| 484 | */ |
| 485 | public class OpenFlowSwitchAgent implements OpenFlowAgent { |
| 486 | |
| 487 | private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); |
| 488 | private final Lock switchLock = new ReentrantLock(); |
| 489 | |
| 490 | @Override |
| 491 | public boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw) { |
alshabib | 9eab22f | 2014-10-20 17:17:31 -0700 | [diff] [blame] | 492 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 493 | if (connectedSwitches.get(dpid) != null) { |
| 494 | log.error("Trying to add connectedSwitch but found a previous " |
| 495 | + "value for dpid: {}", dpid); |
| 496 | return false; |
| 497 | } else { |
Yuta HIGUCHI | eb3f30b | 2014-10-22 11:34:49 -0700 | [diff] [blame] | 498 | log.info("Added switch {}", dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 499 | connectedSwitches.put(dpid, sw); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 500 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 501 | l.switchAdded(dpid); |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public boolean validActivation(Dpid dpid) { |
| 509 | if (connectedSwitches.get(dpid) == null) { |
| 510 | log.error("Trying to activate switch but is not in " |
| 511 | + "connected switches: dpid {}. Aborting ..", |
| 512 | dpid); |
| 513 | return false; |
| 514 | } |
| 515 | if (activeMasterSwitches.get(dpid) != null || |
| 516 | activeEqualSwitches.get(dpid) != null) { |
| 517 | log.error("Trying to activate switch but it is already " |
| 518 | + "activated: dpid {}. Found in activeMaster: {} " |
Ray Milkey | 6bc43c2 | 2015-11-06 13:22:38 -0800 | [diff] [blame] | 519 | + "Found in activeEqual: {}. Aborting ..", |
| 520 | dpid, |
| 521 | (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', |
| 522 | (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 523 | return false; |
| 524 | } |
| 525 | return true; |
| 526 | } |
| 527 | |
| 528 | |
| 529 | @Override |
| 530 | public boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw) { |
| 531 | switchLock.lock(); |
| 532 | try { |
| 533 | if (!validActivation(dpid)) { |
| 534 | return false; |
| 535 | } |
| 536 | activeMasterSwitches.put(dpid, sw); |
| 537 | return true; |
| 538 | } finally { |
| 539 | switchLock.unlock(); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw) { |
| 545 | switchLock.lock(); |
| 546 | try { |
| 547 | if (!validActivation(dpid)) { |
| 548 | return false; |
| 549 | } |
| 550 | activeEqualSwitches.put(dpid, sw); |
| 551 | log.info("Added Activated EQUAL Switch {}", dpid); |
| 552 | return true; |
| 553 | } finally { |
| 554 | switchLock.unlock(); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public void transitionToMasterSwitch(Dpid dpid) { |
| 560 | switchLock.lock(); |
| 561 | try { |
| 562 | if (activeMasterSwitches.containsKey(dpid)) { |
| 563 | return; |
| 564 | } |
| 565 | OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); |
| 566 | if (sw == null) { |
| 567 | sw = getSwitch(dpid); |
| 568 | if (sw == null) { |
| 569 | log.error("Transition to master called on sw {}, but switch " |
| 570 | + "was not found in controller-cache", dpid); |
| 571 | return; |
| 572 | } |
| 573 | } |
| 574 | log.info("Transitioned switch {} to MASTER", dpid); |
| 575 | activeMasterSwitches.put(dpid, sw); |
| 576 | } finally { |
| 577 | switchLock.unlock(); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | |
| 582 | @Override |
| 583 | public void transitionToEqualSwitch(Dpid dpid) { |
| 584 | switchLock.lock(); |
| 585 | try { |
| 586 | if (activeEqualSwitches.containsKey(dpid)) { |
| 587 | return; |
| 588 | } |
| 589 | OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); |
| 590 | if (sw == null) { |
| 591 | sw = getSwitch(dpid); |
| 592 | if (sw == null) { |
| 593 | log.error("Transition to equal called on sw {}, but switch " |
| 594 | + "was not found in controller-cache", dpid); |
| 595 | return; |
| 596 | } |
| 597 | } |
| 598 | log.info("Transitioned switch {} to EQUAL", dpid); |
| 599 | activeEqualSwitches.put(dpid, sw); |
| 600 | } finally { |
| 601 | switchLock.unlock(); |
| 602 | } |
| 603 | |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void removeConnectedSwitch(Dpid dpid) { |
| 608 | connectedSwitches.remove(dpid); |
| 609 | OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); |
| 610 | if (sw == null) { |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 611 | log.debug("sw was null for {}", dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 612 | sw = activeEqualSwitches.remove(dpid); |
| 613 | } |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 614 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 615 | l.switchRemoved(dpid); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public void processMessage(Dpid dpid, OFMessage m) { |
| 621 | processPacket(dpid, m); |
| 622 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 623 | |
| 624 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 625 | public void returnRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 626 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 627 | l.receivedRoleReply(dpid, requested, response); |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 632 | /** |
| 633 | * OpenFlow message handler for incoming control messages. |
| 634 | */ |
Ray Milkey | 7ec0d1b | 2015-11-13 08:51:35 -0800 | [diff] [blame] | 635 | protected final class OFMessageHandler implements Runnable { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 636 | |
Ray Milkey | 7ec0d1b | 2015-11-13 08:51:35 -0800 | [diff] [blame] | 637 | protected final OFMessage msg; |
| 638 | protected final Dpid dpid; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 639 | |
| 640 | public OFMessageHandler(Dpid dpid, OFMessage msg) { |
| 641 | this.msg = msg; |
| 642 | this.dpid = dpid; |
| 643 | } |
| 644 | |
| 645 | @Override |
| 646 | public void run() { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 647 | for (OpenFlowEventListener listener : ofEventListener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 648 | listener.handleMessage(dpid, msg); |
| 649 | } |
| 650 | } |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 651 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 652 | } |