if (!Arrays.asList(supportedTrafficTypes).contains(trafficType)) {
throw new CloudException("Traffic type " + trafficType.toString() + " for nic " + nicTo.toString() + " is not supported.");
}
String switchName = null;
VirtualSwitchType switchType = VirtualSwitchType.StandardVirtualSwitch;
String vlanToken = Vlan.UNTAGGED;
// Get switch details from the nicTO object
if(nicTo.getName() != null && !nicTo.getName().isEmpty()) {
String[] tokens = nicTo.getName().split(",");
// Format of network traffic label is <VSWITCH>,<VLANID>,<VSWITCHTYPE>
// If all 3 fields are mentioned then number of tokens would be 3.
// If only <VSWITCH>,<VLANID> are mentioned then number of tokens would be 2.
switchName = tokens[0];
if(tokens.length == 2 || tokens.length == 3) {
vlanToken = tokens[1];
if (vlanToken.isEmpty()) {
vlanToken = Vlan.UNTAGGED;
}
if (tokens.length == 3) {
switchType = VirtualSwitchType.getType(tokens[2]);
}
}
} else {
if (trafficType == TrafficType.Guest && _guestTrafficInfo != null) {
switchType = _guestTrafficInfo.getVirtualSwitchType();
switchName = _guestTrafficInfo.getVirtualSwitchName();
} else if (trafficType == TrafficType.Public && _publicTrafficInfo != null) {
switchType = _publicTrafficInfo.getVirtualSwitchType();
switchName = _publicTrafficInfo.getVirtualSwitchName();
}
}
if (switchName == null
&& (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management || nicTo.getType() == Networks.TrafficType.Storage)) {
switchName = _privateNetworkVSwitchName;
}
return new Ternary<String,String,String>(switchName, switchType.toString(), vlanToken);
}