package org.opendaylight.ovsdb.plugin;
+import java.math.BigInteger;
import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.*;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
-import org.opendaylight.ovsdb.lib.database.OVSBridge;
-import org.opendaylight.ovsdb.lib.database.OVSInstance;
-import org.opendaylight.ovsdb.lib.database.OvsdbType;
+import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
import org.opendaylight.controller.sal.connection.ConnectionConstants;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
import org.opendaylight.controller.sal.networkconfig.bridgedomain.IPluginInBridgeDomainConfigService;
+import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.database.OVSInstance;
+import org.opendaylight.ovsdb.lib.database.OvsdbType;
+import org.opendaylight.ovsdb.lib.message.TransactBuilder;
+import org.opendaylight.ovsdb.lib.message.operations.InsertOperation;
+import org.opendaylight.ovsdb.lib.message.operations.MutateOperation;
+import org.opendaylight.ovsdb.lib.message.operations.Operation;
+import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
+import org.opendaylight.ovsdb.lib.notation.Condition;
+import org.opendaylight.ovsdb.lib.notation.Function;
+import org.opendaylight.ovsdb.lib.notation.Mutation;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
+import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
+import org.opendaylight.ovsdb.lib.notation.OvsDBSet;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.table.Bridge;
+import org.opendaylight.ovsdb.lib.table.Capability;
+import org.opendaylight.ovsdb.lib.table.Controller;
+import org.opendaylight.ovsdb.lib.table.Interface;
+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.Port;
+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.internal.Table;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ConfigurationService implements IPluginInBridgeDomainConfigService, CommandProvider
+import com.google.common.util.concurrent.ListenableFuture;
+
+public class ConfigurationService implements IPluginInBridgeDomainConfigService, OVSDBConfigService,
+ CommandProvider
{
private static final Logger logger = LoggerFactory
.getLogger(ConfigurationService.class);
IConnectionServiceInternal connectionService;
+ InventoryServiceInternal inventoryServiceInternal;
+ private IClusterGlobalServices clusterServices;
boolean forceConnect = false;
void init() {
}
}
+ public void setInventoryServiceInternal(InventoryServiceInternal inventoryServiceInternal) {
+ this.inventoryServiceInternal = inventoryServiceInternal;
+ }
+
+ public void unsetInventoryServiceInternal(InventoryServiceInternal inventoryServiceInternal) {
+ if (this.inventoryServiceInternal == inventoryServiceInternal) {
+ this.inventoryServiceInternal = null;
+ }
+ }
+
+ public void setClusterServices(IClusterGlobalServices i) {
+ this.clusterServices = i;
+ }
+
+ public void unsetClusterServices(IClusterGlobalServices i) {
+ if (this.clusterServices == i) {
+ this.clusterServices = null;
+ }
+ }
+
private Connection getConnection (Node node) {
Connection connection = connectionService.getConnection(node);
if (connection == null || !connection.getChannel().isActive()) {
return connection;
}
+
/**
* Add a new bridge
* @param node Node serving this configuration service
return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
}
- if (connection != null) {
- String newBridge = "new_bridge";
- String newInterface = "new_interface";
- String newPort = "new_port";
- String newSwitch = "new_switch";
-
- Object addSwitchRequest;
-
- OVSInstance instance = OVSInstance.monitorOVS(connection);
-
- if(instance != null){
- List<String> bridgeUuidPair = new ArrayList<String>();
- bridgeUuidPair.add("named-uuid");
- bridgeUuidPair.add(newBridge);
-
- List<Object> mutation = new ArrayList<Object>();
- mutation.add("bridges");
- mutation.add("insert");
- mutation.add(bridgeUuidPair);
-
- List<Object> mutations = new ArrayList<Object>();
- mutations.add(mutation);
-
- List<String> ovsUuidPair = new ArrayList<String>();
- ovsUuidPair.add("uuid");
- ovsUuidPair.add(instance.getUuid());
-
- List<Object> whereInner = new ArrayList<Object>();
- whereInner.add("_uuid");
- whereInner.add("==");
- whereInner.add(ovsUuidPair);
-
- List<Object> where = new ArrayList<Object>();
- where.add(whereInner);
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
+ String newBridge = "new_bridge";
+ String newInterface = "new_interface";
+ String newPort = "new_port";
+ String newSwitch = "new_switch";
+
+ Operation addSwitchRequest = null;
+
+ if(ovsTable != null){
+ String ovsTableUUID = (String) ovsTable.keySet().toArray()[0];
+ UUID bridgeUuidPair = new UUID(newBridge);
+ Mutation bm = new Mutation("bridges", Mutator.INSERT, bridgeUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(ovsTableUUID);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ addSwitchRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
+ }
+ else{
+ Open_vSwitch ovsTableRow = new Open_vSwitch();
+ OvsDBSet<UUID> bridges = new OvsDBSet<UUID>();
+ UUID bridgeUuidPair = new UUID(newBridge);
+ bridges.add(bridgeUuidPair);
+ ovsTableRow.setBridges(bridges);
+ addSwitchRequest = new InsertOperation(Open_vSwitch.NAME.getName(), newSwitch, ovsTableRow);
+ }
- addSwitchRequest = new MutateRequest("Open_vSwitch", where, mutations);
+ Bridge bridgeRow = new Bridge();
+ bridgeRow.setName(bridgeIdentifier);
+ OvsDBSet<UUID> ports = new OvsDBSet<UUID>();
+ UUID port = new UUID(newPort);
+ ports.add(port);
+ bridgeRow.setPorts(ports);
+ InsertOperation addBridgeRequest = new InsertOperation(Bridge.NAME.getName(), newBridge, bridgeRow);
+
+ Port portRow = new Port();
+ portRow.setName(bridgeIdentifier);
+ OvsDBSet<UUID> interfaces = new OvsDBSet<UUID>();
+ UUID interfaceid = new UUID(newInterface);
+ interfaces.add(interfaceid);
+ portRow.setInterfaces(interfaces);
+ InsertOperation addPortRequest = new InsertOperation(Port.NAME.getName(), newPort, portRow);
+
+ Interface interfaceRow = new Interface();
+ interfaceRow.setName(bridgeIdentifier);
+ interfaceRow.setType("internal");
+ InsertOperation addIntfRequest = new InsertOperation(Interface.NAME.getName(), newInterface, interfaceRow);
+
+ /* Update config version */
+ String ovsTableUUID = (String) ovsTable.keySet().toArray()[0];
+ Mutation bm = new Mutation("next_cfg", Mutator.SUM, 1);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(ovsTableUUID);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ MutateOperation updateCfgVerRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(
+ Arrays.asList(addSwitchRequest,
+ addIntfRequest,
+ addPortRequest,
+ addBridgeRequest,
+ updateCfgVerRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
}
- else{
- Map<String, Object> vswitchRow = new HashMap<String, Object>();
- ArrayList<String> bridges = new ArrayList<String>();
- bridges.add("named-uuid");
- bridges.add(newBridge);
- vswitchRow.put("bridges", bridges);
- addSwitchRequest = new InsertRequest("insert", "Open_vSwitch", newSwitch, vswitchRow);
- }
-
- Map<String, Object> bridgeRow = new HashMap<String, Object>();
- bridgeRow.put("name", bridgeIdentifier);
- ArrayList<String> ports = new ArrayList<String>();
- ports.add("named-uuid");
- ports.add(newPort);
- bridgeRow.put("ports", ports);
- InsertRequest addBridgeRequest = new InsertRequest("insert", "Bridge", newBridge, bridgeRow);
-
- Map<String, Object> portRow = new HashMap<String, Object>();
- portRow.put("name", bridgeIdentifier);
- ArrayList<String> interfaces = new ArrayList<String>();
- interfaces.add("named-uuid");
- interfaces.add(newInterface);
- portRow.put("interfaces", interfaces);
- InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
-
- Map<String, Object> interfaceRow = new HashMap<String, Object>();
- interfaceRow.put("name", bridgeIdentifier);
- interfaceRow.put("type", "internal");
- InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
-
- Object[] params = {"Open_vSwitch", addSwitchRequest, addIntfRequest, addPortRequest, addBridgeRequest};
- OvsdbMessage msg = new OvsdbMessage("transact", params);
+ }
- //connection.sendMessage(msg);
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
}
- }catch(Exception e){
+ if (status.isSuccess()) {
+ setBridgeOFController(node, bridgeIdentifier);
+ }
+ return status;
+ } catch(Exception e){
e.printStackTrace();
}
- return new Status(StatusCode.SUCCESS);
+ return new Status(StatusCode.INTERNALERROR);
}
/**
* @param portIdentifier String representation of a user defined Port Name
*/
@Override
- public Status addPort(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> configs) {
+ public Status addPort(Node node, String bridgeIdentifier, String portIdentifier,
+ Map<ConfigConstants, Object> configs) {
try{
if (connectionService == null) {
logger.error("Couldn't refer to the ConnectionService");
if (connection == null) {
return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
}
-
if (connection != null) {
+ Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ String newBridge = "new_bridge";
String newInterface = "new_interface";
String newPort = "new_port";
- Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
-
- OVSBridge bridge = existingBridges.get(bridgeIdentifier);
-
- List<String> portUuidPair = new ArrayList<String>();
- portUuidPair.add("named-uuid");
- portUuidPair.add(newPort);
-
- List<Object> mutation = new ArrayList<Object>();
- mutation.add("ports");
- mutation.add("insert");
- mutation.add(portUuidPair);
- List<Object> mutations = new ArrayList<Object>();
- mutations.add(mutation);
-
- List<String> bridgeUuidPair = new ArrayList<String>();
- bridgeUuidPair.add("uuid");
- bridgeUuidPair.add(bridge.getUuid());
-
- List<Object> whereInner = new ArrayList<Object>();
- whereInner.add("_uuid");
- whereInner.add("==");
- whereInner.add(bridgeUuidPair);
-
- List<Object> where = new ArrayList<Object>();
- where.add(whereInner);
+ if(brTable != null){
+ Operation addBrMutRequest = null;
+ String brUuid = null;
+ for (String uuid : brTable.keySet()) {
+ Bridge bridge = (Bridge) brTable.get(uuid);
+ if (bridge.getName().contains(bridgeIdentifier)) {
+ brUuid = uuid;
+ }
+ }
- MutateRequest mutateBridgeRequest = new MutateRequest("Bridge", where, mutations);
+ UUID brUuidPair = new UUID(newPort);
+ Mutation bm = new Mutation("ports", Mutator.INSERT, brUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(brUuid);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ addBrMutRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
+
+ OvsDBMap<String, String> options = null;
+ String type = null;
+ OvsDBSet<BigInteger> tags = null;
+ if (configs != null) {
+ type = (String) configs.get(ConfigConstants.TYPE);
+ Map<String, String> customConfigs = (Map<String, String>) configs.get(ConfigConstants.CUSTOM);
+ if (customConfigs != null) {
+ options = new OvsDBMap<String, String>();
+ for (String customConfig : customConfigs.keySet()) {
+ options.put(customConfig, customConfigs.get(customConfig));
+ }
+ }
+ }
- Map<String, Object> portRow = new HashMap<String, Object>();
- portRow.put("name", portIdentifier);
- String portType = null;
- if (configs != null) {
- portType = (String)configs.get(ConfigConstants.TYPE);
- if (portType != null && portType.equalsIgnoreCase(OvsdbType.PortType.VLAN.name())) {
- try {
- portRow.put("tag", Integer.parseInt((String)configs.get(ConfigConstants.VLAN)));
- } catch (Exception e) {
+ Interface interfaceRow = new Interface();
+ interfaceRow.setName(portIdentifier);
+
+ if (type != null) {
+ if (type.equalsIgnoreCase(OvsdbType.PortType.TUNNEL.name())) {
+ interfaceRow.setType((String)configs.get(ConfigConstants.TUNNEL_TYPE));
+ if (options == null) options = new OvsDBMap<String, String>();
+ options.put("remote_ip", (String)configs.get(ConfigConstants.DEST_IP));
+ } else if (type.equalsIgnoreCase(OvsdbType.PortType.VLAN.name())) {
+ tags = new OvsDBSet<BigInteger>();
+ tags.add(BigInteger.valueOf(Integer.parseInt((String)configs.get(ConfigConstants.VLAN))));
+ } else if (type.equalsIgnoreCase(OvsdbType.PortType.PATCH.name())) {
+ interfaceRow.setType(type.toLowerCase());
}
}
- }
- ArrayList<String> interfaces = new ArrayList<String>();
- interfaces.add("named-uuid");
- interfaces.add(newInterface);
- portRow.put("interfaces", interfaces);
- InsertRequest addPortRequest = new InsertRequest("insert", "Port", newPort, portRow);
-
- Map<String, Object> interfaceRow = new HashMap<String, Object>();
- interfaceRow.put("name", portIdentifier);
- //Tunnel specific
-
- if (portType != null && portType.equalsIgnoreCase(OvsdbType.PortType.TUNNEL.name())) {
- interfaceRow.put("type", configs.get(ConfigConstants.TUNNEL_TYPE));
- ArrayList<Object> intopt = new ArrayList<Object>();
- interfaceRow.put("options", intopt);
- ArrayList<Object> intoptmap = new ArrayList<Object>();
- ArrayList<String> intoptep = new ArrayList<String>();
- intopt.add("map");
- intopt.add(intoptmap);
- intoptmap.add(intoptep);
- intoptep.add("remote_ip");
- intoptep.add((String)configs.get(ConfigConstants.DEST_IP));
- }
- InsertRequest addIntfRequest = new InsertRequest("insert", "Interface", newInterface, interfaceRow);
+ if (options != null) {
+ interfaceRow.setOptions(options);
+ }
- Object[] params = {"Open_vSwitch", mutateBridgeRequest, addIntfRequest, addPortRequest};
- OvsdbMessage msg = new OvsdbMessage("transact", params);
+ InsertOperation addIntfRequest = new InsertOperation(Interface.NAME.getName(),
+ newInterface, interfaceRow);
+
+ Port portRow = new Port();
+ portRow.setName(portIdentifier);
+ if (tags != null) portRow.setTag(tags);
+ OvsDBSet<UUID> interfaces = new OvsDBSet<UUID>();
+ UUID interfaceid = new UUID(newInterface);
+ interfaces.add(interfaceid);
+ portRow.setInterfaces(interfaces);
+ InsertOperation addPortRequest = new InsertOperation(Port.NAME.getName(), newPort, portRow);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>
+ (Arrays.asList(addBrMutRequest, addPortRequest, addIntfRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
- //connection.sendMessage(msg);
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ return status;
+ }
+ return new Status(StatusCode.INTERNALERROR);
}
- }catch(Exception e){
+ } catch(Exception e){
e.printStackTrace();
}
- return new Status(StatusCode.SUCCESS);
+ return new Status(StatusCode.INTERNALERROR);
}
+
/**
* Implements the OVS Connection for Managers
*
@Override
public Status deletePort(Node node, String bridgeIdentifier, String portIdentifier) {
- // TODO Auto-generated method stub
- return null;
+
+ try{
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+
+ Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ Map<String, Table<?>> portTable = inventoryServiceInternal.getTableCache(node, Port.NAME.getName());
+ Operation delPortRequest = null;
+ String brUuid = null;
+ String portUuid = null;
+ if(brTable != null){
+ for (String uuid : brTable.keySet()) {
+ Bridge bridge = (Bridge) brTable.get(uuid);
+ if (bridge.getName().contains(bridgeIdentifier)) {
+ brUuid = uuid;
+ }
+ }
+ }
+ if(portTable != null){
+ for (String uuid : portTable.keySet()) {
+ Port port = (Port) portTable.get(uuid);
+ if (port.getName().contains(portIdentifier)) {
+ portUuid = uuid;
+ }
+ }
+ }
+
+ UUID portUuidPair = new UUID(portUuid);
+ Mutation bm = new Mutation("ports", Mutator.DELETE, portUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(brUuid);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ delPortRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(Arrays.asList(delPortRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ return status;
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
}
@Override
@Override
public Status deleteBridgeDomain(Node node, String bridgeIdentifier) {
- // TODO Auto-generated method stub
- return null;
+
+ try {
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
+ Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ Operation delBrRequest = null;
+ String ovsUuid = null;
+ String brUuid = null;
+
+ if (brTable != null) {
+ for (String uuid : brTable.keySet()) {
+ Bridge bridge = (Bridge) brTable.get(uuid);
+ if (bridge.getName().contains(bridgeIdentifier)) {
+ brUuid = uuid;
+ }
+ }
+ }
+ if (ovsTable != null) {
+ ovsUuid = (String) ovsTable.keySet().toArray()[0];
+ }
+ UUID bridgeUuidPair = new UUID(brUuid);
+ Mutation bm = new Mutation("bridges", Mutator.DELETE, bridgeUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(ovsUuid);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ delBrRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(Arrays.asList(delBrRequest)));
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size(); i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size() - 1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}",
+ bridgeIdentifier, result.getError(), result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ return status;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
}
@Override
@Override
public List<String> getBridgeDomains(Node node) {
-
- Connection connection = connectionService.getConnection(node);
- Map<String, OVSBridge> existingBridges = OVSBridge.monitorBridge(connection);
- List<String> bridgeDomains = new ArrayList<String>(existingBridges.keySet());
- return bridgeDomains;
+ List<String> brlist = new ArrayList<String>();
+ Map<String, Table<?>> brTableCache = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ if(brTableCache != null){
+ for (String uuid : brTableCache.keySet()) {
+ Bridge bridge = (Bridge) brTableCache.get(uuid);
+ brlist.add(bridge.getName());
+ }
+ }
+ return brlist;
}
@Override
return null;
}
+ private short getControllerOFPort() {
+ Short defaultOpenFlowPort = 6633;
+ Short openFlowPort = defaultOpenFlowPort;
+ String portString = System.getProperty("of.listenPort");
+ if (portString != null) {
+ try {
+ openFlowPort = Short.decode(portString).shortValue();
+ } catch (NumberFormatException e) {
+ logger.warn("Invalid port:{}, use default({})", portString,
+ openFlowPort);
+ }
+ }
+ return openFlowPort;
+ }
+
+ private List<InetAddress> getControllerIPAddresses() {
+ List<InetAddress> controllers = null;
+ if (clusterServices != null) {
+ controllers = clusterServices.getClusteredControllers();
+ if (controllers != null && controllers.size() > 0) {
+ if (controllers.size() == 1) {
+ InetAddress controller = controllers.get(0);
+ if (!controller.equals(InetAddress.getLoopbackAddress())) {
+ return controllers;
+ }
+ } else {
+ return controllers;
+ }
+ }
+ }
+
+ controllers = new ArrayList<InetAddress>();
+ InetAddress controllerIP;
+ Enumeration<NetworkInterface> nets;
+ try {
+ nets = NetworkInterface.getNetworkInterfaces();
+ for (NetworkInterface netint : Collections.list(nets)) {
+ Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
+ for (InetAddress inetAddress : Collections.list(inetAddresses)) {
+ if (!inetAddress.isLoopbackAddress() &&
+ NetUtils.isIPv4AddressValid(inetAddress.getHostAddress())) {
+ controllers.add(inetAddress);
+ }
+ }
+ }
+ } catch (SocketException e) {
+ controllers.add(InetAddress.getLoopbackAddress());
+ }
+ return controllers;
+ }
+
+ public Boolean setBridgeOFController(Node node, String bridgeIdentifier) {
+ try{
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return false;
+ }
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return false;
+ }
+
+ if (connection != null) {
+ List<InetAddress> ofControllerAddrs = getControllerIPAddresses();
+ short ofControllerPort = getControllerOFPort();
+ OvsDBSet<UUID> controllerUUIDs = new OvsDBSet<UUID>();
+ List<Operation> controllerInsertOperations = new ArrayList<Operation>();
+ Map<String, Table<?>> controllerCache = inventoryServiceInternal.getTableCache(node, Controller.NAME.getName());
+
+ int count = 0;
+ for (InetAddress ofControllerAddress : ofControllerAddrs) {
+ String cntrlUuid = null;
+ String newController = "tcp:"+ofControllerAddress.getHostAddress()+":"+ofControllerPort;
+ if (controllerCache != null) {
+ for (String uuid : controllerCache.keySet()) {
+ Controller controller = (Controller)controllerCache.get(uuid);
+ if (controller.getTarget().equals(newController)) {
+ cntrlUuid = uuid;
+ controllerUUIDs.add(new UUID(uuid));
+ break;
+ }
+ }
+ }
+ if (cntrlUuid == null) {
+ count++;
+ String uuid_name = "new_controller_"+count;
+ controllerUUIDs.add(new UUID(uuid_name));
+ Controller controllerRow = new Controller();
+ controllerRow.setTarget(newController);
+ InsertOperation addCtlRequest = new InsertOperation(Controller.NAME.getName(), uuid_name, controllerRow);
+ controllerInsertOperations.add(addCtlRequest);
+ }
+ }
+ String brCntrlUuid = null;
+ Map<String, Table<?>> brTableCache = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ for (String uuid : brTableCache.keySet()) {
+ Bridge bridge = (Bridge)brTableCache.get(uuid);
+ if (bridge.getName().contains(bridgeIdentifier)) {
+ brCntrlUuid = uuid;
+ }
+ }
+ Operation addControlRequest = null;
+ Mutation bm = new Mutation("controller", Mutator.INSERT, controllerUUIDs);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(brCntrlUuid);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ addControlRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(controllerInsertOperations);
+ transaction.addOperation(addControlRequest);
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+
+ }
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ @Override
+ public Status insertRow(Node node, String tableName, String parent_uuid, Table<?> row) {
+ logger.error("tableName : {}, parent_uuid : {} Row : {}", tableName, parent_uuid, row.toString());
+ Status statusWithUUID = null;
+
+ // Schema based Table handling will help fix this static Table handling.
+
+ if (row.getTableName().getName().equalsIgnoreCase("Bridge")) {
+ statusWithUUID = insertBridgeRow(node, parent_uuid, (Bridge)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Capbility")) {
+ statusWithUUID = insertCapabilityRow(node, parent_uuid, (Capability)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Controller")) {
+ statusWithUUID = insertControllerRow(node, parent_uuid, (Controller)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Interface")) {
+ statusWithUUID = insertInterfaceRow(node, parent_uuid, (Interface)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Manager")) {
+ statusWithUUID = insertManagerRow(node, parent_uuid, (Manager)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Mirror")) {
+ statusWithUUID = insertMirrorRow(node, parent_uuid, (Mirror)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("NetFlow")) {
+ statusWithUUID = insertNetFlowRow(node, parent_uuid, (NetFlow)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Open_vSwitch")) {
+ statusWithUUID = insertOpen_vSwitchRow(node, (Open_vSwitch)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Port")) {
+ statusWithUUID = insertPortRow(node, parent_uuid, (Port)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("QoS")) {
+ statusWithUUID = insertQosRow(node, parent_uuid, (Qos)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("Queue")) {
+ statusWithUUID = insertQueueRow(node, parent_uuid, (Queue)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("sFlow")) {
+ statusWithUUID = insertSflowRow(node, parent_uuid, (SFlow)row);
+ }
+ else if (row.getTableName().getName().equalsIgnoreCase("SSL")) {
+ statusWithUUID = insertSSLRow(node, parent_uuid, (SSL)row);
+ }
+ return statusWithUUID;
+ }
+
+ private Status insertBridgeRow(Node node, String open_VSwitch_uuid, Bridge bridgeRow) {
+ try{
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+
+ Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
+
+ if (ovsTable == null) {
+ return new Status(StatusCode.NOTFOUND, "There are no Open_vSwitch instance in the Open_vSwitch table");
+ }
+
+ String newBridge = "new_bridge";
+
+ Operation addSwitchRequest = null;
+
+ String ovsTableUUID = open_VSwitch_uuid;
+ if (ovsTableUUID == null) ovsTableUUID = (String) ovsTable.keySet().toArray()[0];
+ UUID bridgeUuidPair = new UUID(newBridge);
+ Mutation bm = new Mutation("bridges", Mutator.INSERT, bridgeUuidPair);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(ovsTableUUID);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ addSwitchRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
+
+ InsertOperation addBridgeRequest = new InsertOperation(Bridge.NAME.getName(), newBridge, bridgeRow);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>(
+ Arrays.asList(addSwitchRequest,
+ addBridgeRequest)));
+
+ int bridgeInsertIndex = transaction.getRequests().indexOf(addBridgeRequest);
+
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeRow.getName(),
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ if (status.isSuccess()) {
+ UUID bridgeUUID = tr.get(bridgeInsertIndex).getUuid();
+ status = new Status(StatusCode.SUCCESS, bridgeUUID.toString());
+ }
+ return status;
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ private Status insertPortRow(Node node, String bridge_uuid, Port portRow) {
+ try{
+ if (connectionService == null) {
+ logger.error("Couldn't refer to the ConnectionService");
+ return new Status(StatusCode.NOSERVICE);
+ }
+ Connection connection = this.getConnection(node);
+ if (connection == null) {
+ return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+ }
+
+ Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
+ if (brTable == null || brTable.get(bridge_uuid) == null) {
+ return new Status(StatusCode.NOTFOUND, "Bridge with UUID "+bridge_uuid+" Not found");
+ }
+ String newPort = "new_port";
+ UUID portUUID = new UUID(newPort);
+ Mutation bm = new Mutation("ports", Mutator.INSERT, portUUID);
+ List<Mutation> mutations = new ArrayList<Mutation>();
+ mutations.add(bm);
+
+ UUID uuid = new UUID(bridge_uuid);
+ Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+ List<Condition> where = new ArrayList<Condition>();
+ where.add(condition);
+ Operation addBrMutRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
+
+ // Default OVS schema is to have 1 or more interface part of Bridge. Hence it is mandatory to
+ // Insert an Interface in a Port add case :-(.
+
+ String newInterface = "new_interface";
+ Interface interfaceRow = new Interface();
+ interfaceRow.setName(portRow.getName());
+ InsertOperation addIntfRequest = new InsertOperation(Interface.NAME.getName(),
+ newInterface, interfaceRow);
+
+ OvsDBSet<UUID> interfaces = new OvsDBSet<UUID>();
+ UUID interfaceid = new UUID(newInterface);
+ interfaces.add(interfaceid);
+ portRow.setInterfaces(interfaces);
+
+ InsertOperation addPortRequest = new InsertOperation(Port.NAME.getName(), newPort, portRow);
+
+ TransactBuilder transaction = new TransactBuilder();
+ transaction.addOperations(new ArrayList<Operation>
+ (Arrays.asList(addBrMutRequest, addPortRequest, addIntfRequest)));
+ int portInsertIndex = transaction.getRequests().indexOf(addPortRequest);
+ ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+ List<OperationResult> tr = transResponse.get();
+ List<Operation> requests = transaction.getRequests();
+ Status status = new Status(StatusCode.SUCCESS);
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
+ OperationResult result = tr.get(i);
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ }
+
+ if (tr.size() > requests.size()) {
+ OperationResult result = tr.get(tr.size()-1);
+ logger.error("Error creating port : {}\n Error : {}\n Details : {}", portRow.getName(),
+ result.getError(),
+ result.getDetails());
+ status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+ }
+ if (status.isSuccess()) {
+ uuid = tr.get(portInsertIndex).getUuid();
+ status = new Status(StatusCode.SUCCESS, uuid.toString());
+ }
+
+ return status;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return new Status(StatusCode.INTERNALERROR);
+ }
+
+ private Status insertInterfaceRow(Node node, String port_uuid, Interface row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertOpen_vSwitchRow(Node node, Open_vSwitch row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertControllerRow(Node node, String bridge_uuid, Controller row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertSSLRow(Node node, String parent_uuid, SSL row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertSflowRow(Node node, String parent_uuid, SFlow row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertQueueRow(Node node, String parent_uuid, Queue row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertQosRow(Node node, String parent_uuid, Qos row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertNetFlowRow(Node node, String parent_uuid, NetFlow row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertMirrorRow(Node node, String parent_uuid, Mirror row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertManagerRow(Node node, String parent_uuid, Manager row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ private Status insertCapabilityRow(Node node, String parent_uuid, Capability row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+ }
+
+ @Override
+ public Status updateRow(Node node, String rowUUID, Table<?> row) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Update Row functionality is not implemented yet.");
+ }
+
+ @Override
+ public Status deleteRow(Node node, String tableName, String uuid) {
+ return new Status(StatusCode.NOTIMPLEMENTED, "Delete Row functionality is not implemented yet.");
+ }
+
+ @Override
+ public List<Table<?>> getRows(Node node, String tableName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Table<?> getRow(Node node, String tableName, String uuid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<String> getTables(Node node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
public void _ovsconnect (CommandInterpreter ci) {
String bridgeName = ci.nextArgument();
if (bridgeName == null) {
ci.println("Please enter Node Name");
return;
}
-
String bridgeName = ci.nextArgument();
if (bridgeName == null) {
ci.println("Please enter Bridge Name");
return;
}
Status status;
+
try {
- status = this.createBridgeDomain(Node.fromString(nodeName), bridgeName, null);
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.createBridgeDomain(node, bridgeName, null);
ci.println("Bridge creation status : "+status.toString());
} catch (Throwable e) {
// TODO Auto-generated catch block
}
}
+ public void _getBridgeDomains (CommandInterpreter ci) {
+ String nodeName = ci.nextArgument();
+ if (nodeName == null) {
+ ci.println("Please enter Node Name");
+ return;
+ }
+ Status status;
+
+ List<String> brlist = new ArrayList<String>();
+ try {
+ Node node = Node.fromString(nodeName);
+ brlist = this.getBridgeDomains(node);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ ci.println("Existing Bridges: "+brlist.toString());
+ } catch (Throwable e) {
+ e.printStackTrace();
+ ci.println("Failed to list Bridges");
+ }
+ }
+
+ public void _deleteBridgeDomain (CommandInterpreter ci) {
+ String nodeName = ci.nextArgument();
+ if (nodeName == null) {
+ ci.println("Please enter Node Name");
+ return;
+ }
+ String bridgeName = ci.nextArgument();
+ if (bridgeName == null) {
+ ci.println("Please enter Bridge Name");
+ return;
+ }
+ Status status;
+ try {
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.deleteBridgeDomain(node, bridgeName);
+ ci.println("Bridge deletion status : "+status.toString());
+ } catch (Throwable e) {
+ e.printStackTrace();
+ ci.println("Failed to delete Bridge "+bridgeName);
+ }
+ }
+
public void _addPort (CommandInterpreter ci) {
String nodeName = ci.nextArgument();
if (nodeName == null) {
return;
}
+ String type = ci.nextArgument();
+
+ Map<String, String> configs = new HashMap<String, String>();
+ while(true) {
+ String configKey = ci.nextArgument();
+ if (configKey == null) break;
+ String configValue = ci.nextArgument();
+ if (configValue == null) break;
+ configs.put(configKey, configValue);
+ }
+
+ Map<ConfigConstants, Object> customConfigs = null;
+ if (type != null) {
+ customConfigs = new HashMap<ConfigConstants, Object>();
+ customConfigs.put(ConfigConstants.TYPE, type);
+ }
+
+ if (configs.size() > 0) {
+ if (customConfigs == null) customConfigs = new HashMap<ConfigConstants, Object>();
+ customConfigs.put(ConfigConstants.CUSTOM, configs);
+ ci.println(customConfigs.toString());
+ }
Status status;
try {
- status = this.addPort(Node.fromString(nodeName), bridgeName, portName, null);
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.addPort(node, bridgeName, portName, customConfigs);
ci.println("Port creation status : "+status.toString());
} catch (Throwable e) {
// TODO Auto-generated catch block
}
}
+ public void _deletePort (CommandInterpreter ci) {
+ String nodeName = ci.nextArgument();
+ if (nodeName == null) {
+ ci.println("Please enter Node Name");
+ return;
+ }
+
+ String bridgeName = ci.nextArgument();
+ if (bridgeName == null) {
+ ci.println("Please enter Bridge Name");
+ return;
+ }
+
+ String portName = ci.nextArgument();
+ if (portName == null) {
+ ci.println("Please enter Port Name");
+ return;
+ }
+
+ Status status;
+ try {
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.deletePort(node, bridgeName, portName);
+ ci.println("Port deletion status : "+status.toString());
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ ci.println("Failed to delete Port "+portName+" in Bridge "+bridgeName);
+ }
+ }
+
public void _addPortVlan (CommandInterpreter ci) {
String nodeName = ci.nextArgument();
if (nodeName == null) {
Status status;
try {
- status = this.addPort(Node.fromString(nodeName), bridgeName, portName, configs);
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.addPort(node, bridgeName, portName, configs);
ci.println("Port creation status : "+status.toString());
} catch (Throwable e) {
// TODO Auto-generated catch block
Status status;
try {
- status = this.addPort(Node.fromString(nodeName), bridgeName, portName, configs);
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ status = this.addPort(node, bridgeName, portName, configs);
ci.println("Port creation status : "+status.toString());
} catch (Throwable e) {
// TODO Auto-generated catch block
}
}
+ public void _printCache (CommandInterpreter ci) {
+ String nodeName = ci.nextArgument();
+ if (nodeName == null) {
+ ci.println("Please enter Node Name");
+ return;
+ }
+ Node node = Node.fromString(nodeName);
+ if (node == null) {
+ ci.println("Invalid Node");
+ return;
+ }
+ inventoryServiceInternal.printCache(node);
+ }
+
public void _forceConnect (CommandInterpreter ci) {
String force = ci.nextArgument();
if (force.equalsIgnoreCase("YES")) forceConnect = true;
help.append("---OVSDB CLI---\n");
help.append("\t ovsconnect <ConnectionName> <ip-address> - Connect to OVSDB\n");
help.append("\t addBridge <Node> <BridgeName> - Add Bridge\n");
- help.append("\t addPort <Node> <BridgeName> <PortName> - Add Port\n");
+ help.append("\t getBridgeDomains <Node> - Get Bridges\n");
+ help.append("\t deleteBridgeDomain <Node> <BridgeName> - Delete a Bridge\n");
+ help.append("\t addPort <Node> <BridgeName> <PortName> <type> <options pairs> - Add Port\n");
+ help.append("\t deletePort <Node> <BridgeName> <PortName> - Delete Port\n");
help.append("\t addPortVlan <Node> <BridgeName> <PortName> <vlan> - Add Port, Vlan\n");
help.append("\t addTunnel <Node> <Bridge> <Port> <tunnel-type> <remote-ip> - Add Tunnel\n");
- help.append("\t forceConnect <yes|no> - Force a new OVSDB Connection for every command (Workaround)");
+ help.append("\t printCache <Node> - Prints Table Cache");
return help.toString();
}
}