private void AddSubnetworkNode() { var subnetworkNode = new TreeNode(); if (networkHierarchyTreeView.SelectedNode != null) { networkHierarchyTreeView.SelectedNode.Nodes.Add(subnetworkNode); var parentAddress = networkHierarchyTreeView.SelectedNode.Text; var childIndex = networkHierarchyTreeView.SelectedNode.Nodes.IndexOf(subnetworkNode) + 1; var childAddress = new NetworkAddress(parentAddress).Append(childIndex); subnetworkNode.Text = childAddress.ToString(); } else { networkHierarchyTreeView.Nodes.Add(subnetworkNode); var childIndex = networkHierarchyTreeView.Nodes.IndexOf(subnetworkNode) + 1; var childAddress = new NetworkAddress(childIndex); subnetworkNode.Text = childAddress.ToString(); } subnetworkNode.Tag = new HierarchicalPathComputationServer(new NetworkAddress(subnetworkNode.Text), "127.0.0.1", Settings.Default.SignallingCloudListeningPort); networkHierarchyTreeView.SelectedNode?.Expand(); }
private void RestoreToNetworkHierarchyTreeView(NetworkAddress address, NodeView node) { TreeNode parent = networkHierarchyTreeView.Nodes[address.GetId(0) - 1]; var nodes = parent.Nodes; var currentAddress = new NetworkAddress(address.GetId(0)); for (var i = 1; i < address.Levels - 1; i++) { var id = address.GetId(i); var subnetworkNode = new TreeNode(); currentAddress = currentAddress.Append(id); subnetworkNode.Text = currentAddress.ToString(); subnetworkNode.Name = currentAddress.ToString(); subnetworkNode.Tag = new HierarchicalPathComputationServer(currentAddress, "127.0.0.1", Settings.Default.SignallingCloudListeningPort); if (!nodes.ContainsKey(subnetworkNode.Name)) { nodes.Add(subnetworkNode); parent = subnetworkNode; nodes = parent.Nodes; } else { parent = nodes[subnetworkNode.Name]; nodes = parent.Nodes; } } var treeNode = new TreeNode { Tag = node, Text = address.ToString(), Name = address.ToString() }; if (!nodes.ContainsKey(treeNode.Name)) { nodes.Add(treeNode); } else { nodes[treeNode.Name].Tag = treeNode.Tag; } }
public override string ToString() { if (NodeDescriptor == null) { return("ZigBeeNode [IEEE=" + IeeeAddress + ", NWK=0x" + NetworkAddress.ToString("X4") + "]"); } return("ZigBeeNode [IEEE=" + IeeeAddress + ", NWK=0x" + NetworkAddress.ToString("X4") + ", Type=" + NodeDescriptor.LogicalNodeType + "]"); }
private void DisplayAddress(Address address) { if (address != null) { System.Text.StringBuilder deviceAddress = new System.Text.StringBuilder(); for (int i = 0; i < address.MaxAddressLineIndex; i++) { deviceAddress.AppendLine(address.GetAddressLine(i)); } var objAddress = new NetworkAddress(deviceAddress.ToString()); wiFiAddress = objAddress; // Remove the last comma from the end of the address. //_addressText.Text = deviceAddress.ToString(); Log.Debug(Tag, "Address: " + objAddress.ToString() + "."); } else { //_addressText.Text = "Unable to determine the address. Try again in a few minutes."; } }
public void ConstructFromValues() { var expectedChassisIDType = ChassisSubType.NetworkAddress; var expectedChassisIDNetworkAddress = new NetworkAddress(new IPAddress(new byte[] { 0x0A, 0x00, 0x01, 0x01 })); var expectedPortIDBytes = new byte[] { 0x30, 0x30, 0x31, 0x42, 0x35, 0x34, 0x39, 0x34, 0x35, 0x41, 0x38, 0x42, 0x3a, 0x50, 0x32 }; ushort expectedTimeToLive = 120; var expectedPortDescription = "Port Description"; var expectedSystemName = "SystemName"; var expectedSystemDescription = "System Description"; ushort expectedSystemCapabilitiesCapability = 18; ushort expectedSystemCapabilitiesEnabled = 16; var managementAddressNetworkAddress = new NetworkAddress(new IPAddress(new byte[] { 0x0A, 0x00, 0x01, 0x01 })); var managementAddressObjectIdentifier = "Object Identifier"; uint managementAddressInterfaceNumber = 0x44060124; var expectedOrganizationUniqueIdentifier = new byte[] { 0x24, 0x10, 0x12 }; var expectedOrganizationSubType = 2; var expectedOrganizationSpecificBytes = new byte[] { 0xBA, 0xAD, 0xF0, 0x0D }; var valuesLLDPPacket = new LldpPacket(); Console.WriteLine("valuesLLDPPacket.ToString() {0}", valuesLLDPPacket); valuesLLDPPacket.TlvCollection.Add(new ChassisIdTlv(expectedChassisIDType, expectedChassisIDNetworkAddress)); Console.WriteLine("valuesLLDPPacket.ToString() {0}", valuesLLDPPacket); //valuesLLDPPacket.TlvCollection.Add(new PortId(lldpPacket, PortSubTypes.MacAddress, new PhysicalAddress(new byte[6] { 0x00, 0x1C, 0x23, 0xAF, 0x08, 0xF3 }))); valuesLLDPPacket.TlvCollection.Add(new PortIdTlv(PortSubType.LocallyAssigned, expectedPortIDBytes)); valuesLLDPPacket.TlvCollection.Add(new TimeToLiveTlv(expectedTimeToLive)); valuesLLDPPacket.TlvCollection.Add(new PortDescriptionTlv(expectedPortDescription)); valuesLLDPPacket.TlvCollection.Add(new SystemNameTlv(expectedSystemName)); valuesLLDPPacket.TlvCollection.Add(new SystemDescriptionTlv(expectedSystemDescription)); valuesLLDPPacket.TlvCollection.Add(new SystemCapabilitiesTlv(expectedSystemCapabilitiesCapability, expectedSystemCapabilitiesEnabled)); valuesLLDPPacket.TlvCollection.Add(new ManagementAddressTlv(managementAddressNetworkAddress, InterfaceNumber.SystemPortNumber, managementAddressInterfaceNumber, managementAddressObjectIdentifier)); valuesLLDPPacket.TlvCollection.Add(new OrganizationSpecificTlv(expectedOrganizationUniqueIdentifier, expectedOrganizationSubType, expectedOrganizationSpecificBytes)); valuesLLDPPacket.TlvCollection.Add(new EndOfLldpduTlv()); var lldpBytes = valuesLLDPPacket.Bytes; Console.WriteLine("valuesLLDPPacket.ToString() {0}", valuesLLDPPacket); // reparse these bytes back into a lldp packet var lldpPacket = new LldpPacket(new ByteArraySegment(lldpBytes)); Console.WriteLine("lldpPacket.ToString() {0}", lldpPacket); var expectedTlvCount = 10; Assert.AreEqual(expectedTlvCount, lldpPacket.TlvCollection.Count); var count = 1; foreach (var tlv in lldpPacket.TlvCollection) { Console.WriteLine("Type: " + tlv.GetType()); switch (count) { case 1: { Assert.AreEqual(typeof(ChassisIdTlv), tlv.GetType()); var chassisID = (ChassisIdTlv)tlv; Assert.AreEqual(ChassisSubType.NetworkAddress, chassisID.SubType); Assert.AreEqual(typeof(NetworkAddress), chassisID.SubTypeValue.GetType()); Console.WriteLine(expectedChassisIDNetworkAddress.ToString()); Console.WriteLine(chassisID.SubTypeValue.ToString()); Assert.AreEqual(expectedChassisIDNetworkAddress, chassisID.SubTypeValue); break; } case 2: { Assert.AreEqual(typeof(PortIdTlv), tlv.GetType()); var portID = (PortIdTlv)tlv; Assert.AreEqual(PortSubType.LocallyAssigned, portID.SubType); Assert.AreEqual(expectedPortIDBytes, portID.SubTypeValue); //Assert.AreEqual(PortSubTypes.MacAddress, portID.SubType); //var macAddress = new PhysicalAddress(new byte[6] { 0x00, 0x1C, 0x23, 0xAF, 0x08, 0xF3 }); //Assert.AreEqual(macAddress, portID.SubTypeValue); break; } case 3: { Assert.AreEqual(typeof(TimeToLiveTlv), tlv.GetType()); Assert.AreEqual(expectedTimeToLive, ((TimeToLiveTlv)tlv).Seconds); break; } case 4: { Assert.AreEqual(typeof(PortDescriptionTlv), tlv.GetType()); Assert.AreEqual(expectedPortDescription, ((PortDescriptionTlv)tlv).Description); break; } case 5: { Assert.AreEqual(typeof(SystemNameTlv), tlv.GetType()); Assert.AreEqual(expectedSystemName, ((SystemNameTlv)tlv).Name); break; } case 6: { Assert.AreEqual(typeof(SystemDescriptionTlv), tlv.GetType()); Assert.AreEqual(expectedSystemDescription, ((SystemDescriptionTlv)tlv).Description); break; } case 7: { Assert.AreEqual(typeof(SystemCapabilitiesTlv), tlv.GetType()); var capabilities = (SystemCapabilitiesTlv)tlv; Assert.IsTrue(capabilities.IsCapable(CapabilityOptions.Repeater)); Assert.IsTrue(capabilities.IsEnabled(CapabilityOptions.Router)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.Bridge)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.DocsisCableDevice)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.Other)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.StationOnly)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.Telephone)); Assert.IsFalse(capabilities.IsCapable(CapabilityOptions.WLanAP)); break; } case 8: { Assert.AreEqual(typeof(ManagementAddressTlv), tlv.GetType()); var mgmtAdd = (ManagementAddressTlv)tlv; Assert.AreEqual(IanaAddressFamily.IPv4, mgmtAdd.AddressSubType); Assert.AreEqual(managementAddressNetworkAddress, mgmtAdd.Address); Assert.AreEqual(InterfaceNumber.SystemPortNumber, mgmtAdd.InterfaceSubType); Assert.AreEqual(managementAddressInterfaceNumber, mgmtAdd.InterfaceNumber); var expectedObjIdLength = managementAddressObjectIdentifier.Length; Assert.AreEqual(expectedObjIdLength, mgmtAdd.ObjIdLength); Assert.AreEqual(managementAddressObjectIdentifier, mgmtAdd.ObjectIdentifier); break; } case 9: { Assert.AreEqual(typeof(OrganizationSpecificTlv), tlv.GetType()); var orgSpecifig = (OrganizationSpecificTlv)tlv; Assert.AreEqual(expectedOrganizationUniqueIdentifier, orgSpecifig.OrganizationUniqueID); Assert.AreEqual(expectedOrganizationSubType, orgSpecifig.OrganizationDefinedSubType); Assert.AreEqual(expectedOrganizationSpecificBytes, orgSpecifig.OrganizationDefinedInfoString); break; } case 10: { Assert.AreEqual(typeof(EndOfLldpduTlv), tlv.GetType()); break; } default: { throw new ArgumentException(); } } // increment the counter count++; } }
public IDictionary <String, String> GetValues() => new Dictionary <String, String> { { nameof(NetworkAddress), NetworkAddress.ToString() }, { nameof(Mask), Mask.GetSlashNotation().ToString() }, };
public IDictionary <string, string> GetValues() => new Dictionary <String, String> { { nameof(NetworkAddress), NetworkAddress.ToString() }, { nameof(SubnetMask), SubnetMask.ToString() }, };
public override string ToString() { return(NetworkAddress.ToString() + "/" + Length.ToString()); }