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