public void ComputeBroadcast( ) { var netAddress = SUTest.ComputeBroadcast( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 255, 255)); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 7 }, netAddress.Bytes); netAddress = SUTest.ComputeBroadcast( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(0, 0, 0, 0)); CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255 }, netAddress.Bytes); netAddress = SUTest.ComputeBroadcast( new NetIpAddress(124, 102, 10, 7), new NetIpAddress(255, 255, 254, 0)); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 255 }, netAddress.Bytes); netAddress = SUTest.ComputeBroadcast( new NetIpAddress(124, 100, 11, 7), new NetIpAddress(255, 254, 0, 0)); CollectionAssert.AreEqual(new byte[] { 124, 101, 255, 255 }, netAddress.Bytes); netAddress = SUTest.ComputeBroadcast( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(254, 0, 0, 0)); CollectionAssert.AreEqual(new byte[] { 125, 255, 255, 255 }, netAddress.Bytes); }
public void Constructor( ) { var srcMac = new NetMacAddress(1LU); var dstMac = new NetMacAddress(2LU); var srcInterf = new Abstract.Fakes.StubINetHwInterface( ); srcInterf.HardwareAddressGet = ( ) => srcMac; var dstInterf = new Abstract.Fakes.StubINetHwInterface( ); dstInterf.HardwareAddressGet = ( ) => dstMac; var srcAddress = new NetAddress( new NetIpAddress(182, 95, 34, 147), new NetIpAddress(255, 254, 11, 201), new NetIpAddress(182, 94, 0, 0)); var dstAddress = new NetAddress( new NetIpAddress(214, 21, 157, 193), new NetIpAddress(255, 255, 192, 0), new NetIpAddress(214, 21, 0, 0)); var netPacket = new SUTest( ((INetHwInterface)srcInterf).HardwareAddress, ((INetHwInterface)dstInterf).HardwareAddress, srcAddress, dstAddress); Assert.AreEqual(srcMac, netPacket.SourceHardwareAddress); Assert.AreEqual(dstMac, netPacket.DestinationHardwareAddress); Assert.AreEqual(srcAddress, netPacket.SourceAddress); Assert.AreEqual(dstAddress, netPacket.DestinationAddress); Assert.AreEqual(30, netPacket.TTL); }
public void ComputeNetworkAddress( ) { var netAddress = SUTest.ComputeNetworkAddress( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 255, 255)); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 7 }, netAddress.Bytes); netAddress = SUTest.ComputeNetworkAddress( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(0, 0, 0, 0)); CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 0 }, netAddress.Bytes); netAddress = SUTest.ComputeNetworkAddress( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 254, 0)); CollectionAssert.AreEqual(new byte[] { 124, 102, 10, 0 }, netAddress.Bytes); netAddress = SUTest.ComputeNetworkAddress( new NetIpAddress(124, 101, 11, 7), new NetIpAddress(255, 254, 0, 0)); CollectionAssert.AreEqual(new byte[] { 124, 100, 0, 0 }, netAddress.Bytes); netAddress = SUTest.ComputeNetworkAddress( new NetIpAddress(125, 102, 11, 7), new NetIpAddress(254, 0, 0, 0)); CollectionAssert.AreEqual(new byte[] { 124, 0, 0, 0 }, netAddress.Bytes); }
public void NetmaskIsValid( ) { var result = SUTest.NetmaskIsValid(new NetIpAddress(255, 255, 255, 255)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(0, 0, 0, 0)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(255, 255, 254, 0)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(255, 254, 0, 0)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(254, 0, 0, 0)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(0, 0, 0, 0)); Assert.AreEqual(true, result); result = SUTest.NetmaskIsValid(new NetIpAddress(255, 255, 254, 255)); Assert.AreEqual(false, result); result = SUTest.NetmaskIsValid(new NetIpAddress(253, 0, 0, 0)); Assert.AreEqual(false, result); }
public void Equals( ) { var netAddressA = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 102, 255, 255)); var netAddressB = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 102, 255, 255)); var netAddressC = new SUTest( new NetIpAddress(124, 102, 1, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 102, 255, 255)); var netAddressD = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 254, 0, 0), new NetIpAddress(124, 102, 255, 255)); var netAddressE = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 100, 255, 255)); var netAddressF = new SUTest( new NetIpAddress(124, 102, 1, 7), new NetIpAddress(255, 254, 0, 0), new NetIpAddress(124, 102, 255, 255)); var netAddressG = new SUTest( new NetIpAddress(124, 102, 1, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 100, 255, 255)); var netAddressH = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 254, 0, 0), new NetIpAddress(124, 100, 255, 255)); var netAddressI = new SUTest( new NetIpAddress(124, 102, 1, 7), new NetIpAddress(255, 254, 0, 0), new NetIpAddress(124, 100, 255, 255)); Assert.AreEqual(true, netAddressA.Equals(netAddressA)); Assert.AreEqual(true, netAddressA.Equals(netAddressB)); Assert.AreEqual(true, netAddressB.Equals(netAddressA)); Assert.AreEqual(false, netAddressA.Equals(netAddressC)); Assert.AreEqual(false, netAddressA.Equals(netAddressD)); Assert.AreEqual(false, netAddressA.Equals(netAddressE)); Assert.AreEqual(false, netAddressA.Equals(netAddressF)); Assert.AreEqual(false, netAddressA.Equals(netAddressG)); Assert.AreEqual(false, netAddressA.Equals(netAddressH)); Assert.AreEqual(false, netAddressA.Equals(netAddressI)); }
public void Constructor_SingleHost( ) { var netAddress = new SUTest(new NetIpAddress(124, 102, 11, 7)); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 7 }, netAddress.Address.Bytes); CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255 }, netAddress.Netmask.Bytes); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 7 }, netAddress.Broadcast.Bytes); }
public void IsHost3( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0)); Assert.AreEqual(true, netAddress.IsHost( )); }
public void IsHost2( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 128, 0), new NetIpAddress(255, 255, 128, 0)); Assert.AreEqual(false, netAddress.IsHost( )); }
public bool IsMatch(NetAddress destinationAddress) { if (Address.IsNetwork( )) { return(Address.Contains(destinationAddress)); } return(false); }
public void IsNetwork2( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 128, 0), new NetIpAddress(255, 255, 128, 0)); Assert.AreEqual(true, netAddress.IsNetwork( )); }
public void IsValid4( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 8)); Assert.AreEqual(false, netAddress.IsValid( )); }
public void IsNetwork3( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0)); Assert.AreEqual(false, netAddress.IsNetwork( )); }
public void GetNetwork5( ) { var netAddress = new SUTest( new NetIpAddress(125, 102, 11, 7), new NetIpAddress(254, 0, 0, 0)); var network = netAddress.GetNetwork( ); Assert.AreEqual(netAddress.Netmask, network.Netmask); Assert.AreEqual(netAddress.Broadcast, network.Broadcast); CollectionAssert.AreEqual(new byte[] { 124, 0, 0, 0 }, network.Address.Bytes); }
public void Constructor_FullRandomAddress( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 102, 255, 255)); CollectionAssert.AreEqual(new byte[] { 124, 102, 11, 7 }, netAddress.Address.Bytes); CollectionAssert.AreEqual(new byte[] { 255, 255, 0, 0 }, netAddress.Netmask.Bytes); CollectionAssert.AreEqual(new byte[] { 124, 102, 255, 255 }, netAddress.Broadcast.Bytes); }
public void NetmaskIsValid_FromDataSourceTestXml( ) { // Access the data byte x1 = Convert.ToByte(TestContext.DataRow["x1"]); byte x2 = Convert.ToByte(TestContext.DataRow["x2"]); byte x3 = Convert.ToByte(TestContext.DataRow["x3"]); byte x4 = Convert.ToByte(TestContext.DataRow["x4"]); bool expected = Convert.ToBoolean(TestContext.DataRow["IsValid"]); bool actual = SUTest.NetmaskIsValid(new NetIpAddress(x1, x2, x3, x4)); Assert.AreEqual(expected, actual, "{0}.{1}.{2}.{3}", x1, x2, x3, x4); }
public void IsMatch_Inside( ) { var netRoute = new SUTest( new NetIpAddress(124, 102, 0, 0), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(172, 144, 11, 201)); var netIpAddressInside = new NetAddress( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0)); Assert.AreEqual(true, netRoute.IsMatch(netIpAddressInside)); }
public void Contains( ) { var netAddressNet = new SUTest( new NetIpAddress(124, 102, 128, 0), new NetIpAddress(255, 255, 128, 0)); var netAddressHost = new SUTest( new NetIpAddress(124, 102, 128, 7), new NetIpAddress(255, 255, 0, 0)); Assert.AreEqual(true, netAddressNet.Contains(netAddressNet)); Assert.AreEqual(true, netAddressNet.Contains(netAddressHost)); Assert.AreEqual(false, netAddressHost.Contains(netAddressNet)); Assert.AreEqual(true, netAddressHost.Contains(netAddressHost)); }
public void IsMatch_OutsideBefore( ) { var netRoute = new SUTest( new NetIpAddress(124, 102, 0, 0), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(172, 144, 11, 201)); var netIpAddressOutsideBefore = new NetAddress( new NetIpAddress(124, 101, 255, 254), new NetIpAddress(255, 255, 0, 0)); Assert.AreEqual(false, netRoute.IsMatch(netIpAddressOutsideBefore)); }
public void IsValid6( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 8), new NetIpAddress(124, 102, 255, 247)); Assert.AreEqual(false, netAddress.IsValid( )); }
public void IsValid3( ) { var netAddress = new SUTest( new NetIpAddress(124, 102, 11, 7), new NetIpAddress(255, 255, 0, 0), new NetIpAddress(124, 102, 255, 255)); Assert.AreEqual(true, netAddress.IsValid( )); }
public bool IsMatch(NetAddress destinationAddress) { if (Address.IsNetwork( )) return Address.Contains(destinationAddress); return false; }
public bool Contains(NetAddress hostAddress) { return((this.IsNetwork( ) && this.Address == ComputeNetworkAddress(hostAddress.Address, this.Netmask)) || this.Address == hostAddress.Address); }
public NetRoute(NetIpAddress target) { this.address = new NetAddress(NetIpAddress.Zero, NetIpAddress.Zero); this.target = new NetAddress(target); }
public bool Contains(NetAddress hostAddress) { return (this.IsNetwork( ) && this.Address == ComputeNetworkAddress(hostAddress.Address, this.Netmask)) || this.Address == hostAddress.Address; }
public void IsHost1( ) { var netAddress = new SUTest(new NetIpAddress(124, 102, 11, 7)); Assert.AreEqual(false, netAddress.IsHost( )); }
public NetRoute(NetIpAddress address, NetIpAddress netmask, NetIpAddress target) { this.address = new NetAddress(address, netmask); this.target = new NetAddress(target); }
internal NetPacket(NetMacAddress sourceHardwareAddress, NetMacAddress destinationHardwareAddress, NetAddress? sourceAddress, NetAddress? destinationAddress) : this(sourceHardwareAddress, destinationHardwareAddress) { this.sourceAddress = sourceAddress; this.destinationAddress = destinationAddress; }
public void IsValid1( ) { var netAddress = new SUTest(new NetIpAddress(124, 102, 11, 7)); Assert.AreEqual(true, netAddress.IsValid( )); }
public void IsNetwork1( ) { var netAddress = new SUTest(new NetIpAddress(124, 102, 11, 7)); Assert.AreEqual(true, netAddress.IsNetwork( )); }
public bool Equals(NetAddress other) { return this.address == other.Address && this.netmask == other.Netmask && this.broadcast == other.Broadcast; }
public bool Equals(NetAddress other) { return(this.address == other.Address && this.netmask == other.Netmask && this.broadcast == other.Broadcast); }