if (intfs.size() == 0 || intfs.size() < nic.getDeviceId()) { return false; final InterfaceDef intf = intfs.get(nic.getDeviceId()); final String brname = intf.getBrName(); final String vif = intf.getDevName(); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); if (nic.getIp() != null) { cmd.add("--vmip", nic.getIp()); if (nic.getIp6Address() != null) { cmd.add("--vmip6", nic.getIp6Address()); cmd.add("--vmmac", nic.getMac()); cmd.add("--vif", vif); cmd.add("--brname", brname);
@Override public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); to.setType(profile.getTrafficType()); to.setIp(profile.getIPv4Address()); to.setNetmask(profile.getIPv4Netmask()); to.setMac(profile.getMacAddress()); to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); to.setGateway(profile.getIPv4Gateway()); to.setDefaultNic(profile.isDefaultNic()); to.setBroadcastUri(profile.getBroadCastUri()); to.setIsolationuri(profile.getIsolationUri()); to.setNetworkRateMbps(profile.getNetworkRate()); to.setName(profile.getName()); to.setSecurityGroupEnabled(profile.isSecurityGroupEnabled()); to.setIp6Address(profile.getIPv6Address()); to.setIp6Cidr(profile.getIPv6Cidr()); to.setNetworkUuid(network.getUuid()); to.setUuid(nicVO.getUuid()); to.setPxeDisable(true); to.setNicSecIps(secIps); } else { s_logger.warn("Unabled to load NicVO for NicProfile " + profile.getId());
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) { vNetId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); protocol = Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()).scheme(); if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) { vlanId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { logicalSwitchUuid = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) { vlanId = NetUtils.getPrimaryPvlanFromUri(nic.getBroadcastUri()); String trafficLabel = nic.getName(); Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; if (nic.getType() == Networks.TrafficType.Guest) { 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); intf.defEthernet("ivsnet-" + nic.getUuid().substring(0, 5), nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _ivsIfUpPath, networkRateKBps); } else { throw new InternalErrorException("no traffic label "); } else if (nic.getType() == Networks.TrafficType.Control) { intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter)); } else if (nic.getType() == Networks.TrafficType.Public) { if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
protected boolean defaultNetworkRulesForUserVm(String vmName, Long vmId, NicTO nic) throws XmlRpcException { if (!_canBridgeFirewall) { return false; } OvmVif.Details vif = getVifFromVm(vmName, nic.getDeviceId()); String ipAddress = nic.getIp(); String macAddress = vif.mac; String vifName = vif.name; String bridgeName = vif.bridge; return OvmSecurityGroup.defaultNetworkRulesForUserVm(_conn, vmName, String.valueOf(vmId), ipAddress, macAddress, vifName, bridgeName); }
private void VifHotPlug(final Connect conn, final String vmName, final String broadcastUri, final String macAddr) throws InternalErrorException, LibvirtException { final NicTO nicTO = new NicTO(); nicTO.setMac(macAddr); nicTO.setType(TrafficType.Public); if (broadcastUri == null) { nicTO.setBroadcastType(BroadcastDomainType.Native); } else { final URI uri = BroadcastDomainType.fromString(broadcastUri); nicTO.setBroadcastType(BroadcastDomainType.getSchemeValue(uri)); nicTO.setBroadcastUri(uri); } final Domain vm = getDomain(conn, vmName); vm.attachDevice(getVifDriver(nicTO.getType()).plug(nicTO, "Other PV", "", null).toString()); }
protected String getNetwork(NicTO nic) throws XmlRpcException { String vlanId = null; String bridgeName = null; if (nic.getBroadcastType() == BroadcastDomainType.Vlan) { vlanId = BroadcastDomainType.getValue(nic.getBroadcastUri()); } if (nic.getType() == TrafficType.Guest) { if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) { bridgeName = createVlanBridge(_guestNetworkName, vlanId); } else { bridgeName = _guestNetworkName; } } else if (nic.getType() == TrafficType.Control) { throw new CloudRuntimeException("local link network is not supported"); } else if (nic.getType() == TrafficType.Public) { throw new CloudRuntimeException("public network for system vm is not supported"); } else if (nic.getType() == TrafficType.Management) { bridgeName = _privateNetworkName; } else { throw new CloudRuntimeException("Unkonw network traffic type:" + nic.getType()); } return bridgeName; }
for(i = 0; i < nics.length; i++) { expandedNics[i] = nics[i]; if(nics[i].getDeviceId() > deviceId) deviceId = nics[i].getDeviceId(); NicTO nicTo = new NicTO(); nicTo.setDeviceId(deviceId++); nicTo.setBroadcastType(BroadcastDomainType.Vlan); nicTo.setType(TrafficType.Public); nicTo.setIp("0.0.0.0"); nicTo.setNetmask("255.255.255.255"); nicTo.setName(profile.getName()); nicTo.setMac(mac); } catch (InsufficientAddressCapacityException e) { throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId); nicTo.setDns1(profile.getIPv4Dns1()); nicTo.setDns2(profile.getIPv4Dns2()); if (publicNicProfile != null && publicNicProfile.getIPv4Gateway() != null) { nicTo.setGateway(publicNicProfile.getIPv4Gateway()); } else { nicTo.setGateway(network.getGateway()); nicTo.setDefaultNic(false); nicTo.setBroadcastUri(profile.getBroadCastUri()); nicTo.setIsolationuri(profile.getIsolationUri()); nicTo.setNetworkRateMbps(networkRate);
protected NicTO toNicTO(final NicVO nic, final NicProfile profile, final NetworkVO config) { final NicTO to = new NicTO(); to.setDeviceId(nic.getDeviceId()); to.setBroadcastType(config.getBroadcastDomainType()); to.setType(config.getTrafficType()); to.setIp(nic.getIPv4Address()); to.setNetmask(nic.getIPv4Netmask()); to.setMac(nic.getMacAddress()); to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); if (nic.getIPv4Gateway() != null) { to.setGateway(nic.getIPv4Gateway()); } else { to.setGateway(config.getGateway()); } if (nic.getVmType() != VirtualMachine.Type.User) { to.setPxeDisable(true); } to.setDefaultNic(nic.isDefaultNic()); to.setBroadcastUri(nic.getBroadcastUri()); to.setIsolationuri(nic.getIsolationUri()); if (profile != null) { to.setDns1(profile.getIPv4Dns1()); to.setDns2(profile.getIPv4Dns2()); } final Integer networkRate = _networkModel.getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); to.setUuid(config.getUuid()); return to; }
final NicTO nic = new NicTO(); nic.setMac(ip.getVifMacAddress()); nic.setType(ip.getTrafficType()); if (ip.getBroadcastUri() == null) { nic.setBroadcastType(BroadcastDomainType.Native); } else { final URI uri = BroadcastDomainType.fromString(ip.getBroadcastUri()); nic.setBroadcastType(BroadcastDomainType.getSchemeValue(uri)); nic.setBroadcastUri(uri); nic.setDeviceId(0); nic.setNetworkRateMbps(ip.getNetworkRate()); nic.setName(ip.getNetworkName());
private void createVif(final LibvirtVMDef vm, final NicTO nic, final String nicAdapter, Map<String, String> extraConfig) throws InternalErrorException, LibvirtException { if (nic.getType().equals(TrafficType.Guest) && nic.getBroadcastType().equals(BroadcastDomainType.Vsp)) { String vrIp = nic.getBroadcastUri().getPath().substring(1); vm.getMetaData().getMetadataNode(LibvirtVMDef.NuageExtensionDef.class).addNuageExtension(nic.getMac(), vrIp); if (s_logger.isDebugEnabled()) { s_logger.debug("NIC with MAC " + nic.getMac() + " and BroadcastDomainType " + nic.getBroadcastType() + " in network(" + nic.getGateway() + "/" + nic.getNetmask() + ") is " + nic.getType() + " traffic type. So, vsp-vr-ip " + vrIp + " is set in the metadata"); } } if (vm.getDevices() == null) { s_logger.error("LibvirtVMDef object get devices with null result"); throw new InternalErrorException("LibvirtVMDef object get devices with null result"); } vm.getDevices().addDevice(getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig)); }
if (!_libvirtComputingResource.dpdkSupport || nic.isDpdkDisabled()) { if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) { vlanId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { logicalSwitchUuid = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri()); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) { vlanId = NetUtils.getPrimaryPvlanFromUri(nic.getBroadcastUri()); String trafficLabel = nic.getName(); if (nic.getType() == Networks.TrafficType.Guest) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) && !vlanId.equalsIgnoreCase("untagged")) { if (trafficLabel != null && !trafficLabel.isEmpty()) { if (_libvirtComputingResource.dpdkSupport && !nic.isDpdkDisabled()) { s_logger.debug("DPDK support enabled: configuring per traffic label " + trafficLabel); if (StringUtils.isBlank(_libvirtComputingResource.dpdkOvsPath)) { intf.defDpdkNet(_libvirtComputingResource.dpdkOvsPath, port, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), 0, getExtraDpdkProperties(extraConfig)); } else { s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId)); intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId));
if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) { final HashMap<String, String> args = citrixResourceBase.parseDefaultOvsRuleComamnd(BroadcastDomainType.getValue(nic.getBroadcastUri())); final OvsSetTagAndFlowCommand flowCmd = new OvsSetTagAndFlowCommand(args.get("vmName"), args.get("tag"), args.get("vlans"), args.get("seqno"), Long.parseLong(args.get("vmId"))); boolean secGrpEnabled = false; for (final NicTO nic : nics) { if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { secGrpEnabled = true; break; if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { final List<String> nicSecIps = nic.getNicSecIps(); String secIpsStr; final StringBuilder sb = new StringBuilder(); secIpsStr = "0;"; result = citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules", "vmName", vmName, "vmIP", nic.getIp(), "vmMAC", nic.getMac(), "vmID", Long.toString(vmSpec.getId()), "secIps", secIpsStr); s_logger.warn("Failed to program default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac()); } else { s_logger.info("Programmed default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac());
public VIF createVif(final Connection conn, final String vmName, final VM vm, final VirtualMachineTO vmSpec, final NicTO nic) throws XmlRpcException, XenAPIException { assert nic.getUuid() != null : "Nic should have a uuid value"; vifr.device = Integer.toString(nic.getDeviceId()); vifr.MAC = nic.getMac(); vifr.otherConfig.put("nicira-iface-id", nic.getUuid()); vifr.otherConfig.put("nicira-vm-id", vm.getUuid(conn)); vifr.otherConfig.put("cloudstack-nic-id", nic.getUuid()); if (vmSpec != null) { vifr.otherConfig.put("cloudstack-vm-id", vmSpec.getUuid()); vifr.otherConfig.put("cloudstack-network-id", nic.getNetworkUuid()); final URI broadcastUri = nic.getBroadcastUri(); if (broadcastUri != null && broadcastUri.getScheme().equalsIgnoreCase(Networks.BroadcastDomainType.Vsp.scheme())) { final String path = broadcastUri.getPath(); if (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) { vifr.qosAlgorithmType = "ratelimit"; vifr.qosAlgorithmParams = new HashMap<String, String>(); vifr.qosAlgorithmParams.put("kbps", Integer.toString(nic.getNetworkRateMbps() * 128)); vifr = vif.getRecord(conn); if (vifr != null) { s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId());
protected VIF getCorrectVif(final Connection conn, final VM router, final IpAddressTO ip) throws XmlRpcException, XenAPIException { final NicTO nic = new NicTO(); nic.setType(ip.getTrafficType()); nic.setName(ip.getNetworkName()); if (ip.getBroadcastUri() == null) { nic.setBroadcastType(BroadcastDomainType.Native); } else { final URI uri = BroadcastDomainType.fromString(ip.getBroadcastUri()); nic.setBroadcastType(BroadcastDomainType.getSchemeValue(uri)); nic.setBroadcastUri(uri); } final Network network = getNetwork(conn, nic); // Determine the correct VIF on DomR to associate/disassociate the // IP address with final Set<VIF> routerVIFs = router.getVIFs(conn); for (final VIF vif : routerVIFs) { final Network vifNetwork = vif.getNetwork(conn); if (vifNetwork.getUuid(conn).equals(network.getUuid(conn))) { return vif; } } return null; }
final String[] aclRules = rules[0]; final NicTO nic = command.getNic(); final String dev = "eth" + nic.getDeviceId(); final String netmask = Long.toString(NetUtils.getCidrSize(nic.getNetmask())); final NetworkACL networkACL = new NetworkACL(dev, nic.getMac(), privateGw != null, nic.getIp(), netmask, ingressRules.toArray(new AclRule[ingressRules.size()]), egressRules.toArray(new AclRule[egressRules.size()]));
nic.setPxeDisable(true); nic.setDpdkDisabled(true); if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { if (vmSpec.getType() != VirtualMachine.Type.User) { libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, vmName); break; } else { final List<String> nicSecIps = nic.getNicSecIps(); String secIpsStr; final StringBuilder sb = new StringBuilder(); if (nic.getType() == TrafficType.Control) { controlIp = nic.getIp(); break;
private Boolean createVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException { try { String net = network.getNetwork(nic); if (net != null) { LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName()); vm.addVif(nic.getDeviceId(), net, nic.getMac()); } else { LOGGER.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName()); return false; } } catch (Exception e) { String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage(); LOGGER.debug(msg); throw new Ovm3ResourceException(msg); } return true; } private Boolean deleteVif(Xen.Vm vm, NicTO nic)
protected boolean post_default_network_rules(final Connect conn, final String vmName, final NicTO nic, final Long vmId, final InetAddress dhcpServerIp, final String hostIp, final String hostMacAddr) { if (!_canBridgeFirewall) { return false; } final List<InterfaceDef> intfs = getInterfaces(conn, vmName); if (intfs.size() < nic.getDeviceId()) { return false; } final InterfaceDef intf = intfs.get(nic.getDeviceId()); final String brname = intf.getBrName(); final String vif = intf.getDevName(); final Script cmd = new Script(_securityGroupPath, _timeout, s_logger); cmd.add("post_default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); cmd.add("--vmip", nic.getIp()); cmd.add("--vmmac", nic.getMac()); cmd.add("--vif", vif); cmd.add("--brname", brname); if (dhcpServerIp != null) { cmd.add("--dhcpSvr", dhcpServerIp.getHostAddress()); } cmd.add("--hostIp", hostIp); cmd.add("--hostMacAddr", hostMacAddr); final String result = cmd.execute(); if (result != null) { return false; } return true; }
public Network getNetwork(final Connection conn, final NicTO nic) throws XenAPIException, XmlRpcException { final String name = nic.getName(); final XsLocalNetwork network = getNativeNetworkForTraffic(conn, nic.getType(), name); if (network == null) { s_logger.error("Network is not configured on the backend for nic " + nic.toString()); throw new CloudRuntimeException("Network for the backend is not configured correctly for network broadcast domain: " + nic.getBroadcastUri()); final URI uri = nic.getBroadcastUri(); final BroadcastDomainType type = nic.getBroadcastType(); if (uri != null && uri.toString().contains("untagged")) { return network.getNetwork(); throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri());
@Override public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) { final SetupGuestNetworkCommand command = (SetupGuestNetworkCommand) cmd; final NicTO nic = command.getNic(); final String routerGIP = command.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); final String gateway = command.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY); final String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask())); final String netmask = nic.getNetmask(); final String domainName = command.getNetworkDomain(); String dns = command.getDefaultDns1(); if (dns == null || dns.isEmpty()) { dns = command.getDefaultDns2(); } else { final String dns2 = command.getDefaultDns2(); if (dns2 != null && !dns2.isEmpty()) { dns += "," + dns2; } } final GuestNetwork guestNetwork = new GuestNetwork(command.isAdd(), nic.getMac(), "eth" + nic.getDeviceId(), routerGIP, netmask, gateway, cidr, dns, domainName); return generateConfigItems(guestNetwork); }