package org.opendaylight.ovsdb.lib;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
+
import org.opendaylight.ovsdb.lib.message.MonitorRequest;
import org.opendaylight.ovsdb.lib.operations.Operation;
import org.opendaylight.ovsdb.lib.operations.OperationResult;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
-import java.util.List;
+import com.google.common.util.concurrent.ListenableFuture;
/**
* The main interface to interact with a device speaking ovsdb protocol in an asynchronous fashion and hence most
*/
public interface OvsDBClient {
- /**
- * Represents the Open Vswitch Schema
- */
- String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
-
/**
* Gets the list of database names exposed by this ovsdb capable device
* @return list of database names
import org.opendaylight.ovsdb.lib.jsonrpc.Params;
import org.opendaylight.ovsdb.lib.message.MonitorRequest;
import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
+import org.opendaylight.ovsdb.lib.message.TableUpdate;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
import org.opendaylight.ovsdb.lib.message.TransactBuilder;
import org.opendaylight.ovsdb.lib.message.UpdateNotification;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
+import org.opendaylight.ovsdb.lib.table.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
logger.info("callback received with context {}, but no known handler. Ignoring!", key);
return;
}
- monitorCallBack.update(upadateNotification.getUpdate());
+ _transformingCallback(upadateNotification.getUpdate(), monitorCallBack);
}
@Override
}
}
+ protected void _transformingCallback( org.opendaylight.ovsdb.lib.message.temp.TableUpdates oldUpdate, MonitorCallBack monitorCallBack) {
+ //todo(ashwin) : temp kludge to get stuff working while deprecating old stuff
+ Map<String, TableUpdate> updateMap = Maps.newHashMap();
+ for (Map.Entry<Table.Name, TableUpdate> temp : oldUpdate.map.entrySet()) {
+ updateMap.put(temp.getKey().getName(), temp.getValue());
+ }
+
+ monitorCallBack.update(new TableUpdates(updateMap));
+ }
+
@Override
public ListenableFuture<List<OperationResult>> transact(List<Operation> operations) {
final MonitorHandle monitorHandle = new MonitorHandle(UUID.randomUUID().toString());
registerCallback(monitorHandle, callback);
- ListenableFuture<TableUpdates> monitor = rpc.monitor(new Params() {
+ ListenableFuture<org.opendaylight.ovsdb.lib.message.temp.TableUpdates> monitor = rpc.monitor(new Params() {
@Override
public List<Object> params() {
return Lists.<Object>newArrayList(dbSchema.getName(), monitorHandle.getId(), reqMap);
}
});
- Futures.addCallback(monitor, new FutureCallback<TableUpdates>() {
+ Futures.addCallback(monitor, new FutureCallback<org.opendaylight.ovsdb.lib.message.temp.TableUpdates>() {
@Override
- public void onSuccess(TableUpdates result) {
- callback.update(result);
+ public void onSuccess(org.opendaylight.ovsdb.lib.message.temp.TableUpdates result) {
+ _transformingCallback(result, callback);
}
@Override
import java.util.List;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.operations.OperationResult;
import com.fasterxml.jackson.databind.JsonNode;
/*
- * Copyright (C) 2013 EBay Software Foundation
*
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * * Copyright (C) 2014 EBay Software Foundation
+ * *
+ * * This program and the accompanying materials are made available under the
+ * * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * *
+ * * Authors : Ashwin Raveendran
*
- * Authors : Ashwin Raveendran, Madhu Venugopal
*/
package org.opendaylight.ovsdb.lib.message;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
-
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
-import org.opendaylight.ovsdb.lib.table.Bridge;
-import org.opendaylight.ovsdb.lib.table.Capability;
-import org.opendaylight.ovsdb.lib.table.Interface;
-import org.opendaylight.ovsdb.lib.table.Port;
-import org.opendaylight.ovsdb.lib.table.Controller;
-import org.opendaylight.ovsdb.lib.table.Manager;
-import org.opendaylight.ovsdb.lib.table.Mirror;
-import org.opendaylight.ovsdb.lib.table.NetFlow;
-import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
-import org.opendaylight.ovsdb.lib.table.Qos;
-import org.opendaylight.ovsdb.lib.table.Queue;
-import org.opendaylight.ovsdb.lib.table.SFlow;
-import org.opendaylight.ovsdb.lib.table.SSL;
-import org.opendaylight.ovsdb.lib.table.Flow_Sample_Collector_Set;
-import org.opendaylight.ovsdb.lib.table.Flow_Table;
-import org.opendaylight.ovsdb.lib.table.IPFIX;
-import org.opendaylight.ovsdb.lib.table.Table;
import java.util.Map;
-import java.util.Set;
public class TableUpdates extends Response {
- Map<Table.Name, TableUpdate> map = Maps.newHashMap();
-
- public Set<Table.Name> availableUpdates() {
- return map.keySet();
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Table> TableUpdate<T> getUpdate(Table.Name<T> name) {
- return map.get(name);
- }
-
- private <T extends Table> void put(Table.Name<T> name, TableUpdate<T> update) {
- map.put(name, update);
- }
-
- @JsonProperty("Interface")
- public TableUpdate<Interface> getInterfaceUpdate() {
- return getUpdate(Interface.NAME);
- }
-
- public void setInterfaceUpdate(TableUpdate<Interface> interfaceUpdate) {
- put(Interface.NAME, interfaceUpdate);
- }
-
- @JsonProperty("Bridge")
- TableUpdate<Bridge> getBridgeUpdate() {
- return getUpdate(Bridge.NAME);
- }
-
- public void setBridgeUpdate(TableUpdate<Bridge> bridgeUpdate) {
- put(Bridge.NAME, bridgeUpdate);
- }
-
- @JsonProperty("Port")
- TableUpdate<Port> getPortUpdate() {
- return getUpdate(Port.NAME);
- }
-
- void setPortUpdate(TableUpdate<Port> portUpdate) {
- put(Port.NAME, portUpdate);
- }
-
- @JsonProperty("Capability")
- public TableUpdate<Capability> getCapabilityUpdate() {
- return getUpdate(Capability.NAME);
- }
-
- public void setCapabilityUpdate(TableUpdate<Capability> capabilityUpdate) {
- put(Capability.NAME, capabilityUpdate);
- }
-
- @JsonProperty("Controller")
- public TableUpdate<Controller> getControllerUpdate() {
- return getUpdate(Controller.NAME);
- }
-
- public void setControllerUpdate(TableUpdate<Controller> controllerUpdate) {
- put(Controller.NAME, controllerUpdate);
- }
-
- @JsonProperty("Manager")
- public TableUpdate<Manager> getManagerUpdate() {
- return getUpdate(Manager.NAME);
- }
-
- public void setManagerUpdate(TableUpdate<Manager> managerUpdate) {
- put(Manager.NAME, managerUpdate);
- }
-
- @JsonProperty("Mirror")
- public TableUpdate<Mirror> getMirrorUpdate() {
- return getUpdate(Mirror.NAME);
- }
-
- public void setMirrorUpdate(TableUpdate<Mirror> mirrorUpdate) {
- put(Mirror.NAME, mirrorUpdate);
- }
-
- @JsonProperty("NetFlow")
- public TableUpdate<NetFlow> getNetFlowUpdate() {
- return getUpdate(NetFlow.NAME);
- }
-
- public void setNetFlowUpdate(TableUpdate<NetFlow> netFlowUpdate) {
- put(NetFlow.NAME, netFlowUpdate);
- }
-
- @JsonProperty("Open_vSwitch")
- public TableUpdate<Open_vSwitch> getOpen_vSwitchUpdate() {
- return getUpdate(Open_vSwitch.NAME);
- }
-
- public void setOpen_vSwitchUpdate(TableUpdate<Open_vSwitch> openVSwitchUpdate) {
- put(Open_vSwitch.NAME, openVSwitchUpdate);
- }
-
- @JsonProperty("QoS")
- public TableUpdate<Qos> getQosUpdate() {
- return getUpdate(Qos.NAME);
- }
-
- public void setQosUpdate(TableUpdate<Qos> qosUpdate) {
- put(Qos.NAME, qosUpdate);
- }
-
- @JsonProperty("Queue")
- public TableUpdate<Queue> getQueueUpdate() {
- return getUpdate(Queue.NAME);
- }
-
- public void setQueueUpdate(TableUpdate<Queue> queueUpdate) {
- put(Queue.NAME, queueUpdate);
- }
-
- @JsonProperty("sFlow")
- public TableUpdate<SFlow> getSFlowUpdate() {
- return getUpdate(SFlow.NAME);
- }
-
- public void setSFlowUpdate(TableUpdate<SFlow> sFlowUpdate) {
- put(SFlow.NAME, sFlowUpdate);
- }
-
- @JsonProperty("SSL")
- public TableUpdate<SSL> getSSLUpdate() {
- return getUpdate(SSL.NAME);
- }
-
- public void setSSLUpdate(TableUpdate<SSL> sslUpdate) {
- put(SSL.NAME, sslUpdate);
- }
-
- @JsonProperty("Flow_Table")
- public TableUpdate<Flow_Table> getFlow_TableUpdate() {
- return getUpdate(Flow_Table.NAME);
- }
-
- public void setFlow_TableUpdate(TableUpdate<Flow_Table> Flow_TableUpdate) {
- put(Flow_Table.NAME, Flow_TableUpdate);
- }
-
- @JsonProperty("Flow_Sample_Collector_Set")
- public TableUpdate<Flow_Sample_Collector_Set> getFlow_Sample_Collector_SetUpdate() {
- return getUpdate(Flow_Sample_Collector_Set.NAME);
- }
-
- public void setFlow_Sample_Collector_SetUpdate(TableUpdate<Flow_Sample_Collector_Set> Flow_Sample_Collector_SetUpdate) {
- put(Flow_Sample_Collector_Set.NAME, Flow_Sample_Collector_SetUpdate);
- }
+ Map<String, TableUpdate> map = Maps.newHashMap();
- @JsonProperty("IPFIX")
- public TableUpdate<IPFIX> getIPFIXUpdate() {
- return getUpdate(IPFIX.NAME);
+ public TableUpdates() {
+ this(Maps.<String, TableUpdate>newHashMap());
}
- public void setIPFIXUpdate(TableUpdate<IPFIX> IPFIXUpdate) {
- put(IPFIX.NAME, IPFIXUpdate);
+ public TableUpdates(Map<String, TableUpdate> map) {
+ this.map = map;
}
public TableUpdate getUpdate(GenericTableSchema table) {
//todo Horrible just for time being, before this whole thing is refactored.
- for (Map.Entry<Table.Name, TableUpdate> s : this.map.entrySet()) {
- if (table.getName().equals(s.getKey().getName())) {
+ for (Map.Entry<String, TableUpdate> s : this.map.entrySet()) {
+ if (table.getName().equals(s.getKey())) {
return s.getValue();
}
}
*/
package org.opendaylight.ovsdb.lib.message;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.notation.json.Converter.UpdateNotificationConverter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
--- /dev/null
+/*
+ * Copyright (C) 2013 EBay Software Foundation
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Ashwin Raveendran, Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.lib.message.temp;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.Maps;
+
+import org.opendaylight.ovsdb.lib.message.Response;
+import org.opendaylight.ovsdb.lib.message.TableUpdate;
+import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.lib.table.Bridge;
+import org.opendaylight.ovsdb.lib.table.Capability;
+import org.opendaylight.ovsdb.lib.table.Interface;
+import org.opendaylight.ovsdb.lib.table.Port;
+import org.opendaylight.ovsdb.lib.table.Controller;
+import org.opendaylight.ovsdb.lib.table.Manager;
+import org.opendaylight.ovsdb.lib.table.Mirror;
+import org.opendaylight.ovsdb.lib.table.NetFlow;
+import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
+import org.opendaylight.ovsdb.lib.table.Qos;
+import org.opendaylight.ovsdb.lib.table.Queue;
+import org.opendaylight.ovsdb.lib.table.SFlow;
+import org.opendaylight.ovsdb.lib.table.SSL;
+import org.opendaylight.ovsdb.lib.table.Flow_Sample_Collector_Set;
+import org.opendaylight.ovsdb.lib.table.Flow_Table;
+import org.opendaylight.ovsdb.lib.table.IPFIX;
+import org.opendaylight.ovsdb.lib.table.Table;
+
+import java.util.Map;
+import java.util.Set;
+
+
+public class TableUpdates extends Response {
+
+ public Map<Table.Name, TableUpdate> map = Maps.newHashMap();
+
+ public Set<Table.Name> availableUpdates() {
+ return map.keySet();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Table> TableUpdate<T> getUpdate(Table.Name<T> name) {
+ return map.get(name);
+ }
+
+ private <T extends Table> void put(Table.Name<T> name, TableUpdate<T> update) {
+ map.put(name, update);
+ }
+
+ @JsonProperty("Interface")
+ public TableUpdate<Interface> getInterfaceUpdate() {
+ return getUpdate(Interface.NAME);
+ }
+
+ public void setInterfaceUpdate(TableUpdate<Interface> interfaceUpdate) {
+ put(Interface.NAME, interfaceUpdate);
+ }
+
+ @JsonProperty("Bridge")
+ TableUpdate<Bridge> getBridgeUpdate() {
+ return getUpdate(Bridge.NAME);
+ }
+
+ public void setBridgeUpdate(TableUpdate<Bridge> bridgeUpdate) {
+ put(Bridge.NAME, bridgeUpdate);
+ }
+
+ @JsonProperty("Port")
+ TableUpdate<Port> getPortUpdate() {
+ return getUpdate(Port.NAME);
+ }
+
+ void setPortUpdate(TableUpdate<Port> portUpdate) {
+ put(Port.NAME, portUpdate);
+ }
+
+ @JsonProperty("Capability")
+ public TableUpdate<Capability> getCapabilityUpdate() {
+ return getUpdate(Capability.NAME);
+ }
+
+ public void setCapabilityUpdate(TableUpdate<Capability> capabilityUpdate) {
+ put(Capability.NAME, capabilityUpdate);
+ }
+
+ @JsonProperty("Controller")
+ public TableUpdate<Controller> getControllerUpdate() {
+ return getUpdate(Controller.NAME);
+ }
+
+ public void setControllerUpdate(TableUpdate<Controller> controllerUpdate) {
+ put(Controller.NAME, controllerUpdate);
+ }
+
+ @JsonProperty("Manager")
+ public TableUpdate<Manager> getManagerUpdate() {
+ return getUpdate(Manager.NAME);
+ }
+
+ public void setManagerUpdate(TableUpdate<Manager> managerUpdate) {
+ put(Manager.NAME, managerUpdate);
+ }
+
+ @JsonProperty("Mirror")
+ public TableUpdate<Mirror> getMirrorUpdate() {
+ return getUpdate(Mirror.NAME);
+ }
+
+ public void setMirrorUpdate(TableUpdate<Mirror> mirrorUpdate) {
+ put(Mirror.NAME, mirrorUpdate);
+ }
+
+ @JsonProperty("NetFlow")
+ public TableUpdate<NetFlow> getNetFlowUpdate() {
+ return getUpdate(NetFlow.NAME);
+ }
+
+ public void setNetFlowUpdate(TableUpdate<NetFlow> netFlowUpdate) {
+ put(NetFlow.NAME, netFlowUpdate);
+ }
+
+ @JsonProperty("Open_vSwitch")
+ public TableUpdate<Open_vSwitch> getOpen_vSwitchUpdate() {
+ return getUpdate(Open_vSwitch.NAME);
+ }
+
+ public void setOpen_vSwitchUpdate(TableUpdate<Open_vSwitch> openVSwitchUpdate) {
+ put(Open_vSwitch.NAME, openVSwitchUpdate);
+ }
+
+ @JsonProperty("QoS")
+ public TableUpdate<Qos> getQosUpdate() {
+ return getUpdate(Qos.NAME);
+ }
+
+ public void setQosUpdate(TableUpdate<Qos> qosUpdate) {
+ put(Qos.NAME, qosUpdate);
+ }
+
+ @JsonProperty("Queue")
+ public TableUpdate<Queue> getQueueUpdate() {
+ return getUpdate(Queue.NAME);
+ }
+
+ public void setQueueUpdate(TableUpdate<Queue> queueUpdate) {
+ put(Queue.NAME, queueUpdate);
+ }
+
+ @JsonProperty("sFlow")
+ public TableUpdate<SFlow> getSFlowUpdate() {
+ return getUpdate(SFlow.NAME);
+ }
+
+ public void setSFlowUpdate(TableUpdate<SFlow> sFlowUpdate) {
+ put(SFlow.NAME, sFlowUpdate);
+ }
+
+ @JsonProperty("SSL")
+ public TableUpdate<SSL> getSSLUpdate() {
+ return getUpdate(SSL.NAME);
+ }
+
+ public void setSSLUpdate(TableUpdate<SSL> sslUpdate) {
+ put(SSL.NAME, sslUpdate);
+ }
+
+ @JsonProperty("Flow_Table")
+ public TableUpdate<Flow_Table> getFlow_TableUpdate() {
+ return getUpdate(Flow_Table.NAME);
+ }
+
+ public void setFlow_TableUpdate(TableUpdate<Flow_Table> Flow_TableUpdate) {
+ put(Flow_Table.NAME, Flow_TableUpdate);
+ }
+
+ @JsonProperty("Flow_Sample_Collector_Set")
+ public TableUpdate<Flow_Sample_Collector_Set> getFlow_Sample_Collector_SetUpdate() {
+ return getUpdate(Flow_Sample_Collector_Set.NAME);
+ }
+
+ public void setFlow_Sample_Collector_SetUpdate(TableUpdate<Flow_Sample_Collector_Set> Flow_Sample_Collector_SetUpdate) {
+ put(Flow_Sample_Collector_Set.NAME, Flow_Sample_Collector_SetUpdate);
+ }
+
+ @JsonProperty("IPFIX")
+ public TableUpdate<IPFIX> getIPFIXUpdate() {
+ return getUpdate(IPFIX.NAME);
+ }
+
+ public void setIPFIXUpdate(TableUpdate<IPFIX> IPFIXUpdate) {
+ put(IPFIX.NAME, IPFIXUpdate);
+ }
+
+ public TableUpdate getUpdate(GenericTableSchema table) {
+ //todo Horrible just for time being, before this whole thing is refactored.
+ for (Map.Entry<Table.Name, TableUpdate> s : this.map.entrySet()) {
+ if (table.getName().equals(s.getKey().getName())) {
+ return s.getValue();
+ }
+ }
+ return null;
+ }
+}
@JsonSerialize(using = OvsDBSetSerializer.class)
public class OvsDBSet<T> extends ForwardingSet<T> {
- Set<T> target = Sets.newHashSet();
+ Set<T> target = null;
+
+ public OvsDBSet() {
+ this(Sets.<T>newHashSet());
+ }
+
+ public OvsDBSet(Set<T> backing) {
+ this.target = backing;
+ }
@Override
public Set<T> delegate() {
return target;
}
+
+ public static<D> OvsDBSet<D> fromSet(Set<D> value) {
+ return new OvsDBSet<>(value);
+ }
}
*/
package org.opendaylight.ovsdb.lib.notation.json;
-import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.message.UpdateNotification;
import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.lib.operations;
+
+
+public class Assert extends Operation {
+
+ public static final String ASSERT = "assert";
+ String lock;
+
+ public Assert(String lock) {
+ super(null, ASSERT);
+ this.lock = lock;
+ }
+
+ public String getLock() {
+ return lock;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.lib.operations;
+
+
+public class Comment extends Operation {
+
+ public static final String COMMENT = "comment";
+ String comment;
+
+ public Comment(String comment) {
+ super(null, COMMENT);
+ this.comment = comment;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+}
*/
package org.opendaylight.ovsdb.lib.operations;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.Maps;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
-import java.util.Map;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
public class Insert<E extends TableSchema<E>> extends Operation<E> {
}
public <D, C extends TableSchema<C>> Insert<E> value(ColumnSchema<C, D> columnSchema, D value) {
- row.put(columnSchema.getName(), value);
+ Object tval = null;
+ if (columnSchema.getType().isMultiValued()) {
+ Preconditions.checkArgument((value instanceof Set),"expected a set for multivalued item") ;
+ tval = OvsDBSet.fromSet((Set) value);
+ } else {
+ tval = value;
+ }
+ row.put(columnSchema.getName(), tval);
return this;
}
--- /dev/null
+/*
+ * Copyright (C) 2014 Matt Oswalt
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Matt Oswalt
+ *
+ */
+package org.opendaylight.ovsdb.lib.operations;
+
+import com.google.common.collect.Lists;
+import org.opendaylight.ovsdb.lib.notation.Condition;
+import org.opendaylight.ovsdb.lib.notation.Mutation;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
+import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
+import org.opendaylight.ovsdb.lib.schema.TableSchema;
+
+import java.util.List;
+
+public class Mutate<E extends TableSchema<E>> extends Operation<E> implements ConditionalOperation {
+
+ public static final String MUTATE = "mutate";
+ List<Condition> where = Lists.newArrayList();
+ private List<Mutation> mutations = Lists.newArrayList();
+
+ public Mutate on(TableSchema schema){
+ this.setTableSchema(schema);
+ return this;
+ }
+
+ public Mutate(TableSchema<E> schema) {
+ super(schema, MUTATE);
+ }
+
+ public <T extends TableSchema<T>, D> Mutate<E> addMutation(ColumnSchema<T, D> columnSchema, Mutator mutator, D value) {
+ columnSchema.validate(value);
+ mutations.add(new Mutation(columnSchema.getName(), mutator, value));
+ return this;
+ }
+
+ public List<Mutation> getMutations() {
+ return mutations;
+ }
+
+ public void setMutations(List<Mutation> mutations) {
+ this.mutations = mutations;
+ }
+
+ @Override
+ public void addCondition(Condition condition) {
+ this.where.add(condition);
+ }
+
+ public Where where(Condition condition) {
+ this.where.add(condition);
+ return new Where(this);
+ }
+
+ public List<Condition> getWhere() {
+ return where;
+ }
+
+ public void setWhere(List<Condition> where) {
+ this.where = where;
+ }
+}
\ No newline at end of file
return new Delete<>(schema);
}
+ public <E extends TableSchema<E>> Mutate<E> mutate(TableSchema<E> schema) {
+ return new Mutate<>(schema);
+ }
+
public Commit commit(Boolean durable) {
return new Commit(durable);
}
return new Select<>(schema);
}
-}
\ No newline at end of file
+ public Comment comment(String comment) {
+ return new Comment(comment);
+ }
+
+ /*
+ * Could not use Java keyword "assert" which clashes with the ovsdb json-rpc method.
+ * using assertion instead.
+ */
+ public Assert assertion(String lock) {
+ return new Assert(lock);
+ }
+}
public abstract class ColumnType {
BaseType baseType;
- int min = 0;
- int max = 0;
+ long min = 0;
+ long max = 0;
+
+ public long getMin() {
+ return min;
+ }
+
+ void setMin(long min) {
+ this.min = min;
+ }
+
+ public long getMax() {
+ return max;
+ }
+
+ void setMax(long max) {
+ this.max = max;
+ }
private static ColumnType columns[] = new ColumnType[]{
new AtomicColumnType(),
*/
protected abstract ColumnType fromJsonNode(JsonNode json);
+ public boolean isMultiValued() {
+ //todo check if this is the right logic
+ return this.min != this.max && this.min != 1;
+ }
+
public static class AtomicColumnType extends ColumnType {
public AtomicColumnType() {
}
BaseType baseType = BaseType.fromJson(json, "key");
- return baseType != null ? new AtomicColumnType(baseType) : null;
+ if (baseType != null) {
+
+ AtomicColumnType atomicColumnType = new AtomicColumnType(baseType);
+
+ JsonNode node = null;
+ if ((node = json.get("min")) != null) {
+ atomicColumnType.setMin(node.asLong());
+ }
+ if ((node = json.get("max")) != null) {
+ atomicColumnType.setMax(node.asLong());
+ }
+
+ return atomicColumnType;
+ }
+
+ return null;
}
}
return new Insert<>(this);
}
+ public <D> ColumnSchema<E, Set<D>> multiValuedColumn(String column, Class<D> type) {
+ //todo exception handling
+
+ ColumnSchema columnSchema = columns.get(column);
+ columnSchema.validateType(type);
+ return columnSchema;
+ }
+
public <D> ColumnSchema<E, D> column(String column, Class<D> type) {
//todo exception handling
import java.io.IOException;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.opendaylight.ovsdb.lib.message.TableUpdate;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
import org.opendaylight.ovsdb.lib.message.UpdateNotification;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.operations.OperationResult;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
@Test
public void testTransact() throws IOException, InterruptedException, ExecutionException {
- ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true);
+ ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true);
TableSchema<GenericTableSchema> bridge = schema.get().table("Bridge", GenericTableSchema.class);
for (Map.Entry<String, ColumnSchema> names : bridge.getColumnSchemas().entrySet()) {
ColumnSchema<GenericTableSchema, String> name = bridge.column("name", String.class);
ColumnSchema<GenericTableSchema, String> fail_mode = bridge.column("fail_mode", String.class);
+ ColumnSchema<GenericTableSchema, Set<Integer>> flood_vlans = bridge.multiValuedColumn("flood_vlans", Integer.class);
ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
- .add(op.insert(bridge).value(name, "br-int"))
+ .add(op.insert(bridge)
+ .value(name, "br-test")
+ .value(flood_vlans, Sets.newHashSet(100, 101, 4001)))
+ .add(op.comment("Inserting Bridge br-int"))
.add(op.update(bridge)
.set(fail_mode, "secure")
.where(name.opEqual("br-int"))
- //.and(name.opEqual("br-int"))
.operation())
+ .add(op.comment("Updating fail_mode to secure on Bridge br-int"))
.add(op.select(bridge)
.column(name)
.where(name.opEqual("br-int"))
.operation())
+ .add(op.mutate(bridge)
+ .addMutation(flood_vlans, Mutator.INSERT, Sets.newHashSet(100, 101, 4001))
+ .where(name.opEqual("br-int"))
+ .operation())
.add(op.commit(true))
+ .add(op.comment("Commiting the operation"))
.execute();
List<OperationResult> operationResults = results.get();
.add(op.delete(bridge)
.where(name.opEqual("br-int"))
.operation())
+ .add(op.comment("Deleting Bridge br-int"))
.add(op.commit(true))
+ .add(op.comment("Commiting the operation"))
.execute();
operationResults = results.get();
operationResults = results.get();
Assert.assertFalse(operationResults.isEmpty());
+ /* Testing for Abort Error */
+ Assert.assertFalse(operationResults.get(1).getError() == null);
System.out.println("Abort operation results = " + operationResults);
+ /*
+ * Adding a separate Abort operation in a transaction. Lets not mix this with other
+ * valid transactions as above.
+ */
+ results = ovs.transactBuilder()
+ .add(op.delete(bridge)
+ .where(name.opEqual("br-int"))
+ .operation())
+ .add(op.assertion("Assert12345")) // Failing intentionally
+ .execute();
+
+ operationResults = results.get();
+ Assert.assertFalse(operationResults.isEmpty());
+ /* Testing for an Assertion Error */
+ Assert.assertFalse(operationResults.get(1).getError() == null);
+ System.out.println("Assert operation results = " + operationResults);
+
}
@Test
public void testMonitorRequest() throws ExecutionException, InterruptedException {
- DatabaseSchema dbSchema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get();
+ DatabaseSchema dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get();
GenericTableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class);
List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
MonitorRequestBuilder.builder(bridge)
.addColumn(bridge.column("name"))
.addColumn(bridge.column("fail_mode", String.class))
+ .addColumn(bridge.multiValuedColumn("flood_vlans", Integer.class))
.with(new MonitorSelect(true, true, true, true))
.build());
}
});
- //for (int i = 0; i < 5 && results.isEmpty(); i++) { //wait 5 seconds to get a result
for (int i = 0; i < 5 ; i++) { //wait 5 seconds to get a result
System.out.println("waiting");
Thread.sleep(1000);
Assert.assertNotNull(bridgeUpdate);
}
- @Test
public void testGetDBs() throws ExecutionException, InterruptedException {
ListenableFuture<List<String>> databases = ovs.getDatabases();
List<String> dbNames = databases.get();
Assert.assertNotNull(dbNames);
- Assert.assertTrue(dbNames.size() > 0);
+ boolean hasOpenVswitchSchema = false;
+ for(String dbName : dbNames) {
+ if (dbName.equals(OPEN_VSWITCH_SCHEMA)) {
+ hasOpenVswitchSchema = true;
+ break;
+ }
+ }
+ Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
}
@Before
- public void initalize() throws IOException {
+ public void initalize() throws IOException, ExecutionException, InterruptedException {
if (ovs != null) {
return;
}
}
ExecutorService executorService = Executors.newFixedThreadPool(3);
ovs = new OvsDBClientImpl(rpc, executorService);
+ testGetDBs();
}
public void test() throws IOException, InterruptedException, ExecutionException {
OvsDBClientImpl ovs = getVswitch();
- Bridge bridge = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
+ Bridge bridge = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
.add(op.insert(bridge).value(bridge.name(), "br-int"))
private final static String SERVER_PORT = "ovsdbserver.port";
private final static String DEFAULT_SERVER_PORT = "6640";
+ /**
+ * Represents the Open Vswitch Schema
+ */
+ public final static String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
+
public Properties loadProperties() {
Properties props = new Properties(System.getProperties());
return props;
import junit.framework.TestCase;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
import org.opendaylight.ovsdb.lib.notation.UUID;
*/
package org.opendaylight.ovsdb.lib.schema.temp;
-import org.opendaylight.ovsdb.lib.OvsDBClient;
+import java.util.concurrent.ExecutionException;
+
import org.opendaylight.ovsdb.lib.OvsDBClientImpl;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.OvsdbTestBase;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
-import java.util.concurrent.ExecutionException;
-
public class SchemaObjs {
-
public static class Bridge extends TableSchema<Bridge> {
public static String NAME = "Bridge";
TableSchema target;
public static void main(String[] args) throws ExecutionException, InterruptedException {
OvsDBClientImpl ovs = new OvsDBClientImpl(null, null);
- DatabaseSchema db = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get();
+ DatabaseSchema db = ovs.getSchema(OvsdbTestBase.OPEN_VSWITCH_SCHEMA, true).get();
Bridge bridge = db.table(Bridge.NAME, Bridge.class);
Port port = db.table(Port.NAME, Port.class);
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcServiceBinderHandler;
import org.opendaylight.ovsdb.lib.message.MonitorRequestBuilder;
import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
-import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.message.UpdateNotification;
import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
import org.opendaylight.ovsdb.lib.table.Bridge;
import org.opendaylight.ovsdb.lib.database.DatabaseSchema;
import org.opendaylight.ovsdb.lib.message.TableUpdate;
import org.opendaylight.ovsdb.lib.message.TableUpdate.Row;
-import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
import org.opendaylight.ovsdb.lib.table.Bridge;
import org.opendaylight.ovsdb.lib.table.Table;
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
import org.opendaylight.ovsdb.lib.database.DatabaseSchema;
-import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.message.temp.TableUpdates;
import org.opendaylight.ovsdb.lib.table.Table;
public interface InventoryServiceInternal extends IPluginInInventoryService {