Пример #1
0
        /// <summary>
        /// Create vlans for a vif.
        /// </summary>
        /// <returns>The vlans.</returns>
        /// <param name="ipv4Addresses">Ipv4 addresses.</param>
        protected internal virtual List <Vlan> CreateVlans(AttachmentRole role, List <Ipv4AddressAndMask> ipv4Addresses)
        {
            if (role.IsLayer3Role)
            {
                if (ipv4Addresses.Count != this._interfaces.Count)
                {
                    throw new AttachmentDomainException($"Insufficient IPv4 addresses provided to create vlans for a new vif for attachment '{this.Name}'. " +
                                                        $"{ipv4Addresses.Count} were supplied but {this._interfaces.Count} are required.");
                }
            }

            var vlans = new List <Vlan>();

            foreach (var @interface in this._interfaces)
            {
                var vlan = new Vlan();

                if (role.IsLayer3Role)
                {
                    var ipv4Address = ipv4Addresses.First();
                    vlan.SetIpv4Address(ipv4Address);
                    ipv4Addresses.Remove(ipv4Address);
                }

                @interface.AddVlan(vlan);
                vlans.Add(vlan);
            }

            return(vlans);
        }
Пример #2
0
        /// <summary>
        /// Create interfaces for the attachment.
        /// </summary>
        /// <param name="ipv4Addresses">Ipv4 addresses.</param>
        protected internal virtual void CreateInterfaces(AttachmentRole role, List <Ipv4AddressAndMask> ipv4Addresses)
        {
            var @interface = new Interface();

            if (role.IsLayer3Role)
            {
                @interface.SetIpv4Address(ipv4Addresses.FirstOrDefault());
            }

            this._interfaces.Add(@interface);
        }
Пример #3
0
        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));
        }
Пример #4
0
 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;
 }
Пример #5
0
        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));
        }