Skip to content

Commit e2cc2c1

Browse files
author
Salvatore Orlando
committed
Fixing remaining issues with per-VIF flow script and removing version-specific scripts.
Now generating XSnetwork names using gre keys Plus other minor corrections
1 parent 241ba26 commit e2cc2c1

10 files changed

Lines changed: 80 additions & 129 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@
2121

2222
public class OvsDestroyBridgeCommand extends Command {
2323

24-
long networkId;
24+
Long networkId;
25+
Integer key;
2526

26-
public OvsDestroyBridgeCommand(long networkId) {
27+
public OvsDestroyBridgeCommand(Long networkId, Integer key) {
2728
this.networkId = networkId;
29+
this.key = key;
2830
}
2931

30-
public long getNetworkId() {
32+
public Long getNetworkId() {
3133
return networkId;
3234
}
3335

36+
public Integer getKey() {
37+
return key;
38+
}
39+
3440
@Override
3541
public boolean executeInSequence() {
3642
return true;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@
1515
import com.cloud.agent.api.Command;
1616

1717
public class OvsDestroyTunnelCommand extends Command {
18-
long networkId;
18+
19+
Long networkId;
20+
Integer key;
1921
String inPortName;
2022

21-
public OvsDestroyTunnelCommand(long networkId, String inPortName) {
23+
public OvsDestroyTunnelCommand(Long networkId, Integer key, String inPortName) {
2224
this.networkId = networkId;
2325
this.inPortName = inPortName;
26+
this.key = key;
2427
}
2528

26-
public long getNetworkId() {
29+
public Long getNetworkId() {
2730
return networkId;
2831
}
2932

3033
public String getInPortName() {
3134
return inPortName;
3235
}
3336

37+
public Integer getKey() {
38+
return key;
39+
}
40+
3441
@Override
3542
public boolean executeInSequence() {
3643
return true;

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -620,23 +620,21 @@ private synchronized Network setupvSwitchNetwork(Connection conn) {
620620
/**
621621
* This method just creates a XenServer network following the tunnel network naming convention
622622
*/
623-
private synchronized Network findOrCreateTunnelNetwork(Connection conn, long networkId) {
623+
private synchronized Network findOrCreateTunnelNetwork(Connection conn, long vnetId) {
624624
try {
625-
String nwName = "OVSTunnel" + networkId;
625+
String nwName = "OVSTunnel" + vnetId;
626626
Network nw = null;
627627
Network.Record rec = new Network.Record();
628628
Set<Network> networks = Network.getByNameLabel(conn, nwName);
629629

630630
if (networks.size() == 0) {
631-
rec.nameDescription = "tunnel network id# " + networkId;
631+
rec.nameDescription = "tunnel network id# " + vnetId;
632632
rec.nameLabel = nwName;
633633
//Initialize the ovs-host-setup to avoid error when doing get-param in plugin
634634
Map<String,String> otherConfig = new HashMap<String,String>();
635635
otherConfig.put("ovs-host-setup", "");
636636
rec.otherConfig = otherConfig;
637637
nw = Network.create(conn, rec);
638-
// Plug dom0 vif only when creating network
639-
enableXenServerNetwork(conn, nw, nwName, "tunnel network for account " + networkId);
640638
s_logger.debug("### Xen Server network for tunnels created:" + nwName);
641639
} else {
642640
nw = networks.iterator().next();
@@ -654,7 +652,9 @@ private synchronized Network findOrCreateTunnelNetwork(Connection conn, long net
654652
*/
655653
private synchronized Network configureTunnelNetwork(Connection conn, long networkId, long hostId, int key) {
656654
try {
657-
Network nw = findOrCreateTunnelNetwork(conn, networkId);
655+
// Note: the vnet (or gre key) is used to identify the XS network
656+
Network nw = findOrCreateTunnelNetwork(conn, key);
657+
String nwName = "OVSTunnel" + key;
658658
//Invoke plugin to setup the bridge which will be used by this network
659659
String bridge = nw.getBridge(conn);
660660
Map<String,String> nwOtherConfig = nw.getOtherConfig(conn);
@@ -670,6 +670,8 @@ private synchronized Network configureTunnelNetwork(Connection conn, long networ
670670
}
671671
}
672672
if (!configured) {
673+
// Plug dom0 vif only if not done before for network and host
674+
enableXenServerNetwork(conn, nw, nwName, "tunnel network for account " + key);
673675
String result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge", "bridge", bridge,
674676
"key", String.valueOf(key),
675677
"xs_nw_uuid", nw.getUuid(conn),
@@ -689,9 +691,9 @@ private synchronized Network configureTunnelNetwork(Connection conn, long networ
689691
}
690692
}
691693

692-
private synchronized void destroyTunnelNetwork(Connection conn, long networkId) {
694+
private synchronized void destroyTunnelNetwork(Connection conn, int key) {
693695
try {
694-
Network nw = findOrCreateTunnelNetwork(conn, networkId);
696+
Network nw = findOrCreateTunnelNetwork(conn, key);
695697
String bridge = nw.getBridge(conn);
696698
String result = callHostPlugin(conn, "ovstunnel", "destroy_ovs_bridge", "bridge", bridge);
697699
String[] res = result.split(":");
@@ -731,8 +733,8 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
731733
_isOvs = true;
732734
return setupvSwitchNetwork(conn);
733735
} else {
734-
long networkId = Long.parseLong(nic.getBroadcastUri().getHost());
735-
return findOrCreateTunnelNetwork(conn, networkId);
736+
long vnetId = Long.parseLong(nic.getBroadcastUri().getHost());
737+
return findOrCreateTunnelNetwork(conn, vnetId);
736738
}
737739
} else if (nic.getBroadcastType() == BroadcastDomainType.Storage) {
738740
URI broadcastUri = nic.getBroadcastUri();
@@ -1196,7 +1198,7 @@ public StartAnswer execute(StartCommand cmd) {
11961198
startVM(conn, host, vm, vmName);
11971199

11981200
if (_isOvs) {
1199-
// TODO(Salvatore-orlando): First option is to do per-NIC rules here
1201+
// TODO(Salvatore-orlando): This code should go
12001202
for (NicTO nic : vmSpec.getNics()) {
12011203
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) {
12021204
HashMap<String, String> args = parseDefaultOvsRuleComamnd(nic.getBroadcastUri().toString().substring(Networks.BroadcastDomainType.Vswitch.scheme().length() + "://".length()));
@@ -4791,7 +4793,7 @@ protected boolean can_bridge_firewall(Connection conn) {
47914793
private Answer execute(OvsSetupBridgeCommand cmd) {
47924794
Connection conn = getConnection();
47934795
s_logger.debug("### About to configure OVS bridge");
4794-
Network nw=findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
4796+
Network nw=findOrCreateTunnelNetwork(conn, cmd.getKey());
47954797
this.configureTunnelNetwork(conn, cmd.getNetworkId(), cmd.getHostId(), cmd.getKey());
47964798
s_logger.debug("### Bridge configured");
47974799
return new Answer(cmd, true, null);
@@ -4800,7 +4802,7 @@ private Answer execute(OvsSetupBridgeCommand cmd) {
48004802
private Answer execute(OvsDestroyBridgeCommand cmd) {
48014803
Connection conn = getConnection();
48024804
s_logger.debug("### About to destroy OVS bridge");
4803-
destroyTunnelNetwork(conn, cmd.getNetworkId());
4805+
destroyTunnelNetwork(conn, cmd.getKey());
48044806
s_logger.debug("### Bridge destroyed");
48054807
return new Answer(cmd, true, null);
48064808
}
@@ -4809,7 +4811,7 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
48094811
Connection conn = getConnection();
48104812
s_logger.debug("### About to destroy tunnel network");
48114813
try {
4812-
Network nw = findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
4814+
Network nw = findOrCreateTunnelNetwork(conn, cmd.getKey());
48134815
if (nw == null) {
48144816
s_logger.warn("### Unable to find tunnel network");
48154817
return new Answer(cmd, false, "No network found");
@@ -4841,7 +4843,7 @@ private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
48414843
String bridge = "unknown";
48424844
try {
48434845
s_logger.debug("### About to create tunnel network");
4844-
Network nw = findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
4846+
Network nw = findOrCreateTunnelNetwork(conn, cmd.getKey());
48454847
if (nw == null) {
48464848
s_logger.debug("### SOMETHING WENT WRONG DURING NETWORK SETUP");
48474849
return new OvsCreateTunnelAnswer(cmd, false, "Cannot create network", bridge);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def main(command, vif_raw):
6565
# We need the REAL bridge name
6666
bridge = pluginlib.do_cmd([pluginlib.VSCTL_PATH,
6767
'br-to-parent', bridge])
68-
# For the OVS version shipped with XS56FP1 we need to retrieve
69-
# the ofport number for all interfaces
68+
7069
vsctl_output = pluginlib.do_cmd([pluginlib.VSCTL_PATH,
7170
'list-ports', bridge])
7271
vifs = vsctl_output.split('\n')
@@ -75,8 +74,9 @@ def main(command, vif_raw):
7574
vif_ofport = pluginlib.do_cmd([pluginlib.VSCTL_PATH, 'get',
7675
'Interface', vif, 'ofport'])
7776
if this_vif == vif:
78-
this_vif_ofport = vif_ofport
79-
vif_ofports.append(vif_ofport)
77+
this_vif_ofport = vif_ofport
78+
if vif.startswith('vif'):
79+
vif_ofports.append(vif_ofport)
8080

8181
if command == 'offline':
8282
clear_flows(bridge, this_vif_ofport, vif_ofports)

scripts/vm/hypervisor/xenserver/ovstunnel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def setup_ovs_bridge(session, args):
144144
"uuid=%s" % xs_nw_uuid,
145145
"param-name=other-config",
146146
"param-key=ovs-host-setup", "--minimal"])
147-
conf_hosts = conf_hosts + ",%s" %cs_host_id
147+
conf_hosts = cs_host_id + (conf_hosts and ',%s' % conf_hosts or '')
148148
lib.do_cmd([lib.XE_PATH,"network-param-set", "uuid=%s" % xs_nw_uuid,
149149
"other-config:ovs-host-setup=%s" %conf_hosts])
150150

@@ -176,8 +176,8 @@ def destroy_ovs_bridge(session, args):
176176
# Note that the bridge has been removed on xapi network object
177177
xs_nw_uuid = lib.do_cmd([xePath, "network-list",
178178
"bridge=%s" % bridge, "--minimal"])
179-
lib.do_cmd([xePath,"network-param-set", "uuid=%s" % xs_nw_uuid,
180-
"other-config:ovs-setup=False"])
179+
#lib.do_cmd([xePath,"network-param-set", "uuid=%s" % xs_nw_uuid,
180+
# "other-config:ovs-setup=False"])
181181
result = "SUCCESS:%s" %bridge
182182

183183
logging.debug("Destroy_ovs_bridge completed with result:%s" %result)

scripts/vm/hypervisor/xenserver/xenserver56fp1/patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
NFSSR.py=/opt/xensource/sm
1313
vmops=..,0755,/etc/xapi.d/plugins
1414
xen-ovs-vif-flows.rules=..,0644,/etc/udev/rules.d
15-
ovs-vif-flows.py=.,0755,/etc/xapi.d/plugins
15+
ovs-vif-flows.py=..,0755,/etc/xapi.d/plugins
1616
cloudstack_plugins.conf=..,0644,/etc/xensource
1717
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
1818
ovsgre=..,0755,/etc/xapi.d/plugins

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

Lines changed: 0 additions & 79 deletions
This file was deleted.

scripts/vm/hypervisor/xenserver/xenserver60/patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
NFSSR.py=/opt/xensource/sm
1313
vmops=..,0755,/etc/xapi.d/plugins
1414
xen-ovs-vif-flows.rules=..,0644,/etc/udev/rules.d
15-
ovs-vif-flows.py=.,0755,/etc/xapi.d/plugins
15+
ovs-vif-flows.py=..,0755,/etc/xapi.d/plugins
1616
cloudstack_plugins.conf=..,0644,/etc/xensource
1717
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
1818
ovsgre=..,0755,/etc/xapi.d/plugins

server/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ private void handleCreateTunnelAnswer(Answer[] answers){
129129
_tunnelNetworkDao.update(tunnel.getId(), tunnel);
130130
}
131131

132+
private int getGreKey(Network network) {
133+
int key = 0;
134+
try {
135+
//The GRE key is actually in the host part of the URI
136+
String keyStr = network.getBroadcastUri().getHost();
137+
// The key is most certainly and int.
138+
// So we feel quite safe in converting it into a string
139+
key = Integer.valueOf(keyStr);
140+
return key;
141+
} catch (NumberFormatException e) {
142+
s_logger.debug("Well well, how did '" + key +
143+
"' end up in the broadcast URI for the network?");
144+
throw new CloudRuntimeException(
145+
String.format("Invalid GRE key parsed from network broadcast URI (%s)",
146+
network.getBroadcastUri().toString()));
147+
}
148+
}
149+
132150
@DB
133151
protected void CheckAndCreateTunnel(VirtualMachine instance, Network nw, DeployDestination dest) {
134152
if (!_isEnabled) {
@@ -143,18 +161,7 @@ protected void CheckAndCreateTunnel(VirtualMachine instance, Network nw, DeployD
143161
}
144162

145163
long hostId = dest.getHost().getId();
146-
int key = 0;
147-
try {
148-
//The GRE key is actually in the host part of the URI
149-
String keyStr = nw.getBroadcastUri().getHost();
150-
// The key is most certainly and int.
151-
// So we feel quite safe in converting it into a string
152-
key = Integer.valueOf(keyStr);
153-
} catch (NumberFormatException e) {
154-
s_logger.debug("Well well, how did '" + key +
155-
"' end up in the broadcast URI for the network?");
156-
s_logger.warn("Unable to create GRE tunnels on host:" + hostId);
157-
}
164+
int key = getGreKey(nw);
158165
// Find active (i.e.: not shut off) VMs with a NIC on the target network
159166
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(nw.getId(), State.Running, State.Starting,
160167
State.Stopping, State.Unknown, State.Migrating);
@@ -198,7 +205,7 @@ protected void CheckAndCreateTunnel(VirtualMachine instance, Network nw, DeployD
198205
}
199206
}
200207
}
201-
208+
//FIXME: Why are we cancelling the exception here?
202209
try {
203210
String myIp = dest.getHost().getPrivateIpAddress();
204211
boolean noHost = true;
@@ -337,19 +344,23 @@ public void CheckAndDestroyTunnel(VirtualMachine vm, Network nw) {
337344
try {
338345
/* Now we are last one on host, destroy the bridge with all
339346
* the tunnels for this network */
340-
Command cmd = new OvsDestroyBridgeCommand(nw.getId());
347+
int key = getGreKey(nw);
348+
Command cmd = new OvsDestroyBridgeCommand(nw.getId(), key);
341349
s_logger.debug("### Destroying bridge for network " + nw.getId() + " on host:" + vm.getHostId());
342350
Answer ans = _agentMgr.send(vm.getHostId(), cmd);
343351
handleDestroyBridgeAnswer(ans, vm.getHostId(), nw.getId());
344352

345353
/* Then ask hosts have peer tunnel with me to destroy them */
346354
List<OvsTunnelNetworkVO> peers = _tunnelNetworkDao.listByToNetwork(vm.getHostId(), nw.getId());
347355
for (OvsTunnelNetworkVO p : peers) {
348-
cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), p.getPortName());
349-
s_logger.debug("### Destroying tunnel to " + vm.getHostId() +
350-
" from " + p.getFrom());
351-
ans = _agentMgr.send(p.getFrom(), cmd);
352-
handleDestroyTunnelAnswer(ans, p.getFrom(), p.getTo(), p.getNetworkId());
356+
// If the tunnel was not successfully created don't bother to remove it
357+
if (p.getState().equals("SUCCESS")) {
358+
cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), key, p.getPortName());
359+
s_logger.debug("### Destroying tunnel to " + vm.getHostId() +
360+
" from " + p.getFrom());
361+
ans = _agentMgr.send(p.getFrom(), cmd);
362+
handleDestroyTunnelAnswer(ans, p.getFrom(), p.getTo(), p.getNetworkId());
363+
}
353364
}
354365
} catch (Exception e) {
355366
s_logger.warn(String.format("Destroy tunnel(account:%1$s, hostId:%2$s) failed", vm.getAccountId(), vm.getHostId()), e);

0 commit comments

Comments
 (0)