Committed by
Gerrit Code Review
ONOS-2707
Fix bug of process ovsdb table update Change-Id: I55a879da1bf8770b68cb13c676f54482f685e60d
Showing
1 changed file
with
38 additions
and
54 deletions
| ... | @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | 19 | ||
| 20 | import java.math.BigInteger; | 20 | import java.math.BigInteger; |
| 21 | import java.util.HashSet; | 21 | import java.util.HashSet; |
| 22 | +import java.util.Iterator; | ||
| 22 | import java.util.List; | 23 | import java.util.List; |
| 23 | import java.util.Map; | 24 | import java.util.Map; |
| 24 | import java.util.Set; | 25 | import java.util.Set; |
| ... | @@ -60,7 +61,6 @@ import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; | ... | @@ -60,7 +61,6 @@ import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; |
| 60 | import org.onosproject.ovsdb.rfc.table.Bridge; | 61 | import org.onosproject.ovsdb.rfc.table.Bridge; |
| 61 | import org.onosproject.ovsdb.rfc.table.Interface; | 62 | import org.onosproject.ovsdb.rfc.table.Interface; |
| 62 | import org.onosproject.ovsdb.rfc.table.OvsdbTable; | 63 | import org.onosproject.ovsdb.rfc.table.OvsdbTable; |
| 63 | -import org.onosproject.ovsdb.rfc.table.Port; | ||
| 64 | import org.onosproject.ovsdb.rfc.table.TableGenerator; | 64 | import org.onosproject.ovsdb.rfc.table.TableGenerator; |
| 65 | import org.onosproject.ovsdb.rfc.utils.FromJsonUtil; | 65 | import org.onosproject.ovsdb.rfc.utils.FromJsonUtil; |
| 66 | import org.osgi.service.component.ComponentContext; | 66 | import org.osgi.service.component.ComponentContext; |
| ... | @@ -220,24 +220,23 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -220,24 +220,23 @@ public class OvsdbControllerImpl implements OvsdbController { |
| 220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", | 220 | log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", |
| 221 | uuid.value(), dbName, tableName); | 221 | uuid.value(), dbName, tableName); |
| 222 | 222 | ||
| 223 | - Row row = clientService.getRow(dbName, tableName, uuid.value()); | 223 | + Row oldRow = update.getOld(uuid); |
| 224 | - clientService.updateOvsdbStore(dbName, tableName, uuid.value(), | 224 | + Row newRow = update.getNew(uuid); |
| 225 | - update.getNew(uuid)); | 225 | + if (newRow != null) { |
| 226 | - if (update.getNew(uuid) != null) { | 226 | + clientService.updateOvsdbStore(dbName, tableName, |
| 227 | - boolean isNewRow = (row == null) ? true : false; | 227 | + uuid.value(), newRow); |
| 228 | - if (isNewRow) { | 228 | + |
| 229 | - if (OvsdbConstant.PORT.equals(tableName)) { | 229 | + if (OvsdbConstant.INTERFACE.equals(tableName)) { |
| 230 | - dispatchEvent(clientService, update.getNew(uuid), | 230 | + dispatchInterfaceEvent(clientService, |
| 231 | - null, OvsdbEvent.Type.PORT_ADDED, | 231 | + newRow, null, |
| 232 | + OvsdbEvent.Type.PORT_ADDED, | ||
| 232 | dbSchema); | 233 | dbSchema); |
| 233 | } | 234 | } |
| 234 | - } | ||
| 235 | } else if (update.getOld(uuid) != null) { | 235 | } else if (update.getOld(uuid) != null) { |
| 236 | - clientService.removeRow(dbName, tableName, uuid.toString()); | 236 | + clientService.removeRow(dbName, tableName, uuid.value()); |
| 237 | - if (update.getOld(uuid) != null) { | ||
| 238 | if (OvsdbConstant.PORT.equals(tableName)) { | 237 | if (OvsdbConstant.PORT.equals(tableName)) { |
| 239 | - dispatchEvent(clientService, null, | 238 | + dispatchInterfaceEvent(clientService, null, |
| 240 | - update.getOld(uuid), | 239 | + oldRow, |
| 241 | OvsdbEvent.Type.PORT_REMOVED, | 240 | OvsdbEvent.Type.PORT_REMOVED, |
| 242 | dbSchema); | 241 | dbSchema); |
| 243 | } | 242 | } |
| ... | @@ -245,7 +244,6 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -245,7 +244,6 @@ public class OvsdbControllerImpl implements OvsdbController { |
| 245 | } | 244 | } |
| 246 | } | 245 | } |
| 247 | } | 246 | } |
| 248 | - } | ||
| 249 | 247 | ||
| 250 | /** | 248 | /** |
| 251 | * Dispatches event to the north. | 249 | * Dispatches event to the north. |
| ... | @@ -256,57 +254,42 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -256,57 +254,42 @@ public class OvsdbControllerImpl implements OvsdbController { |
| 256 | * @param eventType type of event | 254 | * @param eventType type of event |
| 257 | * @param dbSchema ovsdb database schema | 255 | * @param dbSchema ovsdb database schema |
| 258 | */ | 256 | */ |
| 259 | - private void dispatchEvent(OvsdbClientService clientService, Row newRow, | 257 | + private void dispatchInterfaceEvent(OvsdbClientService clientService, |
| 260 | - Row oldRow, Type eventType, | 258 | + Row newRow, Row oldRow, |
| 259 | + Type eventType, | ||
| 261 | DatabaseSchema dbSchema) { | 260 | DatabaseSchema dbSchema) { |
| 262 | - Port port = null; | ||
| 263 | - if (OvsdbEvent.Type.PORT_ADDED.equals(eventType)) { | ||
| 264 | - port = (Port) TableGenerator.getTable(dbSchema, newRow, | ||
| 265 | - OvsdbTable.PORT); | ||
| 266 | - } else if (OvsdbEvent.Type.PORT_REMOVED.equals(eventType)) { | ||
| 267 | - port = (Port) TableGenerator.getTable(dbSchema, oldRow, | ||
| 268 | - OvsdbTable.PORT); | ||
| 269 | - } | ||
| 270 | - if (port == null) { | ||
| 271 | - return; | ||
| 272 | - } | ||
| 273 | 261 | ||
| 274 | long dpid = getDataPathid(clientService, dbSchema); | 262 | long dpid = getDataPathid(clientService, dbSchema); |
| 275 | - OvsdbSet intfUuidSet = (OvsdbSet) port.getInterfacesColumn().data(); | ||
| 276 | - @SuppressWarnings({ "unchecked" }) | ||
| 277 | - Set<UUID> intfUuids = intfUuidSet.set(); | ||
| 278 | - for (UUID intfUuid : intfUuids) { | ||
| 279 | - Row intfRow = clientService | ||
| 280 | - .getRow(OvsdbConstant.DATABASENAME, "Interface", | ||
| 281 | - intfUuid.toString()); | ||
| 282 | - if (intfRow == null) { | ||
| 283 | - continue; | ||
| 284 | - } | ||
| 285 | Interface intf = (Interface) TableGenerator | 263 | Interface intf = (Interface) TableGenerator |
| 286 | - .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); | 264 | + .getTable(dbSchema, newRow, OvsdbTable.INTERFACE); |
| 265 | + if (intf == null) { | ||
| 266 | + return; | ||
| 267 | + } | ||
| 287 | 268 | ||
| 288 | String portType = (String) intf.getTypeColumn().data(); | 269 | String portType = (String) intf.getTypeColumn().data(); |
| 289 | long localPort = getOfPort(intf); | 270 | long localPort = getOfPort(intf); |
| 271 | + if (localPort < 0) { | ||
| 272 | + return; | ||
| 273 | + } | ||
| 290 | String[] macAndIfaceId = getMacAndIfaceid(intf); | 274 | String[] macAndIfaceId = getMacAndIfaceid(intf); |
| 291 | if (macAndIfaceId == null) { | 275 | if (macAndIfaceId == null) { |
| 292 | return; | 276 | return; |
| 293 | } | 277 | } |
| 294 | - EventSubject eventSubject = new DefaultEventSubject( | 278 | + |
| 295 | - MacAddress | 279 | + EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf( |
| 296 | - .valueOf(macAndIfaceId[0]), | 280 | + macAndIfaceId[0]), |
| 297 | new HashSet<IpAddress>(), | 281 | new HashSet<IpAddress>(), |
| 298 | - new OvsdbPortName(port.getName()), | 282 | + new OvsdbPortName(intf |
| 283 | + .getName()), | ||
| 299 | new OvsdbPortNumber(localPort), | 284 | new OvsdbPortNumber(localPort), |
| 300 | - new OvsdbDatapathId(Long.toString(dpid)), | 285 | + new OvsdbDatapathId(Long |
| 286 | + .toString(dpid)), | ||
| 301 | new OvsdbPortType(portType), | 287 | new OvsdbPortType(portType), |
| 302 | new OvsdbIfaceId(macAndIfaceId[1])); | 288 | new OvsdbIfaceId(macAndIfaceId[1])); |
| 303 | for (OvsdbEventListener listener : ovsdbEventListener) { | 289 | for (OvsdbEventListener listener : ovsdbEventListener) { |
| 304 | listener.handle(new OvsdbEvent<EventSubject>(eventType, | 290 | listener.handle(new OvsdbEvent<EventSubject>(eventType, |
| 305 | eventSubject)); | 291 | eventSubject)); |
| 306 | } | 292 | } |
| 307 | - | ||
| 308 | - } | ||
| 309 | - | ||
| 310 | } | 293 | } |
| 311 | 294 | ||
| 312 | /** | 295 | /** |
| ... | @@ -345,14 +328,15 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -345,14 +328,15 @@ public class OvsdbControllerImpl implements OvsdbController { |
| 345 | * @return ofport the ofport number | 328 | * @return ofport the ofport number |
| 346 | */ | 329 | */ |
| 347 | private long getOfPort(Interface intf) { | 330 | private long getOfPort(Interface intf) { |
| 348 | - OvsdbSet ovsdbSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); | 331 | + OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); |
| 349 | @SuppressWarnings("unchecked") | 332 | @SuppressWarnings("unchecked") |
| 350 | - Set<Long> ofPorts = ovsdbSet.set(); | 333 | + Set<Integer> ofPorts = ofPortSet.set(); |
| 351 | while (ofPorts == null || ofPorts.size() <= 0) { | 334 | while (ofPorts == null || ofPorts.size() <= 0) { |
| 352 | log.debug("The ofport is null in {}", intf.getName()); | 335 | log.debug("The ofport is null in {}", intf.getName()); |
| 353 | - return 0; | 336 | + return -1; |
| 354 | } | 337 | } |
| 355 | - return (long) ofPorts.toArray()[0]; | 338 | + Iterator<Integer> it = ofPorts.iterator(); |
| 339 | + return Long.parseLong(it.next().toString()); | ||
| 356 | } | 340 | } |
| 357 | 341 | ||
| 358 | /** | 342 | /** |
| ... | @@ -376,9 +360,9 @@ public class OvsdbControllerImpl implements OvsdbController { | ... | @@ -376,9 +360,9 @@ public class OvsdbControllerImpl implements OvsdbController { |
| 376 | "Bridge", bridgeUuid); | 360 | "Bridge", bridgeUuid); |
| 377 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, | 361 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, |
| 378 | OvsdbTable.BRIDGE); | 362 | OvsdbTable.BRIDGE); |
| 379 | - OvsdbSet ovsdbSet = (OvsdbSet) bridge.getDatapathIdColumn().data(); | 363 | + OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data(); |
| 380 | @SuppressWarnings("unchecked") | 364 | @SuppressWarnings("unchecked") |
| 381 | - Set<String> dpids = ovsdbSet.set(); | 365 | + Set<String> dpids = dpidSet.set(); |
| 382 | if (dpids == null || dpids.size() == 0) { | 366 | if (dpids == null || dpids.size() == 0) { |
| 383 | return 0; | 367 | return 0; |
| 384 | } | 368 | } | ... | ... |
-
Please register or login to post a comment