Skip to content

Commit 8987499

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 ac052ed commit 8987499

8 files changed

Lines changed: 131 additions & 69 deletions

File tree

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

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

1717
public class OvsCreateTunnelCommand extends Command {
18-
String key;
18+
Integer key;
1919
String remoteIp;
2020
Long from;
2121
Long to;
@@ -29,7 +29,7 @@ public boolean executeInSequence() {
2929
return true;
3030
}
3131

32-
public OvsCreateTunnelCommand(String remoteIp, String key, Long from, Long to, long networkId, String fromIp) {
32+
public OvsCreateTunnelCommand(String remoteIp, Integer key, Long from, Long to, long networkId, String fromIp) {
3333
this.remoteIp = remoteIp;
3434
this.key = key;
3535
this.from = from;
@@ -38,7 +38,7 @@ public OvsCreateTunnelCommand(String remoteIp, String key, Long from, Long to, l
3838
this.fromIp = fromIp;
3939
}
4040

41-
public String getKey() {
41+
public Integer getKey() {
4242
return key;
4343
}
4444

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.network.ovs;
20+
21+
import com.cloud.agent.api.Command;
22+
23+
public class OvsSetupBridgeCommand extends Command {
24+
Integer key;
25+
Long hostId;
26+
Long networkId;
27+
28+
@Override
29+
public boolean executeInSequence() {
30+
return true;
31+
}
32+
33+
public OvsSetupBridgeCommand(Integer key, Long hostId, Long networkId) {
34+
this.key = key;
35+
this.hostId = hostId;
36+
this.networkId = networkId;
37+
}
38+
39+
public Integer getKey() {
40+
return key;
41+
}
42+
43+
public Long getHostId() {
44+
return hostId;
45+
}
46+
47+
public Long getNetworkId() {
48+
return networkId;
49+
}
50+
51+
}

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

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
import com.cloud.network.ovs.OvsDestroyTunnelCommand;
182182
import com.cloud.network.ovs.OvsSetTagAndFlowAnswer;
183183
import com.cloud.network.ovs.OvsSetTagAndFlowCommand;
184+
import com.cloud.network.ovs.OvsSetupBridgeCommand;
184185
import com.cloud.resource.ServerResource;
185186
import com.cloud.resource.hypervisor.HypervisorResource;
186187
import com.cloud.storage.Storage;
@@ -617,7 +618,7 @@ private synchronized Network setupvSwitchNetwork(Connection conn) {
617618
/**
618619
* This method just creates a XenServer network following the tunnel network naming convention
619620
*/
620-
private synchronized Network createTunnelNetwork(Connection conn, long networkId) {
621+
private synchronized Network findOrCreateTunnelNetwork(Connection conn, long networkId) {
621622
try {
622623
String nwName = "OVSTunnel" + networkId;
623624
Network nw = null;
@@ -632,11 +633,13 @@ private synchronized Network createTunnelNetwork(Connection conn, long networkId
632633
otherConfig.put("ovs-host-setup", "");
633634
rec.otherConfig = otherConfig;
634635
nw = Network.create(conn, rec);
636+
// Plug dom0 vif only when creating network
637+
enableXenServerNetwork(conn, nw, nwName, "tunnel network for account " + networkId);
638+
s_logger.debug("### Xen Server network for tunnels created:" + nwName);
635639
} else {
636640
nw = networks.iterator().next();
641+
s_logger.debug("### Xen Server network for tunnels found:" + nwName);
637642
}
638-
enableXenServerNetwork(conn, nw, nwName, "tunnel network for account " + networkId);
639-
s_logger.debug("### Xen Server network for tunnels created:" + nwName);
640643
return nw;
641644
} catch (Exception e) {
642645
s_logger.warn("createTunnelNetwork failed", e);
@@ -647,9 +650,9 @@ private synchronized Network createTunnelNetwork(Connection conn, long networkId
647650
/**
648651
* This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
649652
*/
650-
private synchronized Network createAndConfigureTunnelNetwork(Connection conn, long networkId, long hostId) {
653+
private synchronized Network configureTunnelNetwork(Connection conn, long networkId, long hostId, int key) {
651654
try {
652-
Network nw = createTunnelNetwork(conn, networkId);
655+
Network nw = findOrCreateTunnelNetwork(conn, networkId);
653656
//Invoke plugin to setup the bridge which will be used by this network
654657
String bridge = nw.getBridge(conn);
655658
Map<String,String> nwOtherConfig = nw.getOtherConfig(conn);
@@ -666,7 +669,7 @@ private synchronized Network createAndConfigureTunnelNetwork(Connection conn, lo
666669
}
667670
if (!configured) {
668671
String result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge", "bridge", bridge,
669-
"key", String.valueOf(networkId),
672+
"key", String.valueOf(key),
670673
"xs_nw_uuid", nw.getUuid(conn),
671674
"cs_host_id", ((Long)hostId).toString());
672675
//Note down the fact that the ovs bridge has been setup
@@ -684,29 +687,9 @@ private synchronized Network createAndConfigureTunnelNetwork(Connection conn, lo
684687
}
685688
}
686689

687-
private synchronized Network findTunnelNetwork(Connection conn, long networkId) {
688-
try {
689-
String nwName = "OVSTunnel" + networkId;
690-
Network nw = null;
691-
Set<Network> networks = Network.getByNameLabel(conn, nwName);
692-
if (networks.size() == 0) {
693-
String errorMessage = "Unable to find OVS bridge for network:" + networkId;
694-
s_logger.error(errorMessage);
695-
throw new CloudRuntimeException(errorMessage);
696-
} else {
697-
nw = networks.iterator().next();
698-
}
699-
s_logger.debug("### Xen Server network for tunnels found:" + nwName);
700-
return nw;
701-
} catch (Exception e) {
702-
s_logger.warn("findTunnelNetwork failed:", e);
703-
return null;
704-
}
705-
}
706-
707690
private synchronized void destroyTunnelNetwork(Connection conn, long networkId) {
708691
try {
709-
Network nw = findTunnelNetwork(conn, networkId);
692+
Network nw = findOrCreateTunnelNetwork(conn, networkId);
710693
String bridge = nw.getBridge(conn);
711694
String result = callHostPlugin(conn, "ovstunnel", "destroy_ovs_bridge", "bridge", bridge);
712695
String[] res = result.split(":");
@@ -747,7 +730,7 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
747730
return setupvSwitchNetwork(conn);
748731
} else {
749732
long networkId = Long.parseLong(nic.getBroadcastUri().getHost());
750-
return createTunnelNetwork(conn, networkId);
733+
return findOrCreateTunnelNetwork(conn, networkId);
751734
}
752735
} else if (nic.getBroadcastType() == BroadcastDomainType.Storage) {
753736
URI broadcastUri = nic.getBroadcastUri();
@@ -4802,6 +4785,16 @@ protected boolean can_bridge_firewall(Connection conn) {
48024785
return Boolean.valueOf(callHostPlugin(conn, "vmops", "can_bridge_firewall", "host_uuid", _host.uuid, "instance", _instance));
48034786
}
48044787

4788+
4789+
private Answer execute(OvsSetupBridgeCommand cmd) {
4790+
Connection conn = getConnection();
4791+
s_logger.debug("### About to configure OVS bridge");
4792+
Network nw=findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
4793+
this.configureTunnelNetwork(conn, cmd.getNetworkId(), cmd.getHostId(), cmd.getKey());
4794+
s_logger.debug("### Bridge configured");
4795+
return new Answer(cmd, true, null);
4796+
}
4797+
48054798
private Answer execute(OvsDestroyBridgeCommand cmd) {
48064799
Connection conn = getConnection();
48074800
s_logger.debug("### About to destroy OVS bridge");
@@ -4814,7 +4807,7 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
48144807
Connection conn = getConnection();
48154808
s_logger.debug("### About to destroy tunnel network");
48164809
try {
4817-
Network nw = findTunnelNetwork(conn, cmd.getNetworkId());
4810+
Network nw = findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
48184811
if (nw == null) {
48194812
s_logger.warn("### Unable to find tunnel network");
48204813
return new Answer(cmd, false, "No network found");
@@ -4846,16 +4839,17 @@ private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
48464839
String bridge = "unknown";
48474840
try {
48484841
s_logger.debug("### About to create tunnel network");
4849-
Network nw = createAndConfigureTunnelNetwork(conn, cmd.getNetworkId(), cmd.getFrom());
4842+
Network nw = findOrCreateTunnelNetwork(conn, cmd.getNetworkId());
48504843
if (nw == null) {
48514844
s_logger.debug("### SOMETHING WENT WRONG DURING NETWORK SETUP");
48524845
return new OvsCreateTunnelAnswer(cmd, false, "Cannot create network", bridge);
48534846
}
4854-
4847+
4848+
configureTunnelNetwork(conn, cmd.getNetworkId(), cmd.getFrom(), cmd.getKey());
48554849
bridge = nw.getBridge(conn);
48564850
s_logger.debug("### The bridge is:" + bridge);
4857-
String result = callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", cmd.getRemoteIp(), "key", cmd.getKey(), "from", cmd.getFrom().toString(), "to", cmd
4858-
.getTo().toString());
4851+
String result = callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", cmd.getRemoteIp(),
4852+
"key", cmd.getKey().toString(), "from", cmd.getFrom().toString(), "to", cmd.getTo().toString());
48594853
s_logger.debug("### Result from create tunnel operation:" + result);
48604854
String[] res = result.split(":");
48614855
if (res.length == 2 && res[0].equalsIgnoreCase("SUCCESS")) {

scripts/vm/hypervisor/xenserver/ovstunnel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ def setup_ovs_bridge(session, args):
155155
version_cmd = [lib.XE_PATH, 'host-param-get', 'uuid=%s' % host_uuid,
156156
'param-name=software-version',
157157
'param-key=product_version']
158-
version = lib.do_cmd(version_cmd)
158+
version = lib.do_cmd(version_cmd).split('.')[0]
159159
block_ipv6_handlers[version](bridge)
160-
lib.add_flow(bridge, priority=65000, proto='ipv6', actions='drop')
161160
logging.debug("Setup_ovs_bridge completed with result:%s" %result)
162161
return result
163162

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/network/NetworkManagerImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,30 +4827,33 @@ public PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List<
48274827
// for GRE phynets allow up to 32bits
48284828
// TODO: Not happy about this test.
48294829
// What about guru-like objects for physical networs?
4830+
s_logger.debug("ISOLATION METHODS:" + network.getIsolationMethods());
4831+
// Java does not have unsigned types...
48304832
if (network.getIsolationMethods().contains("GRE")) {
4831-
maxVnet = 2^32 - 1;
4833+
maxVnet = (int)(Math.pow(2, 32)-1);
48324834
}
4835+
String rangeMessage = " between 0 and " + maxVnet;
48334836
if (newVnetRange.length < 2) {
4834-
throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096");
4837+
throw new InvalidParameterValueException("Please provide valid vnet range" + rangeMessage);
48354838
}
48364839

48374840
if (newVnetRange[0] == null || newVnetRange[1] == null) {
4838-
throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096");
4841+
throw new InvalidParameterValueException("Please provide valid vnet range" + rangeMessage);
48394842
}
48404843

48414844
try {
48424845
newStartVnet = Integer.parseInt(newVnetRange[0]);
48434846
newEndVnet = Integer.parseInt(newVnetRange[1]);
48444847
} catch (NumberFormatException e) {
48454848
s_logger.warn("Unable to parse vnet range:", e);
4846-
throw new InvalidParameterValueException("Please provide valid vnet range between 0-4096");
4849+
throw new InvalidParameterValueException("Please provide valid vnet range" + rangeMessage);
48474850
}
48484851
if (newStartVnet < 0 || newEndVnet > maxVnet) {
4849-
throw new InvalidParameterValueException("Vnet range has to be between 0-4096");
4852+
throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage);
48504853
}
48514854

48524855
if (newStartVnet > newEndVnet) {
4853-
throw new InvalidParameterValueException("Vnet range has to be between 0-4096 and start range should be lesser than or equal to stop range");
4856+
throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage + " and start range should be lesser than or equal to stop range");
48544857
}
48554858

48564859
if (physicalNetworkHasAllocatedVnets(network.getDataCenterId(), network.getId())) {

server/src/com/cloud/network/guru/OvsGuestNetworkGuru.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ protected void allocateVnet(Network network, NetworkVO implemented, long dcId,
7373
if (vnet == null) {
7474
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId);
7575
}
76-
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vnet));
76+
String vnetUri = null;
77+
if (_ovsNetworkMgr.isOvsNetworkEnabled()) {
78+
vnetUri = "vlan" + vnet;
79+
} else if (_ovsTunnelMgr.isOvsTunnelEnabled()) {
80+
vnetUri = vnet;
81+
}
82+
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vnetUri));
83+
s_logger.debug("### URI value:" + vnetUri);
7784
EventUtils.saveEvent(UserContext.current().getCallerUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: "+vnet+ " Network Id: "+network.getId(), 0);
7885
} else {
7986
implemented.setBroadcastUri(network.getBroadcastUri());
@@ -89,15 +96,6 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
8996
s_logger.debug("### Implementing network:" + config.getId() + " in OVS Guest Network Guru");
9097
// The above call will NOT reserve a Vnet
9198
NetworkVO implemented = (NetworkVO)super.implement(config, offering, dest, context);
92-
String uri = null;
93-
if (_ovsNetworkMgr.isOvsNetworkEnabled()) {
94-
uri = "vlan";
95-
} else if (_ovsTunnelMgr.isOvsTunnelEnabled()) {
96-
uri = Long.toString(config.getId());
97-
}
98-
s_logger.debug("### URI value:" + uri);
99-
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(uri));
100-
s_logger.debug("### Broadcast URI is:" + implemented.getBroadcastUri().toString());
10199
return implemented;
102100
}
103101

0 commit comments

Comments
 (0)