/// <summary> /// Assigns the value to our properties from the given tik4net BgpPeer conatiner. /// </summary> /// <param name="bgpPeer">The tik4net BgpPeer container to take the params from.</param> private void SetValuesFromTikPeerContainer(BgpPeer bgpPeer) { this.Id = bgpPeer.Id; this.Name = bgpPeer.Name; this.Instance = bgpPeer.Instance; if (IPAddress.TryParse(bgpPeer.RemoteAddress, out IPAddress remoteAddress)) { this.RemoteAddress = remoteAddress; } this.RemoteAs = bgpPeer.RemoteAs; this.NexthopChoice = bgpPeer.NexthopChoice; this.Multihop = bgpPeer.Multihop; this.RouteReflect = bgpPeer.RouteReflect; this.HoldTime = this.TryConvertToTimeSpanOrMinimum(bgpPeer.HoldTime); this.Ttl = bgpPeer.Ttl; this.AddressFamilies = this.TryParseFamilies(bgpPeer.AddressFamilies); this.DefaultOriginate = bgpPeer.DefaultOriginate; this.RemovePrivateAs = bgpPeer.RemovePrivateAs; this.AsOverride = bgpPeer.AsOverride; this.Passive = bgpPeer.Passive; this.UseBfd = bgpPeer.UseBfd; this.RemoteId = bgpPeer.RemoteId; if (IPAddress.TryParse(bgpPeer.LocalAddress, out IPAddress localAddress)) { this.LocalAddress = localAddress; } this.Uptime = this.TryConvertToTimeSpanOrMinimum(bgpPeer.Uptime); this.PrefixCount = bgpPeer.PrefixCount; this.UpdatesSent = bgpPeer.UpdatesSent; this.UpdatesReceived = bgpPeer.UpdatesReceived; this.WithdrawnSent = bgpPeer.WithdrawnSent; this.WithdrawnReceived = bgpPeer.WithdrawnReceived; this.RemoteHoldTime = this.TryConvertToTimeSpanOrMinimum(bgpPeer.RemoteHoldTime); this.UsedHoldTime = this.TryConvertToTimeSpanOrMinimum(bgpPeer.UsedHoldTime); this.UsedKeepaliveTime = this.TryConvertToTimeSpanOrMinimum(bgpPeer.UsedKeepaliveTime); this.RefreshCapability = bgpPeer.RefreshCapability; this.As4Capability = bgpPeer.As4Capability; this.State = bgpPeer.State; this.StateEnumeration = bgpPeer.State.ToBgpStateEnumeration(); this.Established = bgpPeer.Established; this.Disabled = bgpPeer.Disabled; }
/// <summary> /// Construct for a given peer. We can right-away extract the values. What is lazy here is that for some properties (e.g. Uptime) /// we trigger a re-query. /// </summary> /// <param name="address">The address of the device that we're querying.</param> /// <param name="tikConnection">The tik4Net connection to use for talking to the device.</param> /// <param name="bgpPeer">The BGP peer to construct for.</param> public LazyLoadingMikrotikBgpPeerInfo(IpAddress address, ITikConnection tikConnection, BgpPeer bgpPeer) : base(address, tikConnection) { if (bgpPeer is null) { throw new ArgumentNullException(nameof(bgpPeer), "bgpPeer is null when constructing a LazyLoadingMikrotikBgpPeerInfo"); } this.SetValuesFromTikPeerContainer(bgpPeer); }