2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal, Dave Tucker, Matt Oswalt
11 package org.opendaylight.ovsdb.schema.hardwarevtep;
13 import java.io.IOException;
14 import java.util.HashMap;
15 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.TimeoutException;
21 import junit.framework.Assert;
23 import org.junit.Assume;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.ovsdb.lib.MonitorCallBack;
27 import org.opendaylight.ovsdb.lib.message.MonitorRequest;
28 import org.opendaylight.ovsdb.lib.message.MonitorRequestBuilder;
29 import org.opendaylight.ovsdb.lib.message.MonitorSelect;
30 import org.opendaylight.ovsdb.lib.message.TableUpdate;
31 import org.opendaylight.ovsdb.lib.message.TableUpdates;
32 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
33 import org.opendaylight.ovsdb.lib.notation.Row;
34 import org.opendaylight.ovsdb.lib.notation.UUID;
35 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
36 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
37 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import com.google.common.collect.Lists;
43 public class MonitorTestCases extends HardwareVtepSchemaTestBase {
45 Logger logger = LoggerFactory.getLogger(MonitorTestCases.class);
49 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
54 public void monitorTables() throws ExecutionException, InterruptedException, IOException, TimeoutException {
55 //Ensure test only proceeds if HW VTEP is supported
56 Assume.assumeTrue(super.checkSchema());
57 HardwareVtepSchemaSuiteIT.dbSchema = this.ovs.getSchema(HARDWARE_VTEP_SCHEMA).get();
58 Assert.assertNotNull(HardwareVtepSchemaSuiteIT.dbSchema);
60 List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
61 monitorRequests.add(this.getAllColumnsMonitorRequest(Manager.class));
62 monitorRequests.add(this.getAllColumnsMonitorRequest(Global.class));
64 TableUpdates updates = ovs.monitor(HardwareVtepSchemaSuiteIT.dbSchema, monitorRequests, new UpdateMonitor());
65 Assert.assertNotNull(updates);
66 this.updateTableCache(updates);
70 * As per RFC 7047, section 4.1.5, if a Monitor request is sent without any columns, the update response will not include
72 * ----------------------------------------------------------------------------------------------------------------------------------
73 * Each <monitor-request> specifies one or more columns and the manner in which the columns (or the entire table) are to be monitored.
74 * The "columns" member specifies the columns whose values are monitored. It MUST NOT contain duplicates.
75 * If "columns" is omitted, all columns in the table, except for "_uuid", are monitored.
76 * ----------------------------------------------------------------------------------------------------------------------------------
77 * In order to overcome this limitation, this method
79 * @return MonitorRequest that includes all the Bridge Columns including _uuid
81 public <T extends TypedBaseTable<GenericTableSchema>> MonitorRequest<GenericTableSchema> getAllColumnsMonitorRequest (Class <T> klazz) { //TODO: Needs updated for HW VTEP
82 TypedBaseTable<GenericTableSchema> table = ovs.createTypedRowWrapper(klazz);
83 GenericTableSchema bridgeSchema = table.getSchema();
84 Set<String> columns = bridgeSchema.getColumns();
85 MonitorRequestBuilder<GenericTableSchema> bridgeBuilder = MonitorRequestBuilder.builder(table.getSchema());
86 for (String column : columns) {
87 bridgeBuilder.addColumn(column);
89 return bridgeBuilder.with(new MonitorSelect(true, true, true, true)).build();
95 public void update(Object context, UpdateNotification upadateNotification) {
100 public void locked(Object context, List<String> ids) {
105 public void stolen(Object context, List<String> ids) {
109 private void updateTableCache(TableUpdates updates) {
110 for (String tableName : updates.getUpdates().keySet()) {
111 Map<UUID, Row> tUpdate = HardwareVtepSchemaSuiteIT.getTableCache().get(tableName);
112 TableUpdate update = updates.getUpdates().get(tableName);
113 for (UUID uuid : (Set<UUID>)update.getRows().keySet()) {
114 if (update.getNew(uuid) != null) {
115 if (tUpdate == null) {
116 tUpdate = new HashMap<>();
117 HardwareVtepSchemaSuiteIT.getTableCache().put(tableName, tUpdate);
119 tUpdate.put(uuid, update.getNew(uuid));
121 tUpdate.remove(uuid);
127 private class UpdateMonitor implements MonitorCallBack {
129 public void update(TableUpdates result, DatabaseSchema dbSchema) {
130 updateTableCache(result);
134 public void exception(Throwable t) {
135 System.out.println("Exception t = " + t);