diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 0064edf6a68..dc8bf9d86f7 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -125,6 +125,7 @@ import com.cloud.agent.api.PlugNicAnswer; import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.PrepareForMigrationAnswer; import com.cloud.agent.api.PrepareForMigrationCommand; +import com.cloud.agent.api.PvlanSetupCommand; import com.cloud.agent.api.ReadyAnswer; import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.RebootAnswer; @@ -267,6 +268,8 @@ ServerResource { private String _createTmplPath; private String _heartBeatPath; private String _securityGroupPath; + private String _ovsPvlanDhcpHostPath; + private String _ovsPvlanVmPath; private String _routerProxyPath; private String _host; private String _dcId; @@ -587,6 +590,18 @@ ServerResource { "Unable to find the router_proxy.sh"); } + _ovsPvlanDhcpHostPath = Script.findScript(networkScriptsDir, "ovs-pvlan-dhcp-host.sh"); + if ( _ovsPvlanDhcpHostPath == null) { + throw new ConfigurationException( + "Unable to find the ovs-pvlan-dhcp-host.sh"); + } + + _ovsPvlanVmPath = Script.findScript(networkScriptsDir, "ovs-pvlan-vm.sh"); + if ( _ovsPvlanVmPath == null) { + throw new ConfigurationException( + "Unable to find the ovs-pvlan-vm.sh"); + } + String value = (String) params.get("developer"); boolean isDeveloper = Boolean.parseBoolean(value); @@ -1202,6 +1217,8 @@ ServerResource { return execute((CheckNetworkCommand) cmd); } else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) { return execute((NetworkRulesVmSecondaryIpCommand) cmd); + } else if (cmd instanceof PvlanSetupCommand) { + return execute((PvlanSetupCommand) cmd); } else { s_logger.warn("Unsupported command "); return Answer.createUnsupportedCommandAnswer(cmd); @@ -1517,6 +1534,65 @@ ServerResource { } } + private Answer execute(PvlanSetupCommand cmd) { + String primaryPvlan = cmd.getPrimary(); + String isolatedPvlan = cmd.getIsolated(); + String op = cmd.getOp(); + String dhcpName = cmd.getDhcpName(); + String dhcpMac = cmd.getDhcpMac(); + String dhcpIp = cmd.getDhcpIp(); + String vmMac = cmd.getVmMac(); + boolean add = true; + + String opr = "-A"; + if (op.equals("delete")) { + opr = "-D"; + add = false; + } + + String result = null; + Connect conn; + try { + if (cmd.getType() == PvlanSetupCommand.Type.DHCP) { + Script script = new Script(_ovsPvlanDhcpHostPath, _timeout, s_logger); + if (add) { + conn = LibvirtConnection.getConnectionByVmName(dhcpName); + List ifaces = getInterfaces(conn, dhcpName); + InterfaceDef guestNic = ifaces.get(0); + script.add(opr, "-b", _guestBridgeName, + "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName, + "-d", dhcpIp, "-m", dhcpMac, "-I", guestNic.getDevName()); + } else { + script.add(opr, "-b", _guestBridgeName, + "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName, + "-d", dhcpIp, "-m", dhcpMac); + } + result = script.execute(); + if (result != null) { + s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); + return new Answer(cmd, false, result); + } else { + s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); + } + } else if (cmd.getType() == PvlanSetupCommand.Type.VM) { + Script script = new Script(_ovsPvlanVmPath, _timeout, s_logger); + script.add(opr, "-b", _guestBridgeName, + "-p", primaryPvlan, "-i", isolatedPvlan, "-v", vmMac); + result = script.execute(); + if (result != null) { + s_logger.warn("Failed to program pvlan for vm with mac " + vmMac); + return new Answer(cmd, false, result); + } else { + s_logger.info("Programmed pvlan for vm with mac " + vmMac); + } + } + } catch (LibvirtException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new Answer(cmd, true, result); + } + private void VifHotPlug(Connect conn, String vmName, String vlanId, String macAddr) throws InternalErrorException, LibvirtException { NicTO nicTO = new NicTO(); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java index 37761aa5555..ac226e212e5 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java @@ -79,7 +79,7 @@ public class OvsVifDriver extends VifDriverBase { } String trafficLabel = nic.getName(); if (nic.getType() == Networks.TrafficType.Guest) { - if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan + if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) && !vlanId.equalsIgnoreCase("untagged")) { if(trafficLabel != null && !trafficLabel.isEmpty()) { s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); diff --git a/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh b/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh similarity index 92% rename from scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh rename to scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh index a30b180bed0..6b30ee62a06 100755 --- a/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh +++ b/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh @@ -22,5 +22,4 @@ bridge=$1 dhcp_name=$2 dom_id=`xe vm-list is-control-domain=false power-state=running params=dom-id name-label=$dhcp_name|cut -d ':' -f 2 |tr -d ' ' ` iface="vif${dom_id}.0" -port=`ovs-ofctl show $bridge|grep $iface|cut -d '(' -f 1|tr -d ' '` -echo $port +echo $iface diff --git a/scripts/vm/hypervisor/xenserver/ovs-pvlan b/scripts/vm/hypervisor/xenserver/ovs-pvlan index 956ea6d7978..c821870d64d 100755 --- a/scripts/vm/hypervisor/xenserver/ovs-pvlan +++ b/scripts/vm/hypervisor/xenserver/ovs-pvlan @@ -34,7 +34,7 @@ xePath = "/opt/xensource/bin/xe" lib.setup_logging("/var/log/ovs-pvlan.log") dhcpSetupPath = "/opt/xensource/bin/ovs-pvlan-dhcp-host.sh" vmSetupPath = "/opt/xensource/bin/ovs-pvlan-vm.sh" -getDhcpPortPath = "/opt/xensource/bin/ovs-get-dhcp-port.sh" +getDhcpIfacePath = "/opt/xensource/bin/ovs-get-dhcp-iface.sh" pvlanCleanupPath = "/opt/xensource/bin/ovs-pvlan-cleanup.sh" getBridgePath = "/opt/xensource/bin/ovs-get-bridge.sh" @@ -67,11 +67,11 @@ def setup_pvlan_dhcp(session, args): if op == "add": logging.debug("Try to get dhcp vm %s port on the switch:%s" % (dhcp_name, bridge)) - dhcp_port = lib.do_cmd([getDhcpPortPath, bridge, dhcp_name]) + dhcp_iface = lib.do_cmd([getDhcpIfacePath, bridge, dhcp_name]) logging.debug("About to setup dhcp vm on the switch:%s" % bridge) res = lib.do_cmd([dhcpSetupPath, "-A", "-b", bridge, "-p", primary, "-i", isolated, "-n", dhcp_name, "-d", dhcp_ip, "-m", dhcp_mac, - "-P", dhcp_port]) + "-I", dhcp_iface]) if res: result = "FAILURE:%s" % res return result; diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index fe36ba9cb84..9af32b1457a 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -71,5 +71,5 @@ ovs-pvlan=..,0755,/etc/xapi.d/plugins ovs-pvlan-dhcp-host.sh=../../../network,0755,/opt/xensource/bin ovs-pvlan-vm.sh=../../../network,0755,/opt/xensource/bin ovs-pvlan-cleanup.sh=../../../network,0755,/opt/xensource/bin -ovs-get-dhcp-port.sh=..,0755,/opt/xensource/bin +ovs-get-dhcp-iface.sh=..,0755,/opt/xensource/bin ovs-get-bridge.sh=..,0755,/opt/xensource/bin diff --git a/scripts/vm/network/ovs-pvlan-dhcp-host.sh b/scripts/vm/network/ovs-pvlan-dhcp-host.sh index 93f56534beb..73d735f822e 100755 --- a/scripts/vm/network/ovs-pvlan-dhcp-host.sh +++ b/scripts/vm/network/ovs-pvlan-dhcp-host.sh @@ -18,10 +18,8 @@ #!/bin/bash -source ovs-func.sh - usage() { - printf "Usage: %s: (-A|-D) -b -p -i -n -d -m -P -v -h \n" $(basename $0) >&2 + printf "Usage: %s: (-A|-D) -b -p -i -n -d -m -I -v -h \n" $(basename $0) >&2 exit 2 } @@ -31,11 +29,11 @@ sec_iso_vlan= dhcp_name= dhcp_ip= dhcp_mac= -dhcp_port= vm_mac= +iface= op= -while getopts 'ADb:p:i:d:m:v:n:P:h' OPTION +while getopts 'ADb:p:i:d:m:v:n:I:h' OPTION do case $OPTION in A) op="add" @@ -54,7 +52,7 @@ do ;; m) dhcp_mac="$OPTARG" ;; - P) dhcp_port="$OPTARG" + I) iface="$OPTARG" ;; v) vm_mac="$OPTARG" ;; @@ -106,14 +104,15 @@ then exit 1 fi -if [ "$op" == "add" -a -z "$dhcp_port" ] +if [ "$op" == "add" -a -z "$iface" ] then - echo Missing parameter DHCP PORT! + echo Missing parameter DHCP VM interface! exit 1 fi if [ "$op" == "add" ] then + dhcp_port=`ovs-ofctl show $br | grep $iface | cut -d '(' -f 1|tr -d ' '` ovs-ofctl add-flow $br priority=200,arp,dl_vlan=$sec_iso_vlan,nw_dst=$dhcp_ip,actions=strip_vlan,output:$dhcp_port ovs-ofctl add-flow $br priority=180,arp,nw_dst=$dhcp_ip,actions=strip_vlan,output:$dhcp_port ovs-ofctl add-flow $br priority=150,dl_vlan=$sec_iso_vlan,dl_dst=$dhcp_mac,actions=strip_vlan,output:$dhcp_port