public BundleAttachment(int tenantId, string locationName, string description, string notes, AttachmentBandwidth attachmentBandwidth, AttachmentRole role, bool enableJumboMtu, string planeName = null, List <Ipv4AddressAndMask> ipv4Addresses = null, int?bundleMinLinks = null, int?bundleMaxLinks = null) : base(tenantId, locationName, description, notes, attachmentBandwidth, role, enableJumboMtu, planeName) { // Check the requested bandwidth for the attachment is supported by a bundle if (!attachmentBandwidth.MustBeBundleOrMultiPort && !attachmentBandwidth.SupportedByBundle) { throw new AttachmentDomainException($"The requested bandwidth, '{attachmentBandwidth.BandwidthGbps} Gbps', " + "is not supported by a bundle attachment."); } // Default values for min/max bundle links if (bundleMinLinks.HasValue) { this._bundleMinLinks = bundleMinLinks.Value; } else { this._bundleMinLinks = attachmentBandwidth.GetNumberOfPortsRequiredForBundle().Value; } if (bundleMaxLinks.HasValue) { this._bundleMaxLinks = bundleMaxLinks.Value; } else { this._bundleMaxLinks = attachmentBandwidth.GetNumberOfPortsRequiredForBundle().Value; } // Create some interfaces and assign IP addresses if the attachment is enabled for layer 3 base.CreateInterfaces(role, ipv4Addresses); this.AttachmentStatus = AttachmentStatus.CreatedAwaitingUni; // Raise a domain event to notify listeners that a new attachment has been created this.AddDomainEvent(new AttachmentCreatedDomainEvent(this, attachmentBandwidth.GetNumberOfPortsRequiredForBundle().Value, attachmentBandwidth.BundleOrMultiPortMemberBandwidthGbps.Value, locationName, role.PortPoolId, role.RequireRoutingInstance, planeName)); }
/// <summary> /// Adds a vif to the attachment. /// </summary> /// <param name="role">Role of the vif</param> /// <param name="vlanTagRange">Vlan tag range for assignment of a vlan tag to the vif</param> /// <param name="mtu">Maximum transmission unit for the vif </param> /// <param name="contractBandwidthPool">An existing contract bandwidth pool to allocate to the vif</param> /// <param name="contractBandwidth">Contract bandwidth denoting the bandwidth requested for the vif</param> /// <param name="ipv4Addresses">Ipv4 addresses to be assigned to the layer 3 vif.</param> /// <param name="tenantId">Tenant identifier denoting the tenant for which the vif is assigned</param> /// <param name="vlanTag">Vlan tag to be assigned to the vif. It not provided one will be assigned.</param> public void AddVif(int tenantId, VifRole role, VlanTagRange vlanTagRange, Mtu mtu, ContractBandwidthPool contractBandwidthPool, AttachmentBandwidth attachmentBandwidth, ContractBandwidth contractBandwidth, List <Ipv4AddressAndMask> ipv4Addresses, bool trustReceivedCosAndDscp = false, int?vlanTag = null) { // The supplied vif role must be compatible with the attachment if (role.AttachmentRole.Id != this._attachmentRoleId) { throw new AttachmentDomainException($"Vif role '{role.Name}' is not valid for attachment '{this.Name}' "); } // Attachment must be 'tagged' in order to create a vif if (!role.AttachmentRole.IsTaggedRole) { throw new AttachmentDomainException($"A Vif cannot be created for attachment '{this.Name}' because the attachment is not enabled for tagging. "); } // Supplied attachment bandwidth must match that set for the attachment if (attachmentBandwidth.Id != this._attachmentBandwidthId) { throw new AttachmentDomainException($"Attachment bandwidth '{attachmentBandwidth.BandwidthGbps}' is not valid for attachment '{this.Name}' "); } // If a vlan tag is supplied, validate that it is in the correct range if (vlanTag.HasValue) { if (vlanTag < 2 || vlanTag > 4094) { throw new AttachmentDomainException("The vlan tag must be between 2 and 4094."); } // Validate that the supplied vlan tag is unique if (this._vifs.Select(v => v.VlanTag).Contains(vlanTag.Value)) { throw new AttachmentDomainException($"Vlan tag '{vlanTag}' is already used."); } } else { // Assign a free vlan tag from the supplied range vlanTag = AssignVlanTag(vlanTagRange); } var vlans = CreateVlans(role.AttachmentRole, ipv4Addresses); if (contractBandwidthPool == null && contractBandwidth == null) { throw new AttachmentDomainException("Either a contract bandwidth or an existing contract bandwidth pool is needed to create a vif."); } if (contractBandwidthPool != null) { // Validate the contract bandwidth pool belongs to this attachment if (!this.GetContractBandwidthPools().Contains(contractBandwidthPool)) { throw new AttachmentDomainException($"The supplied contract bandwidth pool does not exist or does not belong to " + "attachment '{this.Name}'."); } } if (contractBandwidth != null) { // Validate there is sufficient attachment bandwidth available var usedBandwidthMbps = this._vifs.Select(v => v.ContractBandwidthPool.ContractBandwidth.BandwidthMbps).Sum(); var availableBandwidthMbps = attachmentBandwidth.BandwidthGbps * 1000 - usedBandwidthMbps; if (availableBandwidthMbps < contractBandwidth.BandwidthMbps) { throw new AttachmentDomainException($"Insufficient bandwidth remaining. Attachment '{this.Name}' has '{availableBandwidthMbps}' " + "Mbps available."); } contractBandwidthPool = new ContractBandwidthPool(contractBandwidth, trustReceivedCosAndDscp, tenantId); } var vif = new Vif(this.Id, tenantId, role, mtu, vlans, vlanTag.Value, contractBandwidthPool, trustReceivedCosAndDscp); this._vifs.Add(vif); }
public SingleAttachment(int tenantId, string locationName, string description, string notes, AttachmentBandwidth attachmentBandwidth, AttachmentRole role, bool enableJumboMtu, string planeName = null, List <Ipv4AddressAndMask> ipv4Addresses = null) : base(tenantId, locationName, description, notes, attachmentBandwidth, role, enableJumboMtu, planeName) { // Create some interfaces and assign IP addresses if the attachment is enabled for layer 3 base.CreateInterfaces(role, ipv4Addresses); this.AttachmentStatus = AttachmentStatus.CreatedAwaitingUni; // Raise a domain event to notify listeners that a new attachment has been created this.AddDomainEvent(new AttachmentCreatedDomainEvent(this, 1, attachmentBandwidth.BandwidthGbps, locationName, role.PortPoolId, role.RequireRoutingInstance, planeName)); }
protected Attachment(int tenantId, string locationName, string description, string notes, AttachmentBandwidth attachmentBandwidth, AttachmentRole role, bool enableJumboMtu, string planeName = null) : this() { this._tenantId = tenantId; this._attachmentRoleId = role.Id; this._locationName = locationName; this.Name = Guid.NewGuid().ToString("N"); this._attachmentBandwidthId = attachmentBandwidth?.Id ?? throw new ArgumentNullException(nameof(attachmentBandwidth)); this._attachmentRoleId = role?.Id ?? throw new ArgumentNullException(nameof(role)); this._description = description ?? throw new ArgumentNullException(nameof(description)); this._notes = notes; _mtuId = enableJumboMtu ? Mtu.m9000.Id : Mtu.m1500.Id; this._planeName = planeName; }