Open vSwitch tunnel manager

Applying patch with new ovs-tunnel-manager on top of cloudstack oss-master
This commit is contained in:
Salvatore Orlando 2012-03-14 12:44:45 +00:00
parent 5568e95d4c
commit 3eef46f8a9
3 changed files with 2 additions and 164 deletions

View File

@ -30,6 +30,7 @@ public class OvsCreateTunnelCommand extends Command {
}
public OvsCreateTunnelCommand(String remoteIp, Integer key, Long from, Long to, long networkId, String fromIp) {
this.remoteIp = remoteIp;
this.key = key;
this.from = from;

View File

@ -492,169 +492,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((OvsCreateTunnelCommand)cmd);
} else if (clazz == OvsSetupBridgeCommand.class) {
return execute((OvsSetupBridgeCommand)cmd);
} else if (clazz == OvsDestroyBridgeCommand.class) {
return execute((OvsDestroyBridgeCommand)cmd);
} else if (clazz == OvsDestroyTunnelCommand.class) {
return execute((OvsDestroyTunnelCommand)cmd);
} else if (clazz == UpdateHostPasswordCommand.class) {
return execute((UpdateHostPasswordCommand)cmd);
} else if (cmd instanceof CheckRouterCommand) {
return execute((CheckRouterCommand)cmd);
} else if (cmd instanceof SetFirewallRulesCommand) {
return execute((SetFirewallRulesCommand)cmd);
} else if (cmd instanceof BumpUpPriorityCommand) {
return execute((BumpUpPriorityCommand)cmd);
} else if (cmd instanceof ClusterSyncCommand) {
return execute((ClusterSyncCommand)cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
return execute((GetDomRVersionCmd)cmd);
} else if (clazz == CheckNetworkCommand.class) {
return execute((CheckNetworkCommand) cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type, String name) throws XenAPIException, XmlRpcException {
if (name != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for network named " + name);
}
return getNetworkByName(conn, name);
}
if (type == TrafficType.Guest) {
return new XsLocalNetwork(Network.getByUuid(conn, _host.guestNetwork), null, PIF.getByUuid(conn, _host.guestPif), null);
} else if (type == TrafficType.Control) {
setupLinkLocalNetwork(conn);
return new XsLocalNetwork(Network.getByUuid(conn, _host.linkLocalNetwork));
} else if (type == TrafficType.Management) {
return new XsLocalNetwork(Network.getByUuid(conn, _host.privateNetwork), null, PIF.getByUuid(conn, _host.privatePif), null);
} else if (type == TrafficType.Public) {
return new XsLocalNetwork(Network.getByUuid(conn, _host.publicNetwork), null, PIF.getByUuid(conn, _host.publicPif), null);
} else if (type == TrafficType.Storage) {
return new XsLocalNetwork(Network.getByUuid(conn, _host.storageNetwork1), null, PIF.getByUuid(conn, _host.storagePif1), null);
}
throw new CloudRuntimeException("Unsupported network type: " + type);
}
/**
* This is a tricky to create network in xenserver.
* if you create a network then create bridge by brctl or openvswitch yourself,
* then you will get an expection that is "REQUIRED_NETWROK" when you start a
* vm with this network. The soultion is, create a vif of dom0 and plug it in
* network, xenserver will create the bridge on behalf of you
* @throws XmlRpcException
* @throws XenAPIException
*/
private void enableXenServerNetwork(Connection conn, Network nw,
String vifNameLabel, String networkDesc) throws XenAPIException, XmlRpcException {
/* Make sure there is a physical bridge on this network */
VIF dom0vif = null;
Pair<VM, VM.Record> vm = getControlDomain(conn);
VM dom0 = vm.first();
// Create a VIF unless there's not already another VIF
Set<VIF> dom0Vifs = dom0.getVIFs(conn);
for (VIF vif:dom0Vifs) {
vif.getRecord(conn);
if (vif.getNetwork(conn).getUuid(conn) == nw.getUuid(conn)) {
dom0vif = vif;
s_logger.debug("### A dom0 VIF has already been found - No need to create one");
}
}
if (dom0vif == null) {
s_logger.debug("Create a vif on dom0 for " + networkDesc);
VIF.Record vifr = new VIF.Record();
vifr.VM = dom0;
vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
if (vifr.device == null) {
s_logger.debug("Failed to create " + networkDesc + ", no vif available");
return;
}
Map<String, String> config = new HashMap<String, String>();
config.put("nameLabel", vifNameLabel);
vifr.otherConfig = config;
vifr.MAC = "FE:FF:FF:FF:FF:FF";
vifr.network = nw;
dom0vif = VIF.create(conn, vifr);
}
// At this stage we surely have a VIF
dom0vif.plug(conn);
dom0vif.unplug(conn);
synchronized(_tmpDom0Vif) {
_tmpDom0Vif.add(dom0vif);
}
}
private synchronized Network setupvSwitchNetwork(Connection conn) {
try {
if (_host.vswitchNetwork == null) {
Network vswitchNw = null;
Network.Record rec = new Network.Record();
String nwName = Networks.BroadcastScheme.VSwitch.toString();
Set<Network> networks = Network.getByNameLabel(conn, nwName);
if (networks.size() == 0) {
rec.nameDescription = "vswitch network for " + nwName;
rec.nameLabel = nwName;
vswitchNw = Network.create(conn, rec);
} else {
vswitchNw = networks.iterator().next();
}
enableXenServerNetwork(conn, vswitchNw, "vswitch", "vswicth network");
_host.vswitchNetwork = vswitchNw;
}
return _host.vswitchNetwork;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* This method just creates a XenServer network following the tunnel network naming convention
*/
private synchronized Network findOrCreateTunnelNetwork(Connection conn, long vnetId) {
try {
String nwName = "OVSTunnel" + vnetId;
Network nw = null;
Network.Record rec = new Network.Record();
Set<Network> networks = Network.getByNameLabel(conn, nwName);
if (networks.size() == 0) {
rec.nameDescription = "tunnel network id# " + vnetId;
rec.nameLabel = nwName;
//Initialize the ovs-host-setup to avoid error when doing get-param in plugin
Map<String,String> otherConfig = new HashMap<String,String>();
otherConfig.put("ovs-host-setup", "");
rec.otherConfig = otherConfig;
nw = Network.create(conn, rec);
s_logger.debug("### Xen Server network for tunnels created:" + nwName);
} else {
nw = networks.iterator().next();
s_logger.debug("### Xen Server network for tunnels found:" + nwName);
}
return nw;
} catch (Exception e) {
s_logger.warn("createTunnelNetwork failed", e);
return null;
}
}
/**
* This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
*/
private synchronized Network configureTunnelNetwork(Connection conn, long networkId, long hostId, int key) {
try {
// Note: the vnet (or gre key) is used to identify the XS network
Network nw = findOrCreateTunnelNetwork(conn, key);
String nwName = "OVSTunnel" + key;
//Invoke plugin to setup the bridge which will be used by this network
String bridge = nw.getBridge(conn);
Map<String,String> nwOtherConfig = nw.getOtherConfig(conn);
@ -4811,7 +4648,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Connection conn = getConnection();
s_logger.debug("### About to destroy tunnel network");
try {
Network nw = findOrCreateTunnelNetwork(conn, cmd.getKey());
Network nw = findTunnelNetwork(conn, cmd.getNetworkId());
if (nw == null) {
s_logger.warn("### Unable to find tunnel network");
return new Answer(cmd, false, "No network found");

0
scripts/vm/hypervisor/xenserver/ovstunnel Normal file → Executable file
View File