Skip to content

Commit 2340ebc

Browse files
author
Salvatore Orlando
committed
Now using vnets instead of network id for creating networks
Fixed issues with vif scripts on 5.6FP1 Fixed ipv6 issue on 5.6FP1 Plus other various fixes and improvements Starting to remove debug code NOTE: Network is configured correctly but instances do not start. Possibly indefinite wait occuring on some commands
1 parent 08daf9e commit 2340ebc

4 files changed

Lines changed: 175 additions & 15 deletions

File tree

api/src/com/cloud/network/ovs/OvsCreateTunnelCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public boolean executeInSequence() {
3030
}
3131

3232
public OvsCreateTunnelCommand(String remoteIp, Integer key, Long from, Long to, long networkId, String fromIp) {
33-
3433
this.remoteIp = remoteIp;
3534
this.key = key;
3635
this.from = from;

core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,170 @@ public Answer executeRequest(Command cmd) {
492492
return execute((OvsCreateTunnelCommand)cmd);
493493
} else if (clazz == OvsSetupBridgeCommand.class) {
494494
return execute((OvsSetupBridgeCommand)cmd);
495+
} else if (clazz == OvsDestroyBridgeCommand.class) {
496+
return execute((OvsDestroyBridgeCommand)cmd);
497+
} else if (clazz == OvsDestroyTunnelCommand.class) {
498+
return execute((OvsDestroyTunnelCommand)cmd);
499+
} else if (clazz == UpdateHostPasswordCommand.class) {
500+
return execute((UpdateHostPasswordCommand)cmd);
501+
} else if (cmd instanceof CheckRouterCommand) {
502+
return execute((CheckRouterCommand)cmd);
503+
} else if (cmd instanceof SetFirewallRulesCommand) {
504+
return execute((SetFirewallRulesCommand)cmd);
505+
} else if (cmd instanceof BumpUpPriorityCommand) {
506+
return execute((BumpUpPriorityCommand)cmd);
507+
} else if (cmd instanceof ClusterSyncCommand) {
508+
return execute((ClusterSyncCommand)cmd);
509+
} else if (cmd instanceof GetDomRVersionCmd) {
510+
return execute((GetDomRVersionCmd)cmd);
511+
} else if (clazz == CheckNetworkCommand.class) {
512+
return execute((CheckNetworkCommand) cmd);
513+
} else {
514+
return Answer.createUnsupportedCommandAnswer(cmd);
515+
}
516+
}
517+
518+
519+
protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type, String name) throws XenAPIException, XmlRpcException {
520+
if (name != null) {
521+
if (s_logger.isDebugEnabled()) {
522+
s_logger.debug("Looking for network named " + name);
523+
}
524+
return getNetworkByName(conn, name);
525+
}
526+
527+
if (type == TrafficType.Guest) {
528+
return new XsLocalNetwork(Network.getByUuid(conn, _host.guestNetwork), null, PIF.getByUuid(conn, _host.guestPif), null);
529+
} else if (type == TrafficType.Control) {
530+
setupLinkLocalNetwork(conn);
531+
return new XsLocalNetwork(Network.getByUuid(conn, _host.linkLocalNetwork));
532+
} else if (type == TrafficType.Management) {
533+
return new XsLocalNetwork(Network.getByUuid(conn, _host.privateNetwork), null, PIF.getByUuid(conn, _host.privatePif), null);
534+
} else if (type == TrafficType.Public) {
535+
return new XsLocalNetwork(Network.getByUuid(conn, _host.publicNetwork), null, PIF.getByUuid(conn, _host.publicPif), null);
536+
} else if (type == TrafficType.Storage) {
537+
return new XsLocalNetwork(Network.getByUuid(conn, _host.storageNetwork1), null, PIF.getByUuid(conn, _host.storagePif1), null);
538+
}
539+
540+
throw new CloudRuntimeException("Unsupported network type: " + type);
541+
}
542+
543+
/**
544+
* This is a tricky to create network in xenserver.
545+
* if you create a network then create bridge by brctl or openvswitch yourself,
546+
* then you will get an expection that is "REQUIRED_NETWROK" when you start a
547+
* vm with this network. The soultion is, create a vif of dom0 and plug it in
548+
* network, xenserver will create the bridge on behalf of you
549+
* @throws XmlRpcException
550+
* @throws XenAPIException
551+
*/
552+
private void enableXenServerNetwork(Connection conn, Network nw,
553+
String vifNameLabel, String networkDesc) throws XenAPIException, XmlRpcException {
554+
/* Make sure there is a physical bridge on this network */
555+
VIF dom0vif = null;
556+
Pair<VM, VM.Record> vm = getControlDomain(conn);
557+
VM dom0 = vm.first();
558+
// Create a VIF unless there's not already another VIF
559+
Set<VIF> dom0Vifs = dom0.getVIFs(conn);
560+
for (VIF vif:dom0Vifs) {
561+
vif.getRecord(conn);
562+
if (vif.getNetwork(conn).getUuid(conn) == nw.getUuid(conn)) {
563+
dom0vif = vif;
564+
s_logger.debug("### A dom0 VIF has already been found - No need to create one");
565+
}
566+
}
567+
if (dom0vif == null) {
568+
s_logger.debug("Create a vif on dom0 for " + networkDesc);
569+
VIF.Record vifr = new VIF.Record();
570+
vifr.VM = dom0;
571+
vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
572+
if (vifr.device == null) {
573+
s_logger.debug("Failed to create " + networkDesc + ", no vif available");
574+
return;
575+
}
576+
Map<String, String> config = new HashMap<String, String>();
577+
config.put("nameLabel", vifNameLabel);
578+
vifr.otherConfig = config;
579+
vifr.MAC = "FE:FF:FF:FF:FF:FF";
580+
vifr.network = nw;
581+
582+
dom0vif = VIF.create(conn, vifr);
583+
}
584+
// At this stage we surely have a VIF
585+
dom0vif.plug(conn);
586+
dom0vif.unplug(conn);
587+
synchronized(_tmpDom0Vif) {
588+
_tmpDom0Vif.add(dom0vif);
589+
}
590+
591+
}
592+
593+
private synchronized Network setupvSwitchNetwork(Connection conn) {
594+
try {
595+
if (_host.vswitchNetwork == null) {
596+
Network vswitchNw = null;
597+
Network.Record rec = new Network.Record();
598+
String nwName = Networks.BroadcastScheme.VSwitch.toString();
599+
Set<Network> networks = Network.getByNameLabel(conn, nwName);
600+
601+
if (networks.size() == 0) {
602+
rec.nameDescription = "vswitch network for " + nwName;
603+
rec.nameLabel = nwName;
604+
vswitchNw = Network.create(conn, rec);
605+
} else {
606+
vswitchNw = networks.iterator().next();
607+
}
608+
609+
enableXenServerNetwork(conn, vswitchNw, "vswitch", "vswicth network");
610+
_host.vswitchNetwork = vswitchNw;
611+
}
612+
return _host.vswitchNetwork;
613+
} catch (Exception e) {
614+
e.printStackTrace();
615+
}
616+
617+
return null;
618+
}
619+
620+
/**
621+
* This method just creates a XenServer network following the tunnel network naming convention
622+
*/
623+
private synchronized Network findOrCreateTunnelNetwork(Connection conn, long networkId) {
624+
try {
625+
String nwName = "OVSTunnel" + networkId;
626+
Network nw = null;
627+
Network.Record rec = new Network.Record();
628+
Set<Network> networks = Network.getByNameLabel(conn, nwName);
629+
630+
if (networks.size() == 0) {
631+
rec.nameDescription = "tunnel network id# " + networkId;
632+
rec.nameLabel = nwName;
633+
//Initialize the ovs-host-setup to avoid error when doing get-param in plugin
634+
Map<String,String> otherConfig = new HashMap<String,String>();
635+
otherConfig.put("ovs-host-setup", "");
636+
rec.otherConfig = otherConfig;
637+
nw = Network.create(conn, rec);
638+
// Plug dom0 vif only when creating network
639+
enableXenServerNetwork(conn, nw, nwName, "tunnel network for account " + networkId);
640+
s_logger.debug("### Xen Server network for tunnels created:" + nwName);
641+
} else {
642+
nw = networks.iterator().next();
643+
s_logger.debug("### Xen Server network for tunnels found:" + nwName);
644+
}
645+
return nw;
646+
} catch (Exception e) {
647+
s_logger.warn("createTunnelNetwork failed", e);
648+
return null;
649+
}
650+
}
651+
652+
/**
653+
* This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
654+
*/
655+
private synchronized Network configureTunnelNetwork(Connection conn, long networkId, long hostId, int key) {
656+
try {
657+
Network nw = findOrCreateTunnelNetwork(conn, networkId);
658+
>>>>>>> fb7dcaa... Now using vnets instead of network id for creating networks
495659
//Invoke plugin to setup the bridge which will be used by this network
496660
String bridge = nw.getBridge(conn);
497661
Map<String,String> nwOtherConfig = nw.getOtherConfig(conn);
@@ -4648,7 +4812,7 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
46484812
Connection conn = getConnection();
46494813
s_logger.debug("### About to destroy tunnel network");
46504814
try {
4651-
Network nw = findTunnelNetwork(conn, cmd.getNetworkId());
4815+
Network nw = findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
46524816
if (nw == null) {
46534817
s_logger.warn("### Unable to find tunnel network");
46544818
return new Answer(cmd, false, "No network found");

scripts/vm/hypervisor/xenserver/xenserver56fp1/ovs-vif-flows.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,12 @@ def main(command, vif_raw):
7777
if this_vif == vif:
7878
this_vif_ofport = vif_ofport
7979
vif_ofports.append(vif_ofport)
80-
# So regardless of whether the VIF is brought online or offline we
81-
# will always execute the same action
82-
if command == 'offline':
83-
clear_flows(bridge, this_vif_ofport, vif_ofports)
8480

85-
if command == 'online':
86-
apply_flows(bridge, this_vif_ofport, vif_ofports)
87-
88-
81+
if command == 'offline':
82+
clear_flows(bridge, this_vif_ofport, vif_ofports)
83+
84+
if command == 'online':
85+
apply_flows(bridge, this_vif_ofport, vif_ofports)
8986

9087

9188
if __name__ == "__main__":
@@ -95,4 +92,4 @@ def main(command, vif_raw):
9592
sys.exit(1)
9693
else:
9794
command, vif_raw = sys.argv[1:3]
98-
main(command, vif_raw)
95+
main(command, vif_raw)

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,12 +3355,12 @@ public StorageNetworkIpRangeResponse createStorageNetworkIpRangeResponse(Storage
33553355
response.setNetmask(result.getNetmask());
33563356
response.setGateway(result.getGateway());
33573357
response.setObjectName("storagenetworkiprange");
3358-
return response;
3358+
return response;
33593359
}
33603360

33613361
@Override
33623362
public Long getIdentiyId(String tableName, String token) {
33633363
return ApiDispatcher.getIdentiyId(tableName, token);
3364-
}
3365-
3366-
}
3364+
}
3365+
3366+
}

0 commit comments

Comments
 (0)