Example #1
0
 public static NetAddress?GetRoute(NetAddress?destinationAddress, IEnumerable <INetLgInterface> ipInterfaces, IEnumerable <INetRoute> routes, INetRoute defaultRoute)
 {
     if (destinationAddress != null)
     {
         foreach (var route in routes)
         {
             if (route.IsMatch(destinationAddress.Value))
             {
                 EmulatorLogger.Log(LogLevel.Info, EventType.RouteFound, string.Empty);
                 return(route.Target);
             }
         }
         if (defaultRoute != null)
         {
             EmulatorLogger.Log(LogLevel.Info, EventType.RouteDefaultUsed, string.Empty);
             return(defaultRoute.Target);
         }
         EmulatorLogger.Log(LogLevel.Info, EventType.RouteNotFound, string.Empty);
     }
     else
     {
         EmulatorLogger.Log(LogLevel.Warning, EventType.RouteInvalidDestinationAddress, string.Empty);
     }
     return(null);
 }
Example #2
0
 public void SendData(INetPacket data)
 {
     if (data.DestinationAddress != null)
     {
         var targetIf = RouteTableModule.GetTargetInterface(data.DestinationAddress, interfaces);
         if (targetIf != null)
         {
             targetIf.SendData(data);
             return;
         }
         else
         {
             var routeTarget = RouteTableModule.GetRoute(data.DestinationAddress, interfaces, routes, DefaultRoute);
             if (routeTarget != null)
             {
                 targetIf = RouteTableModule.GetTargetInterface(routeTarget, interfaces);
                 if (targetIf != null)
                 {
                     targetIf.SendData(data);
                     return;
                 }
             }
         }
         EmulatorLogger.Log(LogLevel.Info, EventType.RouteNotFound, string.Empty);
     }
 }
        public virtual void Disconnect( )
        {
            var other = otherInterface;

            if (other != null)
            {
                otherInterface = null;
                EmulatorLogger.Log(LogLevel.Info, EventType.Disconnected, this.Name);
                other.Disconnect( );
            }
        }
 public virtual void ReceiveData(INetPacket data)
 {
     EmulatorLogger.Log(LogLevel.Info, EventType.PacketRecived, this.Name);
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if (data.DestinationHardwareAddress == this.HardwareAddress)
     {
         parent.ReceiveData(data, this);
     }
 }
 public virtual void SendData(INetPacket data)
 {
     if (otherInterface != null)
     {
         EmulatorLogger.Log(LogLevel.Info, EventType.PacketSend, this.Name);
         otherInterface.ReceiveData(new NetPacket(this.HardwareAddress, otherInterface.HardwareAddress, data.SourceAddress, data.DestinationAddress));
     }
     else
     {
         EmulatorLogger.Log(LogLevel.Info, EventType.NotConnected, this.Name);
     }
 }
Example #6
0
 public override void SendData(INetPacket data)
 {
     if (otherInterface != null)
     {
         EmulatorLogger.Log(LogLevel.Info, EventType.PacketSend, this.Name);
         otherInterface.ReceiveData(new NetPacket(this.HardwareAddress, otherInterface.HardwareAddress, data.SourceAddress ?? this.Address, data.DestinationAddress));
     }
     else
     {
         EmulatorLogger.Log(LogLevel.Error, EventType.NotConnected, "There are no connected devie: " + this.Name);
     }
 }
 private void Connect(NetHwInterface other)
 {
     if (otherInterface != null)
     {
         otherInterface.Disconnect( );
     }
     if (other != null)
     {
         other.Disconnect( );
         other.otherInterface = this;
         EmulatorLogger.Log(LogLevel.Info, EventType.Connected, other.Name);
     }
     otherInterface = other;
     EmulatorLogger.Log(LogLevel.Info, EventType.Connected, this.Name);
 }
Example #8
0
 public static INetLgInterface GetTargetInterface(NetAddress?destinationAddress, IEnumerable <INetLgInterface> ipInterfaces)
 {
     if (destinationAddress != null)
     {
         foreach (var ipInterface in ipInterfaces)
         {
             if (ipInterface.Address != null && ipInterface.Address.Value.GetNetwork( ).Contains(destinationAddress.Value) == true)
             {
                 EmulatorLogger.Log(LogLevel.Info, EventType.RouteFoundConnected, string.Empty);
                 return(ipInterface);
             }
         }
     }
     return(null);
 }
Example #9
0
 public void ReceiveData(INetPacket data, INetHwInterface iface)
 {
     if (busyInterface != null)
     {
         EmulatorLogger.Log(LogLevel.Error, EventType.HubPacketColision, this.Name);
         return;
     }
     else
     {
         int ifaceNo = this.interfaces.FindIndex(x => ReferenceEquals(x, iface));
         if (ifaceNo >= 0)
         {
             busyInterface = ifaceNo;
             if (data.TTL > 0)
             {
                 data.TTL--;
                 this.SendData(data);
             }
             busyInterface = null;
         }
     }
 }