Skip to content

Commit 40386fc

Browse files
author
Sheng Yang
committed
PVLAN: Add network label parameter to PvlanSetupCommand
We need it to find the real bridge/switch to program on the OVS.
1 parent 142f3b3 commit 40386fc

8 files changed

Lines changed: 72 additions & 13 deletions

File tree

‎api/src/com/cloud/agent/api/PvlanSetupCommand.java‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,31 @@ public enum Type {
3333
private String dhcpMac;
3434
private String dhcpIp;
3535
private Type type;
36+
private String networkTag;
3637

3738
protected PvlanSetupCommand() {}
3839

39-
protected PvlanSetupCommand(Type type, String op, URI uri)
40+
protected PvlanSetupCommand(Type type, String op, URI uri, String networkTag)
4041
{
4142
this.type = type;
4243
this.op = op;
4344
this.primary = NetUtils.getPrimaryPvlanFromUri(uri);
4445
this.isolated = NetUtils.getIsolatedPvlanFromUri(uri);
46+
this.networkTag = networkTag;
4547
}
4648

47-
static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String dhcpName, String dhcpMac, String dhcpIp)
49+
static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String networkTag, String dhcpName, String dhcpMac, String dhcpIp)
4850
{
49-
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri);
51+
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri, networkTag);
5052
cmd.setDhcpName(dhcpName);
5153
cmd.setDhcpMac(dhcpMac);
5254
cmd.setDhcpIp(dhcpIp);
5355
return cmd;
5456
}
5557

56-
static public PvlanSetupCommand createVmSetup(String op, URI uri, String vmMac)
58+
static public PvlanSetupCommand createVmSetup(String op, URI uri, String networkTag, String vmMac)
5759
{
58-
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri);
60+
PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri, networkTag);
5961
cmd.setVmMac(vmMac);
6062
return cmd;
6163
}
@@ -112,4 +114,8 @@ public String getDhcpName() {
112114
public void setDhcpName(String dhcpName) {
113115
this.dhcpName = dhcpName;
114116
}
117+
118+
public String getNetworkTag() {
119+
return networkTag;
120+
}
115121
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,24 @@ private Answer execute(PvlanSetupCommand cmd) {
14781478
String dhcpMac = cmd.getDhcpMac();
14791479
String dhcpIp = cmd.getDhcpIp();
14801480
String vmMac = cmd.getVmMac();
1481+
String networkTag = cmd.getNetworkTag();
1482+
1483+
XsLocalNetwork nw = null;
1484+
String nwNameLabel = null;
1485+
try {
1486+
nw = getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
1487+
nwNameLabel = nw.getNetwork().getNameLabel(conn);
1488+
} catch (XenAPIException e) {
1489+
s_logger.warn("Fail to get network", e);
1490+
return new Answer(cmd, false, e.toString());
1491+
} catch (XmlRpcException e) {
1492+
s_logger.warn("Fail to get network", e);
1493+
return new Answer(cmd, false, e.toString());
1494+
}
14811495

1482-
String bridge = "xenbr0";
14831496
String result = null;
14841497
if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
1485-
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "bridge", bridge,
1498+
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel,
14861499
"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName,
14871500
"dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
14881501
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
@@ -1492,7 +1505,7 @@ private Answer execute(PvlanSetupCommand cmd) {
14921505
s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
14931506
}
14941507
} else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
1495-
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "bridge", bridge,
1508+
result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel,
14961509
"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
14971510
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
14981511
s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
nw_label=$1
20+
br=`xe network-list name-label="$nw_label" params=bridge |cut -d ':' -f 2 |tr -d ' ' `
21+
pbr=`ovs-vsctl br-to-parent $br`
22+
while [ "$br" != "$pbr" ]
23+
do
24+
br=$pbr
25+
pbr=`ovs-vsctl br-to-parent $br`
26+
done
27+
echo $pbr

‎scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh‎

100644100755
File mode changed.

‎scripts/vm/hypervisor/xenserver/ovs-pvlan‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dhcpSetupPath = "/opt/xensource/bin/ovs-pvlan-dhcp-host.sh"
3636
vmSetupPath = "/opt/xensource/bin/ovs-pvlan-vm.sh"
3737
getDhcpPortPath = "/opt/xensource/bin/ovs-get-dhcp-port.sh"
3838
pvlanCleanupPath = "/opt/xensource/bin/ovs-pvlan-cleanup.sh"
39+
getBridgePath = "/opt/xensource/bin/ovs-get-bridge.sh"
3940

4041
def echo(fn):
4142
def wrapped(*v, **k):
@@ -46,11 +47,10 @@ def echo(fn):
4647
return res
4748
return wrapped
4849

49-
5050
@echo
5151
def setup_pvlan_dhcp(session, args):
5252
op = args.pop("op")
53-
bridge = args.pop("bridge")
53+
nw_label = args.pop("nw-label")
5454
primary = args.pop("primary-pvlan")
5555
isolated = args.pop("isolated-pvlan")
5656
dhcp_name = args.pop("dhcp-name")
@@ -61,6 +61,10 @@ def setup_pvlan_dhcp(session, args):
6161
if res != "SUCCESS":
6262
return "FAILURE:%s" % res
6363

64+
logging.debug("Network is:%s" % (nw_label))
65+
bridge = lib.do_cmd([getBridgePath, nw_label])
66+
logging.debug("Determine bridge/switch is :%s" % (bridge))
67+
6468
if op == "add":
6569
logging.debug("Try to get dhcp vm %s port on the switch:%s" % (dhcp_name, bridge))
6670
dhcp_port = lib.do_cmd([getDhcpPortPath, bridge, dhcp_name])
@@ -88,7 +92,7 @@ def setup_pvlan_dhcp(session, args):
8892
@echo
8993
def setup_pvlan_vm(session, args):
9094
op = args.pop("op")
91-
bridge = args.pop("bridge")
95+
nw_label = args.pop("nw-label")
9296
primary = args.pop("primary-pvlan")
9397
isolated = args.pop("isolated-pvlan")
9498
vm_mac = args.pop("vm-mac")
@@ -98,6 +102,9 @@ def setup_pvlan_vm(session, args):
98102
if res != "SUCCESS":
99103
return "FAILURE:%s" % res
100104

105+
bridge = lib.do_cmd([getBridgePath, nw_label])
106+
logging.debug("Determine bridge/switch is :%s" % (bridge))
107+
101108
if op == "add":
102109
logging.debug("About to setup vm on the switch:%s" % bridge)
103110
res = lib.do_cmd([vmSetupPath, "-A", "-b", bridge, "-p", primary, "-i", isolated, "-v", vm_mac])

‎scripts/vm/hypervisor/xenserver/xenserver60/patch‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ ovs-pvlan-dhcp-host.sh=../../../network,0755,/opt/xensource/bin
7272
ovs-pvlan-vm.sh=../../../network,0755,/opt/xensource/bin
7373
ovs-pvlan-cleanup.sh=../../../network,0755,/opt/xensource/bin
7474
ovs-get-dhcp-port.sh=..,0755,/opt/xensource/bin
75+
ovs-get-bridge.sh=..,0755,/opt/xensource/bin

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,9 @@ private boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Nic nic) {
22192219
if (!add) {
22202220
op = "delete";
22212221
}
2222-
PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(), router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
2222+
Network network = _networkDao.findById(nic.getNetworkId());
2223+
String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
2224+
PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
22232225
Commands cmds = new Commands(cmd);
22242226
// In fact we send command to the host of router, we're not programming router but the host
22252227
try {

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,10 @@ private boolean setupVmForPvlan(boolean add, Long hostId, NicVO nic) {
27612761
// "delete" would remove all the rules(if using ovs) related to this vm
27622762
op = "delete";
27632763
}
2764-
PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadcastUri(), nic.getMacAddress());
2764+
Network network = _networkDao.findById(nic.getNetworkId());
2765+
Host host = _hostDao.findById(hostId);
2766+
String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
2767+
PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadcastUri(), networkTag, nic.getMacAddress());
27652768
Answer answer = null;
27662769
try {
27672770
answer = _agentMgr.send(hostId, cmd);

0 commit comments

Comments
 (0)