Skip to content

Commit a0ade28

Browse files
committed
Summary: Add initial support for OpenVswitch to the KVM hypervisor
Create OvsVifDriver to deal with openvswitch specifics for plugging intefaces Create a parameter to set the bridge type to use in LibvirtComputingResource. Create several functions to get bridge information from openvswitch Add a check to detect the libvirt version and throw an exception when the version is to low ( < 0.9.11 ) Fix classpath loading in Script.findScript to deal with missing path separators at the end. Add notification to the BridgeVifDriver that lswitch broadcast type is not supported.
1 parent 0412cb8 commit a0ade28

5 files changed

Lines changed: 348 additions & 10 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType)
8585
URI broadcastUri = nic.getBroadcastUri();
8686
vlanId = broadcastUri.getHost();
8787
}
88+
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
89+
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
90+
}
8891
String trafficLabel = nic.getName();
8992
if (nic.getType() == Networks.TrafficType.Guest) {
9093
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,16 @@ protected String getDefaultScriptsDir() {
362362
private String _pingTestPath;
363363

364364
private int _dom0MinMem;
365+
366+
protected enum BridgeType {
367+
NATIVE, OPENVSWITCH
368+
}
365369

366370
protected enum defineOps {
367371
UNDEFINE_VM, DEFINE_VM
368372
}
373+
374+
protected BridgeType _bridgeType;
369375

370376
private String getEndIpFromStartIp(String startIp, int numIps) {
371377
String[] tokens = startIp.split("[.]");
@@ -474,6 +480,14 @@ public boolean configure(String name, Map<String, Object> params)
474480
if (storageScriptsDir == null) {
475481
storageScriptsDir = getDefaultStorageScriptsDir();
476482
}
483+
484+
String bridgeType = (String) params.get("network.bridge.type");
485+
if (bridgeType == null) {
486+
_bridgeType = BridgeType.NATIVE;
487+
}
488+
else {
489+
_bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
490+
}
477491

478492
params.put("domr.scripts.dir", domrScriptsDir);
479493

@@ -650,11 +664,19 @@ public boolean configure(String name, Map<String, Object> params)
650664

651665
LibvirtConnection.initialize(_hypervisorURI);
652666
Connect conn = null;
653-
try {
654-
conn = LibvirtConnection.getConnection();
655-
} catch (LibvirtException e) {
656-
throw new CloudRuntimeException(e.getMessage());
657-
}
667+
try {
668+
conn = LibvirtConnection.getConnection();
669+
670+
if (_bridgeType == BridgeType.OPENVSWITCH) {
671+
if (conn.getLibVirVersion() < (9 * 1000 + 11)) {
672+
throw new ConfigurationException(
673+
"LibVirt version 0.9.11 required for openvswitch support, but version "
674+
+ conn.getLibVirVersion() + " detected");
675+
}
676+
}
677+
} catch (LibvirtException e) {
678+
throw new CloudRuntimeException(e.getMessage());
679+
}
658680

659681
/* Does node support HVM guest? If not, exit */
660682
if (!IsHVMEnabled(conn)) {
@@ -697,7 +719,15 @@ public boolean configure(String name, Map<String, Object> params)
697719
}
698720
}
699721

700-
getPifs();
722+
switch (_bridgeType) {
723+
case NATIVE:
724+
getPifs();
725+
break;
726+
case OPENVSWITCH:
727+
getOvsPifs();
728+
break;
729+
}
730+
701731
if (_pifs.get("private") == null) {
702732
s_logger.debug("Failed to get private nic name");
703733
throw new ConfigurationException("Failed to get private nic name");
@@ -796,6 +826,26 @@ private void getPifs() {
796826
}
797827
s_logger.debug("done looking for pifs, no more bridges");
798828
}
829+
830+
private void getOvsPifs() {
831+
String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'");
832+
s_logger.debug("cmdout was " + cmdout);
833+
List<String> bridges = Arrays.asList(cmdout.split("%"));
834+
for (String bridge : bridges) {
835+
s_logger.debug("looking for pif for bridge " + bridge);
836+
//String pif = getOvsPif(bridge);
837+
// Not really interested in the pif name at this point for ovs bridges
838+
String pif = bridge;
839+
if(_publicBridgeName != null && bridge.equals(_publicBridgeName)){
840+
_pifs.put("public", pif);
841+
}
842+
if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) {
843+
_pifs.put("private", pif);
844+
}
845+
_pifs.put(bridge, pif);
846+
}
847+
s_logger.debug("done looking for pifs, no more bridges");
848+
}
799849

800850
private String getPif(String bridge) {
801851
String pif = Script.runSimpleBashScript("brctl show | grep " + bridge + " | awk '{print $4}'");
@@ -808,11 +858,29 @@ private String getPif(String bridge) {
808858
return pif;
809859
}
810860

861+
private String getOvsPif(String bridge) {
862+
String pif = Script.runSimpleBashScript("ovs-vsctl list-ports " + bridge);
863+
return pif;
864+
}
865+
811866
private boolean checkNetwork(String networkName) {
812867
if (networkName == null) {
813868
return true;
814869
}
815870

871+
if (_bridgeType == BridgeType.OPENVSWITCH) {
872+
return checkOvsNetwork(networkName);
873+
}
874+
else {
875+
return checkBridgeNetwork(networkName);
876+
}
877+
}
878+
879+
private boolean checkBridgeNetwork(String networkName) {
880+
if (networkName == null) {
881+
return true;
882+
}
883+
816884
String name = Script.runSimpleBashScript("brctl show | grep "
817885
+ networkName + " | awk '{print $4}'");
818886
if (name == null) {
@@ -821,6 +889,23 @@ private boolean checkNetwork(String networkName) {
821889
return true;
822890
}
823891
}
892+
893+
private boolean checkOvsNetwork(String networkName) {
894+
s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
895+
if (networkName == null) {
896+
return true;
897+
}
898+
899+
Script command = new Script("/bin/sh", _timeout);
900+
command.add("-c");
901+
command.add("ovs-vsctl br-exists " + networkName);
902+
String result = command.execute(null);
903+
if ("Ok".equals(result)) {
904+
return true;
905+
} else {
906+
return false;
907+
}
908+
}
824909

825910
private String getVnetId(String vnetId) {
826911
return vnetId;

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ enum hostNicType {
646646
private String _ipAddr;
647647
private String _scriptPath;
648648
private nicModel _model;
649+
private String _virtualPortType;
650+
private String _virtualPortInterfaceId;
649651

650652
public void defBridgeNet(String brName, String targetBrName,
651653
String macAddr, nicModel model) {
@@ -695,6 +697,22 @@ public String getDevName() {
695697
public String getMacAddress() {
696698
return _macAddr;
697699
}
700+
701+
public void setVirtualPortType(String virtualPortType) {
702+
_virtualPortType = virtualPortType;
703+
}
704+
705+
public String getVirtualPortType() {
706+
return _virtualPortType;
707+
}
708+
709+
public void setVirtualPortInterfaceId(String virtualPortInterfaceId) {
710+
_virtualPortInterfaceId = virtualPortInterfaceId;
711+
}
712+
713+
public String getVirtualPortInterfaceId() {
714+
return _virtualPortInterfaceId;
715+
}
698716

699717
@Override
700718
public String toString() {
@@ -714,6 +732,13 @@ public String toString() {
714732
if (_model != null) {
715733
netBuilder.append("<model type='" + _model + "'/>\n");
716734
}
735+
if (_virtualPortType != null) {
736+
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
737+
if (_virtualPortInterfaceId != null) {
738+
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
739+
}
740+
netBuilder.append("</virtualport>\n");
741+
}
717742
netBuilder.append("</interface>\n");
718743
return netBuilder.toString();
719744
}

0 commit comments

Comments
 (0)