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 2015-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 | */ |
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; |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Multimap; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 21 | import org.onosproject.cfg.ComponentConfigService; |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 22 | import org.onosproject.core.CoreService; |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.config.ConfigFactory; |
Brian O'Connor | 1bd4a9f | 2018-05-10 22:40:41 -0700 | [diff] [blame] | 25 | import org.onosproject.net.config.NetworkConfigEvent; |
| 26 | import org.onosproject.net.config.NetworkConfigListener; |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 27 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 28 | import org.onosproject.net.config.basics.SubjectFactories; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 29 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 30 | import org.onosproject.openflow.config.OpenFlowDeviceConfig; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; |
| 32 | import org.onosproject.openflow.controller.Dpid; |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 33 | import org.onosproject.openflow.controller.OpenFlowClassifierListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.openflow.controller.OpenFlowController; |
| 35 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 36 | import org.onosproject.openflow.controller.OpenFlowMessageListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.openflow.controller.OpenFlowPacketContext; |
| 38 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 39 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 40 | import org.onosproject.openflow.controller.OpenFlowListener; |
| 41 | import org.onosproject.openflow.controller.OpenFlowService; |
| 42 | import org.onosproject.openflow.controller.OpenFlowEvent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.openflow.controller.PacketListener; |
| 44 | import org.onosproject.openflow.controller.RoleState; |
| 45 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 46 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | import org.osgi.service.component.annotations.Activate; |
| 48 | import org.osgi.service.component.annotations.Component; |
| 49 | import org.osgi.service.component.annotations.Deactivate; |
| 50 | import org.osgi.service.component.annotations.Modified; |
| 51 | import org.osgi.service.component.annotations.Reference; |
| 52 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 53 | import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry; |
| 54 | import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
| 56 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.OFFactories; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry; |
| 59 | import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
| 61 | import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; |
| 63 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply; |
| 64 | import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry; |
| 65 | import org.projectfloodlight.openflow.protocol.OFGroupStatsReply; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 66 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 67 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 68 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 70 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 71 | import org.projectfloodlight.openflow.protocol.OFQueueStatsEntry; |
| 72 | import org.projectfloodlight.openflow.protocol.OFQueueStatsReply; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 73 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 74 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
Jian Li | 2266bff | 2016-04-21 11:01:25 -0700 | [diff] [blame] | 75 | import org.projectfloodlight.openflow.protocol.OFTableStatsEntry; |
| 76 | import org.projectfloodlight.openflow.protocol.OFTableStatsReply; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 78 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 79 | import org.slf4j.Logger; |
| 80 | import org.slf4j.LoggerFactory; |
| 81 | |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 82 | import java.util.ArrayList; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 83 | import java.util.Collection; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 84 | import java.util.Collections; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 85 | import java.util.List; |
Brian O'Connor | 1bd4a9f | 2018-05-10 22:40:41 -0700 | [diff] [blame] | 86 | import java.util.Objects; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 87 | import java.util.Set; |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 88 | import java.util.concurrent.CompletableFuture; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 89 | import java.util.concurrent.ConcurrentHashMap; |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 90 | import java.util.concurrent.ConcurrentMap; |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 91 | import java.util.concurrent.CopyOnWriteArraySet; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 92 | import java.util.concurrent.ExecutorService; |
| 93 | import java.util.concurrent.Executors; |
| 94 | import java.util.concurrent.locks.Lock; |
| 95 | import java.util.concurrent.locks.ReentrantLock; |
Jian Li | 2266bff | 2016-04-21 11:01:25 -0700 | [diff] [blame] | 96 | |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 97 | import static org.onlab.util.Tools.groupedThreads; |
Ray Milkey | 309f9a0 | 2018-10-12 14:09:37 -0700 | [diff] [blame] | 98 | import static org.onosproject.openflow.controller.impl.OsgiPropertyConstants.*; |
Ozge AYAZ | 60aded2 | 2017-06-20 08:35:30 +0000 | [diff] [blame] | 99 | |
Ray Milkey | 309f9a0 | 2018-10-12 14:09:37 -0700 | [diff] [blame] | 100 | @Component( |
| 101 | immediate = true, |
| 102 | service = OpenFlowController.class, |
| 103 | property = { |
| 104 | OFPORTS + "=" + OFPORTS_DEFAULT, |
Ray Milkey | 2d7bca1 | 2018-10-17 14:51:52 -0700 | [diff] [blame] | 105 | WORKER_THREADS + ":Integer=" + WORKER_THREADS_DEFAULT, |
Ray Milkey | 309f9a0 | 2018-10-12 14:09:37 -0700 | [diff] [blame] | 106 | TLS_MODE + "=" + TLS_MODE_DEFAULT, |
| 107 | KEY_STORE + "=" + KEY_STORE_DEFAULT, |
| 108 | KEY_STORE_PASSWORD + "=" + KEY_STORE_PASSWORD_DEFAULT, |
| 109 | TRUST_STORE + "=" + TRUST_STORE_DEFAULT, |
| 110 | TRUST_STORE_PASSWORD + "=" + TRUST_STORE_PASSWORD_DEFAULT, |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 111 | DEFAULT_QUEUE_SIZE + ":Integer=" + DEFAULT_QUEUE_SIZE_DEFAULT, |
| 112 | DEBAULT_BULK_SIZE + ":Integer=" + BULK_SIZE_DEFAULT, |
| 113 | QUEUE_SIZE_N0 + ":Integer=" + QUEUE_SIZE_N0_DEFAULT, |
| 114 | BULK_SIZE_N0 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 115 | QUEUE_SIZE_N1 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 116 | BULK_SIZE_N1 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 117 | QUEUE_SIZE_N2 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 118 | BULK_SIZE_N2 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 119 | QUEUE_SIZE_N3 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 120 | BULK_SIZE_N3 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 121 | QUEUE_SIZE_N4 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 122 | BULK_SIZE_N4 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 123 | QUEUE_SIZE_N5 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 124 | BULK_SIZE_N5 + ":Integer=" + BULK_SIZE_DEFAULT, |
| 125 | QUEUE_SIZE_N6 + ":Integer=" + QUEUE_SIZE_DEFAULT, |
| 126 | BULK_SIZE_N6 + ":Integer=" + BULK_SIZE_DEFAULT, |
Ray Milkey | 309f9a0 | 2018-10-12 14:09:37 -0700 | [diff] [blame] | 127 | } |
| 128 | ) |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 129 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 130 | public class OpenFlowControllerImpl implements OpenFlowController { |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 131 | private static final String APP_ID = "org.onosproject.openflow-base"; |
Andrea Campanella | 86e0c56 | 2017-11-23 16:38:24 +0100 | [diff] [blame] | 132 | protected static final String SCHEME = "of"; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 133 | |
| 134 | private static final Logger log = |
| 135 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); |
| 136 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 138 | protected CoreService coreService; |
| 139 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 141 | protected DriverService driverService; |
| 142 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 144 | protected ComponentConfigService cfgService; |
| 145 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 147 | protected NetworkConfigRegistry netCfgService; |
| 148 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 149 | /** Port numbers (comma separated) used by OpenFlow protocol; default is 6633,6653. */ |
Ray Milkey | bd508ed | 2019-03-19 14:22:02 -0700 | [diff] [blame] | 150 | private String openflowPorts = OFPORTS_DEFAULT; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 151 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 152 | /** Number of controller worker threads. */ |
| 153 | private int workerThreads = WORKER_THREADS_DEFAULT; |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 154 | |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 155 | /** TLS mode for OpenFlow channel; options are: disabled [default], enabled, strict. */ |
Ray Milkey | bd508ed | 2019-03-19 14:22:02 -0700 | [diff] [blame] | 156 | private String tlsMode; |
Brian O'Connor | f7215b8 | 2018-05-10 19:12:44 -0700 | [diff] [blame] | 157 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 158 | /** File path to key store for TLS connections. */ |
| 159 | private String keyStore; |
Brian O'Connor | f7215b8 | 2018-05-10 19:12:44 -0700 | [diff] [blame] | 160 | |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 161 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 162 | protected OpenFlowService openFlowManager; |
| 163 | |
| 164 | private final OpenFlowListener openFlowListener = new InternalOpenFlowListener(); |
| 165 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 166 | /** Key store password. */ |
| 167 | private String keyStorePassword; |
Brian O'Connor | f7215b8 | 2018-05-10 19:12:44 -0700 | [diff] [blame] | 168 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 169 | /** File path to trust store for TLS connections. */ |
| 170 | private String trustStore; |
Brian O'Connor | f7215b8 | 2018-05-10 19:12:44 -0700 | [diff] [blame] | 171 | |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 172 | /** Trust store password. */ |
| 173 | private String trustStorePassword; |
Brian O'Connor | f7215b8 | 2018-05-10 19:12:44 -0700 | [diff] [blame] | 174 | |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 175 | /** Size of deafult queue. */ |
| 176 | private int defaultQueueSize = DEFAULT_QUEUE_SIZE_DEFAULT; |
| 177 | |
| 178 | /** Size of deafult bulk. */ |
| 179 | private int defaultBulkSize = BULK_SIZE_DEFAULT; |
| 180 | |
| 181 | /** Size of queue N0. */ |
| 182 | private int queueSizeN0 = QUEUE_SIZE_N0_DEFAULT; |
| 183 | |
| 184 | /** Size of bulk N0. */ |
| 185 | private int bulkSizeN0 = BULK_SIZE_DEFAULT; |
| 186 | |
| 187 | /** Size of queue N1. */ |
| 188 | private int queueSizeN1 = QUEUE_SIZE_DEFAULT; |
| 189 | |
| 190 | /** Size of bulk N1. */ |
| 191 | private int bulkSizeN1 = BULK_SIZE_DEFAULT; |
| 192 | |
| 193 | /** Size of queue N2. */ |
| 194 | private int queueSizeN2 = QUEUE_SIZE_DEFAULT; |
| 195 | |
| 196 | /** Size of bulk N2. */ |
| 197 | private int bulkSizeN2 = BULK_SIZE_DEFAULT; |
| 198 | |
| 199 | /** Size of queue N3. */ |
| 200 | private int queueSizeN3 = QUEUE_SIZE_DEFAULT; |
| 201 | |
| 202 | /** Size of bulk N3. */ |
| 203 | private int bulkSizeN3 = BULK_SIZE_DEFAULT; |
| 204 | |
| 205 | /** Size of queue N4. */ |
| 206 | private int queueSizeN4 = QUEUE_SIZE_DEFAULT; |
| 207 | |
| 208 | /** Size of bulk N4. */ |
| 209 | private int bulkSizeN4 = BULK_SIZE_DEFAULT; |
| 210 | |
| 211 | /** Size of queue N5. */ |
| 212 | private int queueSizeN5 = QUEUE_SIZE_DEFAULT; |
| 213 | |
| 214 | /** Size of bulk N5. */ |
| 215 | private int bulkSizeN5 = BULK_SIZE_DEFAULT; |
| 216 | |
| 217 | /** Size of queue N6. */ |
| 218 | private int queueSizeN6 = QUEUE_SIZE_DEFAULT; |
| 219 | |
| 220 | /** Size of bulk N6. */ |
| 221 | private int bulkSizeN6 = BULK_SIZE_DEFAULT; |
| 222 | |
Ray Milkey | 7ec0d1b | 2015-11-13 08:51:35 -0800 | [diff] [blame] | 223 | protected ExecutorService executorMsgs = |
Andrea Campanella | dda9356 | 2016-03-02 11:08:12 -0800 | [diff] [blame] | 224 | Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d", log)); |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 225 | |
| 226 | private final ExecutorService executorBarrier = |
Andrea Campanella | dda9356 | 2016-03-02 11:08:12 -0800 | [diff] [blame] | 227 | Executors.newFixedThreadPool(4, groupedThreads("onos/of", "event-barrier-%d", log)); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 228 | |
Prince Pereira | e779803 | 2016-07-08 16:31:58 +0530 | [diff] [blame] | 229 | //Separate executor thread for handling error messages and barrier replies for same failed |
| 230 | // transactions to avoid context switching of thread |
| 231 | protected ExecutorService executorErrorMsgs = |
| 232 | Executors.newSingleThreadExecutor(groupedThreads("onos/of", "event-error-msg-%d", log)); |
| 233 | |
| 234 | //concurrent hashmap to track failed transactions |
| 235 | protected ConcurrentMap<Long, Boolean> errorMsgs = |
| 236 | new ConcurrentHashMap<>(); |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 237 | protected ConcurrentMap<Dpid, OpenFlowSwitch> connectedSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 238 | new ConcurrentHashMap<>(); |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 239 | protected ConcurrentMap<Dpid, OpenFlowSwitch> activeMasterSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 240 | new ConcurrentHashMap<>(); |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 241 | protected ConcurrentMap<Dpid, OpenFlowSwitch> activeEqualSwitches = |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 242 | new ConcurrentHashMap<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 243 | |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 244 | // Key: dpid, value: map with key: long (XID), value: completable future |
| 245 | protected ConcurrentMap<Dpid, ConcurrentMap<Long, CompletableFuture<OFMessage>>> responses = |
| 246 | new ConcurrentHashMap<>(); |
| 247 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 248 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 249 | protected Set<OpenFlowSwitchListener> ofSwitchListener = new CopyOnWriteArraySet<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 250 | |
| 251 | protected Multimap<Integer, PacketListener> ofPacketListener = |
| 252 | ArrayListMultimap.create(); |
| 253 | |
Jonathan Hart | 6d44d19 | 2015-05-11 18:01:19 -0700 | [diff] [blame] | 254 | protected Set<OpenFlowEventListener> ofEventListener = new CopyOnWriteArraySet<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 255 | |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 256 | protected Set<OpenFlowClassifierListener> ofClassifierListener = new CopyOnWriteArraySet<>(); |
| 257 | |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 258 | protected Set<OpenFlowMessageListener> ofMessageListener = new CopyOnWriteArraySet<>(); |
Jian Li | 28247b5 | 2016-01-07 17:24:15 -0800 | [diff] [blame] | 259 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 260 | protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats = |
| 261 | ArrayListMultimap.create(); |
| 262 | |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 263 | protected Multimap<Dpid, OFFlowLightweightStatsEntry> fullFlowLightweightStats = |
| 264 | ArrayListMultimap.create(); |
| 265 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 266 | protected Multimap<Dpid, OFTableStatsEntry> fullTableStats = |
| 267 | ArrayListMultimap.create(); |
| 268 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 269 | protected Multimap<Dpid, OFGroupStatsEntry> fullGroupStats = |
| 270 | ArrayListMultimap.create(); |
| 271 | |
| 272 | protected Multimap<Dpid, OFGroupDescStatsEntry> fullGroupDescStats = |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 273 | ArrayListMultimap.create(); |
| 274 | |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 275 | // deprecated in 1.11.0, no longer referenced from anywhere |
| 276 | @Deprecated |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 277 | protected Multimap<Dpid, OFPortStatsEntry> fullPortStats = |
| 278 | ArrayListMultimap.create(); |
| 279 | |
Ozge AYAZ | 60aded2 | 2017-06-20 08:35:30 +0000 | [diff] [blame] | 280 | protected Multimap<Dpid, OFQueueStatsEntry> fullQueueStats = |
| 281 | ArrayListMultimap.create(); |
| 282 | |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 283 | protected final ConfigFactory factory = |
| 284 | new ConfigFactory<DeviceId, OpenFlowDeviceConfig>( |
| 285 | SubjectFactories.DEVICE_SUBJECT_FACTORY, |
| 286 | OpenFlowDeviceConfig.class, OpenFlowDeviceConfig.CONFIG_KEY) { |
| 287 | @Override |
| 288 | public OpenFlowDeviceConfig createConfig() { |
| 289 | return new OpenFlowDeviceConfig(); |
| 290 | } |
| 291 | }; |
| 292 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 293 | private final Controller ctrl = new Controller(); |
| 294 | |
Brian O'Connor | 1bd4a9f | 2018-05-10 22:40:41 -0700 | [diff] [blame] | 295 | private final NetworkConfigListener netCfgListener = new NetworkConfigListener() { |
| 296 | @Override |
| 297 | public boolean isRelevant(NetworkConfigEvent event) { |
| 298 | return OpenFlowDeviceConfig.class.equals(event.configClass()); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void event(NetworkConfigEvent event) { |
| 303 | // We only receive NetworkConfigEvents |
| 304 | OpenFlowDeviceConfig prevConfig = null; |
| 305 | if (event.prevConfig().isPresent()) { |
| 306 | prevConfig = (OpenFlowDeviceConfig) event.prevConfig().get(); |
| 307 | } |
| 308 | |
| 309 | OpenFlowDeviceConfig newConfig = null; |
| 310 | if (event.config().isPresent()) { |
| 311 | newConfig = (OpenFlowDeviceConfig) event.config().get(); |
| 312 | } |
| 313 | |
| 314 | boolean closeConnection = false; |
| 315 | if (prevConfig != null && newConfig != null) { |
| 316 | if (!Objects.equals(prevConfig.keyAlias(), newConfig.keyAlias())) { |
| 317 | closeConnection = true; |
| 318 | } |
| 319 | } else if (prevConfig != null) { |
| 320 | // config was removed |
| 321 | closeConnection = true; |
| 322 | } |
| 323 | if (closeConnection) { |
| 324 | if (event.subject() instanceof DeviceId) { |
| 325 | DeviceId deviceId = (DeviceId) event.subject(); |
| 326 | Dpid dpid = Dpid.dpid(deviceId.uri()); |
| 327 | OpenFlowSwitch sw = getSwitch(dpid); |
| 328 | if (sw != null && ctrl.tlsParams.mode == Controller.TlsMode.STRICT) { |
| 329 | sw.disconnectSwitch(); |
| 330 | log.info("Disconnecting switch {} because key has been updated or removed", dpid); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | }; |
| 336 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 337 | @Activate |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 338 | public void activate(ComponentContext context) { |
Andrea Campanella | 3556f36 | 2016-04-28 15:18:10 -0700 | [diff] [blame] | 339 | coreService.registerApplication(APP_ID, this::cleanup); |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 340 | cfgService.registerProperties(getClass()); |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 341 | netCfgService.registerConfigFactory(factory); |
Brian O'Connor | 1bd4a9f | 2018-05-10 22:40:41 -0700 | [diff] [blame] | 342 | netCfgService.addListener(netCfgListener); |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 343 | ctrl.setConfigParams(context.getProperties()); |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 344 | ctrl.start(agent, driverService, netCfgService); |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 345 | openFlowManager.addListener(openFlowListener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Andrea Campanella | 3556f36 | 2016-04-28 15:18:10 -0700 | [diff] [blame] | 348 | private void cleanup() { |
| 349 | // Close listening channel and all OF channels. Clean information about switches |
| 350 | // before deactivating |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 351 | ctrl.stop(); |
| 352 | connectedSwitches.values().forEach(OpenFlowSwitch::disconnectSwitch); |
Andrea Campanella | 3556f36 | 2016-04-28 15:18:10 -0700 | [diff] [blame] | 353 | connectedSwitches.clear(); |
| 354 | activeMasterSwitches.clear(); |
| 355 | activeEqualSwitches.clear(); |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 356 | openFlowManager.removeListener(openFlowListener); |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 357 | } |
| 358 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 359 | @Deactivate |
| 360 | public void deactivate() { |
Thiago Santos | 6172540 | 2016-08-05 17:58:56 -0300 | [diff] [blame] | 361 | cleanup(); |
Charles Chan | 3b00e1b | 2015-08-26 23:12:52 +0800 | [diff] [blame] | 362 | cfgService.unregisterProperties(getClass(), false); |
Brian O'Connor | 1bd4a9f | 2018-05-10 22:40:41 -0700 | [diff] [blame] | 363 | netCfgService.removeListener(netCfgListener); |
Brian O'Connor | f69e3e3 | 2018-05-10 02:25:09 -0700 | [diff] [blame] | 364 | netCfgService.unregisterConfigFactory(factory); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 367 | @Modified |
| 368 | public void modified(ComponentContext context) { |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 369 | ctrl.setConfigParams(context.getProperties()); |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 370 | } |
| 371 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 372 | @Override |
| 373 | public Iterable<OpenFlowSwitch> getSwitches() { |
| 374 | return connectedSwitches.values(); |
| 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public Iterable<OpenFlowSwitch> getMasterSwitches() { |
| 379 | return activeMasterSwitches.values(); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public Iterable<OpenFlowSwitch> getEqualSwitches() { |
| 384 | return activeEqualSwitches.values(); |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public OpenFlowSwitch getSwitch(Dpid dpid) { |
| 389 | return connectedSwitches.get(dpid); |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public OpenFlowSwitch getMasterSwitch(Dpid dpid) { |
| 394 | return activeMasterSwitches.get(dpid); |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public OpenFlowSwitch getEqualSwitch(Dpid dpid) { |
| 399 | return activeEqualSwitches.get(dpid); |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public void addListener(OpenFlowSwitchListener listener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 404 | if (!ofSwitchListener.contains(listener)) { |
| 405 | this.ofSwitchListener.add(listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void removeListener(OpenFlowSwitchListener listener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 411 | this.ofSwitchListener.remove(listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | @Override |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 415 | public void addClassifierListener(OpenFlowClassifierListener listener) { |
| 416 | this.ofClassifierListener.add(listener); |
| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | public void removeClassifierListener(OpenFlowClassifierListener listener) { |
| 421 | this.ofClassifierListener.remove(listener); |
| 422 | } |
| 423 | |
| 424 | @Override |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 425 | public void addMessageListener(OpenFlowMessageListener listener) { |
| 426 | ofMessageListener.add(listener); |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void removeMessageListener(OpenFlowMessageListener listener) { |
| 431 | ofMessageListener.remove(listener); |
| 432 | } |
| 433 | |
| 434 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 435 | public void addPacketListener(int priority, PacketListener listener) { |
| 436 | ofPacketListener.put(priority, listener); |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public void removePacketListener(PacketListener listener) { |
| 441 | ofPacketListener.values().remove(listener); |
| 442 | } |
| 443 | |
| 444 | @Override |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 445 | public void addEventListener(OpenFlowEventListener listener) { |
| 446 | ofEventListener.add(listener); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void removeEventListener(OpenFlowEventListener listener) { |
| 451 | ofEventListener.remove(listener); |
| 452 | } |
| 453 | |
| 454 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 455 | public void write(Dpid dpid, OFMessage msg) { |
| 456 | this.getSwitch(dpid).sendMsg(msg); |
| 457 | } |
| 458 | |
| 459 | @Override |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 460 | public CompletableFuture<OFMessage> writeResponse(Dpid dpid, OFMessage msg) { |
| 461 | write(dpid, msg); |
| 462 | |
| 463 | ConcurrentMap<Long, CompletableFuture<OFMessage>> xids = |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 464 | responses.computeIfAbsent(dpid, k -> new ConcurrentHashMap<>()); |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 465 | |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 466 | CompletableFuture<OFMessage> future = new CompletableFuture<>(); |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 467 | xids.put(msg.getXid(), future); |
| 468 | |
| 469 | return future; |
| 470 | } |
| 471 | |
| 472 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 473 | public void processPacket(Dpid dpid, OFMessage msg) { |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 474 | OpenFlowSwitch sw = this.getSwitch(dpid); |
Laszlo Papp | b68fe7e | 2017-11-24 17:06:59 +0000 | [diff] [blame] | 475 | if (log.isTraceEnabled()) { |
| 476 | log.trace("Processing message from switch {} via openflow: {}", dpid, msg); |
| 477 | } |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 478 | |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 479 | // Check if someone is waiting for this message |
| 480 | ConcurrentMap<Long, CompletableFuture<OFMessage>> xids = responses.get(dpid); |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 481 | if (xids != null) { |
| 482 | CompletableFuture<OFMessage> future = xids.remove(msg.getXid()); |
| 483 | if (future != null) { |
| 484 | future.complete(msg); |
| 485 | } |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 486 | } |
| 487 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 488 | switch (msg.getType()) { |
| 489 | case PORT_STATUS: |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 490 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 491 | l.portChanged(dpid, (OFPortStatus) msg); |
| 492 | } |
| 493 | break; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 494 | case FEATURES_REPLY: |
| 495 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 496 | l.switchChanged(dpid); |
| 497 | } |
| 498 | break; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 499 | case PACKET_IN: |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 500 | if (sw == null) { |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 501 | log.error("Ignoring PACKET_IN, switch {} is not found", dpid); |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 502 | break; |
| 503 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 504 | OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext |
Ozge AYAZ | 60aded2 | 2017-06-20 08:35:30 +0000 | [diff] [blame] | 505 | .packetContextFromPacketIn(sw, (OFPacketIn) msg); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 506 | for (PacketListener p : ofPacketListener.values()) { |
| 507 | p.handlePacket(pktCtx); |
| 508 | } |
| 509 | break; |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 510 | // TODO: Consider using separate threadpool for sensitive messages. |
| 511 | // ie. Back to back error could cause us to starve. |
| 512 | case FLOW_REMOVED: |
Andrea Campanella | dda9356 | 2016-03-02 11:08:12 -0800 | [diff] [blame] | 513 | executorMsgs.execute(new OFMessageHandler(dpid, msg)); |
Pavlin Radoslavov | 369c643 | 2014-12-03 16:25:14 -0800 | [diff] [blame] | 514 | break; |
Prince Pereira | e779803 | 2016-07-08 16:31:58 +0530 | [diff] [blame] | 515 | case ERROR: |
| 516 | log.debug("Received error message from {}: {}", dpid, msg); |
| 517 | errorMsgs.putIfAbsent(msg.getXid(), true); |
| 518 | executorErrorMsgs.execute(new OFMessageHandler(dpid, msg)); |
| 519 | break; |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 520 | case STATS_REPLY: |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 521 | processStatsReply(dpid, (OFStatsReply) msg); |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 522 | break; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 523 | case BARRIER_REPLY: |
Prince Pereira | e779803 | 2016-07-08 16:31:58 +0530 | [diff] [blame] | 524 | if (errorMsgs.containsKey(msg.getXid())) { |
| 525 | //To make oferror msg handling and corresponding barrier reply serialized, |
| 526 | // executorErrorMsgs is used for both transaction |
| 527 | errorMsgs.remove(msg.getXid()); |
| 528 | executorErrorMsgs.execute(new OFMessageHandler(dpid, msg)); |
| 529 | } else { |
| 530 | executorBarrier.execute(new OFMessageHandler(dpid, msg)); |
| 531 | } |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 532 | break; |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 533 | case EXPERIMENTER: |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 534 | if (sw == null) { |
| 535 | log.error("Switch {} is not found", dpid); |
| 536 | break; |
| 537 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 538 | long experimenter = ((OFExperimenter) msg).getExperimenter(); |
| 539 | if (experimenter == 0x748771) { |
| 540 | // LINC-OE port stats |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 541 | OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; |
sangyun-han | 69ed446 | 2016-07-27 12:10:12 +0900 | [diff] [blame] | 542 | OFPortStatus.Builder portStatus = sw.factory().buildPortStatus(); |
| 543 | OFPortDesc.Builder portDesc = sw.factory().buildPortDesc(); |
Marc De Leenheer | 631ffce | 2014-10-28 16:29:07 -0700 | [diff] [blame] | 544 | portDesc.setPortNo(circuitPortStatus.getPortNo()) |
| 545 | .setHwAddr(circuitPortStatus.getHwAddr()) |
| 546 | .setName(circuitPortStatus.getName()) |
| 547 | .setConfig(circuitPortStatus.getConfig()) |
| 548 | .setState(circuitPortStatus.getState()); |
| 549 | portStatus.setReason(circuitPortStatus.getReason()).setDesc(portDesc.build()); |
| 550 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 551 | l.portChanged(dpid, portStatus.build()); |
| 552 | } |
| 553 | } else { |
| 554 | log.warn("Handling experimenter type {} not yet implemented", |
| 555 | ((OFExperimenter) msg).getExperimenter(), msg); |
| 556 | } |
| 557 | break; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 558 | default: |
| 559 | log.warn("Handling message type {} not yet implemented {}", |
| 560 | msg.getType(), msg); |
| 561 | } |
| 562 | } |
| 563 | |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 564 | private void processStatsReply(Dpid dpid, OFStatsReply reply) { |
| 565 | switch (reply.getStatsType()) { |
| 566 | case QUEUE: |
| 567 | Collection<OFQueueStatsEntry> queueStatsEntries = publishQueueStats(dpid, (OFQueueStatsReply) reply); |
| 568 | if (queueStatsEntries != null) { |
| 569 | OFQueueStatsReply.Builder rep = |
| 570 | OFFactories.getFactory(reply.getVersion()).buildQueueStatsReply(); |
| 571 | rep.setEntries(ImmutableList.copyOf(queueStatsEntries)); |
| 572 | rep.setXid(reply.getXid()); |
| 573 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 574 | } |
| 575 | break; |
| 576 | |
| 577 | case PORT_DESC: |
| 578 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 579 | l.switchChanged(dpid); |
| 580 | } |
| 581 | break; |
| 582 | |
| 583 | case FLOW: |
| 584 | Collection<OFFlowStatsEntry> flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply); |
| 585 | if (flowStats != null) { |
| 586 | OFFlowStatsReply.Builder rep = |
| 587 | OFFactories.getFactory(reply.getVersion()).buildFlowStatsReply(); |
| 588 | rep.setEntries(ImmutableList.copyOf(flowStats)); |
| 589 | rep.setXid(reply.getXid()); |
| 590 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 591 | } |
| 592 | break; |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 593 | case FLOW_LIGHTWEIGHT: |
| 594 | Collection<OFFlowLightweightStatsEntry> flowLightweightStats = |
| 595 | publishFlowStatsLightweight(dpid, (OFFlowLightweightStatsReply) reply); |
| 596 | if (flowLightweightStats != null) { |
| 597 | OFFlowLightweightStatsReply.Builder rep = |
| 598 | OFFactories.getFactory(reply.getVersion()).buildFlowLightweightStatsReply(); |
| 599 | rep.setEntries(ImmutableList.copyOf(flowLightweightStats)); |
| 600 | rep.setXid(reply.getXid()); |
| 601 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 602 | } |
| 603 | break; |
Yuta HIGUCHI | 7b41dc9 | 2017-06-22 19:37:06 -0700 | [diff] [blame] | 604 | case TABLE: |
| 605 | Collection<OFTableStatsEntry> tableStats = publishTableStats(dpid, (OFTableStatsReply) reply); |
| 606 | if (tableStats != null) { |
| 607 | OFTableStatsReply.Builder rep = |
| 608 | OFFactories.getFactory(reply.getVersion()).buildTableStatsReply(); |
| 609 | rep.setEntries(ImmutableList.copyOf(tableStats)); |
| 610 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 611 | } |
| 612 | break; |
| 613 | |
| 614 | case GROUP: |
| 615 | Collection<OFGroupStatsEntry> groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply); |
| 616 | if (groupStats != null) { |
| 617 | OFGroupStatsReply.Builder rep = |
| 618 | OFFactories.getFactory(reply.getVersion()).buildGroupStatsReply(); |
| 619 | rep.setEntries(ImmutableList.copyOf(groupStats)); |
| 620 | rep.setXid(reply.getXid()); |
| 621 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 622 | } |
| 623 | break; |
| 624 | |
| 625 | case GROUP_DESC: |
| 626 | Collection<OFGroupDescStatsEntry> groupDescStats = publishGroupDescStats(dpid, |
| 627 | (OFGroupDescStatsReply) reply); |
| 628 | if (groupDescStats != null) { |
| 629 | OFGroupDescStatsReply.Builder rep = |
| 630 | OFFactories.getFactory(reply.getVersion()).buildGroupDescStatsReply(); |
| 631 | rep.setEntries(ImmutableList.copyOf(groupDescStats)); |
| 632 | rep.setXid(reply.getXid()); |
| 633 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 634 | } |
| 635 | break; |
| 636 | |
| 637 | case PORT: |
| 638 | executorMsgs.execute(new OFMessageHandler(dpid, reply)); |
| 639 | break; |
| 640 | |
| 641 | case METER: |
| 642 | executorMsgs.execute(new OFMessageHandler(dpid, reply)); |
| 643 | break; |
| 644 | |
| 645 | case EXPERIMENTER: |
| 646 | if (reply instanceof OFCalientFlowStatsReply) { |
| 647 | OpenFlowSwitch sw = this.getSwitch(dpid); |
| 648 | // Convert Calient flow statistics to regular flow stats |
| 649 | // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API |
| 650 | if (sw == null) { |
| 651 | log.error("Switch {} is not found", dpid); |
| 652 | break; |
| 653 | } |
| 654 | OFFlowStatsReply.Builder fsr = sw.factory().buildFlowStatsReply(); |
| 655 | List<OFFlowStatsEntry> entries = new ArrayList<>(); |
| 656 | for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) reply).getEntries()) { |
| 657 | |
| 658 | // Single instruction, i.e., output to port |
| 659 | OFActionOutput action = sw.factory() |
| 660 | .actions() |
| 661 | .buildOutput() |
| 662 | .setPort(entry.getOutPort()) |
| 663 | .build(); |
| 664 | OFInstruction instruction = sw.factory() |
| 665 | .instructions() |
| 666 | .applyActions(Collections.singletonList(action)); |
| 667 | OFFlowStatsEntry fs = sw.factory().buildFlowStatsEntry() |
| 668 | .setMatch(entry.getMatch()) |
| 669 | .setTableId(entry.getTableId()) |
| 670 | .setDurationSec(entry.getDurationSec()) |
| 671 | .setDurationNsec(entry.getDurationNsec()) |
| 672 | .setPriority(entry.getPriority()) |
| 673 | .setIdleTimeout(entry.getIdleTimeout()) |
| 674 | .setHardTimeout(entry.getHardTimeout()) |
| 675 | .setFlags(entry.getFlags()) |
| 676 | .setCookie(entry.getCookie()) |
| 677 | .setInstructions(Collections.singletonList(instruction)) |
| 678 | .build(); |
| 679 | entries.add(fs); |
| 680 | } |
| 681 | fsr.setEntries(entries); |
| 682 | |
| 683 | flowStats = publishFlowStats(dpid, fsr.build()); |
| 684 | if (flowStats != null) { |
| 685 | OFFlowStatsReply.Builder rep = |
| 686 | sw.factory().buildFlowStatsReply(); |
| 687 | rep.setEntries(ImmutableList.copyOf(flowStats)); |
| 688 | executorMsgs.execute(new OFMessageHandler(dpid, rep.build())); |
| 689 | } |
| 690 | } else { |
| 691 | executorMsgs.execute(new OFMessageHandler(dpid, reply)); |
| 692 | } |
| 693 | break; |
| 694 | default: |
| 695 | log.warn("Discarding unknown stats reply type {}", reply.getStatsType()); |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 700 | private synchronized Collection<OFFlowStatsEntry> publishFlowStats(Dpid dpid, |
| 701 | OFFlowStatsReply reply) { |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 702 | //TODO: Get rid of synchronized |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 703 | fullFlowStats.putAll(dpid, reply.getEntries()); |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 704 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 705 | return fullFlowStats.removeAll(dpid); |
| 706 | } |
| 707 | return null; |
| 708 | } |
| 709 | |
Cem Türker | 3baff67 | 2017-10-12 15:09:01 +0300 | [diff] [blame] | 710 | private synchronized Collection<OFFlowLightweightStatsEntry> publishFlowStatsLightweight( |
| 711 | Dpid dpid, |
| 712 | OFFlowLightweightStatsReply reply) { |
| 713 | //TODO: Get rid of synchronized |
| 714 | fullFlowLightweightStats.putAll(dpid, reply.getEntries()); |
| 715 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 716 | return fullFlowLightweightStats.removeAll(dpid); |
| 717 | } |
| 718 | return null; |
| 719 | } |
| 720 | |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 721 | private synchronized Collection<OFTableStatsEntry> publishTableStats(Dpid dpid, |
| 722 | OFTableStatsReply reply) { |
| 723 | //TODO: Get rid of synchronized |
| 724 | fullTableStats.putAll(dpid, reply.getEntries()); |
| 725 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 726 | return fullTableStats.removeAll(dpid); |
| 727 | } |
| 728 | return null; |
| 729 | } |
| 730 | |
sangho | 6a0bb17 | 2015-02-05 12:24:48 -0800 | [diff] [blame] | 731 | private synchronized Collection<OFGroupStatsEntry> publishGroupStats(Dpid dpid, |
| 732 | OFGroupStatsReply reply) { |
| 733 | //TODO: Get rid of synchronized |
| 734 | fullGroupStats.putAll(dpid, reply.getEntries()); |
| 735 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 736 | return fullGroupStats.removeAll(dpid); |
| 737 | } |
| 738 | return null; |
| 739 | } |
| 740 | |
| 741 | private synchronized Collection<OFGroupDescStatsEntry> publishGroupDescStats(Dpid dpid, |
| 742 | OFGroupDescStatsReply reply) { |
| 743 | //TODO: Get rid of synchronized |
| 744 | fullGroupDescStats.putAll(dpid, reply.getEntries()); |
| 745 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 746 | return fullGroupDescStats.removeAll(dpid); |
alshabib | 64def64 | 2014-12-02 23:27:37 -0800 | [diff] [blame] | 747 | } |
| 748 | return null; |
| 749 | } |
| 750 | |
Ozge AYAZ | 60aded2 | 2017-06-20 08:35:30 +0000 | [diff] [blame] | 751 | private synchronized Collection<OFQueueStatsEntry> publishQueueStats(Dpid dpid, OFQueueStatsReply reply) { |
| 752 | fullQueueStats.putAll(dpid, reply.getEntries()); |
| 753 | if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 754 | return fullQueueStats.removeAll(dpid); |
| 755 | } |
| 756 | return null; |
| 757 | } |
| 758 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 759 | @Override |
| 760 | public void setRole(Dpid dpid, RoleState role) { |
Yuta HIGUCHI | 79cbd1c | 2014-10-02 16:57:57 -0700 | [diff] [blame] | 761 | final OpenFlowSwitch sw = getSwitch(dpid); |
| 762 | if (sw == null) { |
| 763 | log.debug("Switch not connected. Ignoring setRole({}, {})", dpid, role); |
| 764 | return; |
| 765 | } |
| 766 | sw.setRole(role); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Implementation of an OpenFlow Agent which is responsible for |
| 771 | * keeping track of connected switches and the state in which |
| 772 | * they are. |
| 773 | */ |
| 774 | public class OpenFlowSwitchAgent implements OpenFlowAgent { |
| 775 | |
| 776 | private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); |
| 777 | private final Lock switchLock = new ReentrantLock(); |
| 778 | |
| 779 | @Override |
| 780 | public boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw) { |
alshabib | 9eab22f | 2014-10-20 17:17:31 -0700 | [diff] [blame] | 781 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 782 | if (connectedSwitches.get(dpid) != null) { |
| 783 | log.error("Trying to add connectedSwitch but found a previous " |
| 784 | + "value for dpid: {}", dpid); |
| 785 | return false; |
| 786 | } else { |
Yuta HIGUCHI | eb3f30b | 2014-10-22 11:34:49 -0700 | [diff] [blame] | 787 | log.info("Added switch {}", dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 788 | connectedSwitches.put(dpid, sw); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 789 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 790 | l.switchAdded(dpid); |
| 791 | } |
| 792 | return true; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | @Override |
| 797 | public boolean validActivation(Dpid dpid) { |
| 798 | if (connectedSwitches.get(dpid) == null) { |
| 799 | log.error("Trying to activate switch but is not in " |
| 800 | + "connected switches: dpid {}. Aborting ..", |
| 801 | dpid); |
| 802 | return false; |
| 803 | } |
| 804 | if (activeMasterSwitches.get(dpid) != null || |
| 805 | activeEqualSwitches.get(dpid) != null) { |
| 806 | log.error("Trying to activate switch but it is already " |
| 807 | + "activated: dpid {}. Found in activeMaster: {} " |
Ray Milkey | 6bc43c2 | 2015-11-06 13:22:38 -0800 | [diff] [blame] | 808 | + "Found in activeEqual: {}. Aborting ..", |
| 809 | dpid, |
| 810 | (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', |
| 811 | (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 812 | return false; |
| 813 | } |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | |
| 818 | @Override |
| 819 | public boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw) { |
| 820 | switchLock.lock(); |
| 821 | try { |
| 822 | if (!validActivation(dpid)) { |
| 823 | return false; |
| 824 | } |
| 825 | activeMasterSwitches.put(dpid, sw); |
| 826 | return true; |
| 827 | } finally { |
| 828 | switchLock.unlock(); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | public boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw) { |
| 834 | switchLock.lock(); |
| 835 | try { |
| 836 | if (!validActivation(dpid)) { |
| 837 | return false; |
| 838 | } |
| 839 | activeEqualSwitches.put(dpid, sw); |
| 840 | log.info("Added Activated EQUAL Switch {}", dpid); |
| 841 | return true; |
| 842 | } finally { |
| 843 | switchLock.unlock(); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | @Override |
| 848 | public void transitionToMasterSwitch(Dpid dpid) { |
| 849 | switchLock.lock(); |
| 850 | try { |
| 851 | if (activeMasterSwitches.containsKey(dpid)) { |
| 852 | return; |
| 853 | } |
| 854 | OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); |
| 855 | if (sw == null) { |
| 856 | sw = getSwitch(dpid); |
| 857 | if (sw == null) { |
| 858 | log.error("Transition to master called on sw {}, but switch " |
| 859 | + "was not found in controller-cache", dpid); |
| 860 | return; |
| 861 | } |
| 862 | } |
| 863 | log.info("Transitioned switch {} to MASTER", dpid); |
| 864 | activeMasterSwitches.put(dpid, sw); |
| 865 | } finally { |
| 866 | switchLock.unlock(); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | |
| 871 | @Override |
| 872 | public void transitionToEqualSwitch(Dpid dpid) { |
| 873 | switchLock.lock(); |
| 874 | try { |
| 875 | if (activeEqualSwitches.containsKey(dpid)) { |
| 876 | return; |
| 877 | } |
| 878 | OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); |
| 879 | if (sw == null) { |
| 880 | sw = getSwitch(dpid); |
| 881 | if (sw == null) { |
| 882 | log.error("Transition to equal called on sw {}, but switch " |
| 883 | + "was not found in controller-cache", dpid); |
| 884 | return; |
| 885 | } |
| 886 | } |
| 887 | log.info("Transitioned switch {} to EQUAL", dpid); |
| 888 | activeEqualSwitches.put(dpid, sw); |
| 889 | } finally { |
| 890 | switchLock.unlock(); |
| 891 | } |
| 892 | |
| 893 | } |
| 894 | |
| 895 | @Override |
| 896 | public void removeConnectedSwitch(Dpid dpid) { |
| 897 | connectedSwitches.remove(dpid); |
| 898 | OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); |
| 899 | if (sw == null) { |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 900 | log.debug("sw was null for {}", dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 901 | sw = activeEqualSwitches.remove(dpid); |
| 902 | } |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 903 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 904 | l.switchRemoved(dpid); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | @Override |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 909 | public void processDownstreamMessage(Dpid dpid, List<OFMessage> m) { |
| 910 | for (OpenFlowMessageListener listener : ofMessageListener) { |
| 911 | listener.handleOutgoingMessage(dpid, m); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | |
| 916 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 917 | public void processMessage(Dpid dpid, OFMessage m) { |
| 918 | processPacket(dpid, m); |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 919 | |
| 920 | for (OpenFlowMessageListener listener : ofMessageListener) { |
| 921 | listener.handleIncomingMessage(dpid, m); |
| 922 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 923 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 924 | |
| 925 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 926 | public void returnRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 927 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 928 | l.receivedRoleReply(dpid, requested, response); |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 931 | |
| 932 | @Override |
| 933 | public void addClassifierListener(OpenFlowClassifierListener listener) { |
| 934 | ofClassifierListener.add(listener); |
| 935 | } |
| 936 | |
| 937 | @Override |
| 938 | public void removeClassifierListener(OpenFlowClassifierListener listener) { |
| 939 | ofClassifierListener.remove(listener); |
| 940 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 943 | /** |
Jian Li | 2266bff | 2016-04-21 11:01:25 -0700 | [diff] [blame] | 944 | * OpenFlow message handler. |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 945 | */ |
Ray Milkey | 7ec0d1b | 2015-11-13 08:51:35 -0800 | [diff] [blame] | 946 | protected final class OFMessageHandler implements Runnable { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 947 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 948 | final OFMessage msg; |
| 949 | final Dpid dpid; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 950 | |
| 951 | public OFMessageHandler(Dpid dpid, OFMessage msg) { |
| 952 | this.msg = msg; |
| 953 | this.dpid = dpid; |
| 954 | } |
| 955 | |
| 956 | @Override |
| 957 | public void run() { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 958 | for (OpenFlowEventListener listener : ofEventListener) { |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 959 | listener.handleMessage(dpid, msg); |
| 960 | } |
| 961 | } |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 962 | } |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 963 | |
| 964 | private class InternalOpenFlowListener implements OpenFlowListener { |
| 965 | public void event(OpenFlowEvent event) { |
| 966 | try { |
| 967 | switch (event.type()) { |
| 968 | case INSERT: |
| 969 | for (OpenFlowClassifierListener listener : ofClassifierListener) { |
| 970 | listener.handleClassifiersAdd(event.subject()); |
| 971 | } |
| 972 | break; |
| 973 | case REMOVE: |
| 974 | for (OpenFlowClassifierListener listener : ofClassifierListener) { |
| 975 | listener.handleClassifiersRemove(event.subject()); |
| 976 | } |
| 977 | break; |
| 978 | default: |
| 979 | log.warn("Unknown OpenFlow classifier event type: {}", event.type()); |
| 980 | break; |
| 981 | } |
| 982 | } catch (Exception e) { |
| 983 | log.error("Internal OpenFlowListener exception: {}", e.getMessage()); |
| 984 | } |
| 985 | } |
| 986 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 987 | } |