예제 #1
0
        public override void SendPacket(IPacket packet, IInterfaceView from)
        {
            if (packet == null)
                throw new ArgumentNullException ();

            if (from == null)
                throw new ArgumentNullException ();

            if (!this.endpoints.Contains (from))
                throw new ArgumentException ();

            var endpoint_index = packet.Data [0];
            if (endpoint_index >= this.EndPointsCount)
                return;

            this.State = StateMock.BUSY;

            this.clock.RegisterActionAtTime (MathHelper.CalculateTime (packet.Data.Length, this.Speed),
                                             () => {
                                                 this.State = StateMock.FREE;
                                                 this.OnTransmit (this, packet);
                                                 this.endpoints [endpoint_index].ReceivePacket (
                                                     packet);
                                             });
        }
예제 #2
0
 public void DetachEndPoint(IInterfaceView iface)
 {
     Contract.Requires <ArgumentNullException> (iface != null);
     Contract.Ensures (Contract.ForAll (this.EndPoints, i => i != iface));
     Contract.EnsuresOnThrow <InterfaceNotAttachedToBackboneException> (iface.Backbone == null ||
                                                                        Contract.ForAll (this.EndPoints,
                                                                                         i => i != iface));
 }
예제 #3
0
        public void DispatchPacket_ToInterface(IPacket packet, IInterfaceView iface)
        {
            if (packet == null)
                throw new ArgumentNullException ("packet");

            if (iface == null)
                throw new ArgumentNullException ("iface");
        }
예제 #4
0
 public void AttachEndPoint(IInterfaceView iface)
 {
     Contract.Requires <ArgumentNullException> (iface != null);
     Contract.Ensures (Contract.Exists (this.EndPoints, i => i == iface));
     Contract.EnsuresOnThrow <InterfaceAlreadyAttachedToBackboneException> (iface.Backbone != null ||
                                                                            Contract.Exists (this.EndPoints,
                                                                                             i => i == iface));
     Contract.EnsuresOnThrow <EndPointsOverflowException> (this.EndPointsCount >= this.EndPointsCapacity);
 }
 /// <summary>
 ///   Получает префикс имени интерфейса, связанный с классом объекта интерфейса.
 /// </summary>
 /// <param name = "iface">Объект интерфейса, префикс имени которого нужно получить.</param>
 /// <returns>Префикс имени интерфейса или <c>null</c>, если атрибут не найден.</returns>
 /// <exception cref = "ArgumentNullException"><paramref name = "iface" /> является <c>null</c>.</exception>
 public static string GetPrefix(IInterfaceView iface)
 {
     if (iface == null)
         throw new ArgumentNullException ("iface");
     return
         (from InterfacePrefixAttribute attr in
              iface.GetType ().GetCustomAttributes (typeof (InterfacePrefixAttribute), false)
          select attr.Prefix).FirstOrDefault ();
 }
예제 #6
0
        /// <inheritdoc />
        public override void SendPacket (IPacket packet, IInterfaceView from) {
            /*
             * todo:
             * 1. –еализовать возможность full-duplex, half-duplex
             * 2. ”точнить максимальный интервал ожидани¤ ретрансл¤ции в документации.
             * 3. ¬ытащить константу ожидани¤ отдельно (дл¤ возможности переопределени¤).
             * 4. —делать расчЄт времени передачи сообщени¤.
             */

            if (packet == null)
                throw new ArgumentNullException ("packet");

            if (from == null)
                throw new ArgumentNullException ("from");

            if (!this.endpoints.Contains (from))
                throw new InterfaceNotAttachedToBackboneException (from.Name, this.Name);

            if (this.endpoints.Count != 2)
                throw new Exception ();

            //if (this.State.Equals (WireState.WIRE_BUSY)) {
            //    this.packets.Enqueue (new Pair <IPacket, IInterfaceView> (packet, from));
            //    var time = (ulong) new Random ().Next (100);
            //    this.clock.RegisterActionAtTime (time,
            //                                     () => {
            //                                         var entry = this.packets.Dequeue ();
            //                                         this.SendPacket (entry.First, entry.Second);
            //                                     });
            //    return;
            //}

            this.State = WireState.WIRE_BUSY;

            var iface = (this.EndPoints.First () == from) ? this.EndPoints.Last () : this.EndPoints.First ();

            if (new Random ().NextDouble () < this.LossPercent)
                return;

            this.clock.RegisterAction (() => {
                                           this.State = WireState.WIRE_FREE;
                                           this.OnTransmit.Invoke (this, packet);
                                           iface.ReceivePacket (packet);
                                       });
        }
        public override void SendPacket(IPacket packet, IInterfaceView from)
        {
            if (packet == null)
                throw new ArgumentNullException ();

            if (from == null)
                throw new ArgumentNullException ();

            if (!this.endpoints.Contains (from))
                throw new ArgumentException ();

            this.State = StateMock.BUSY;

            foreach (var endpoint in this.EndPoints.Where (_ => _ != from)) {
                var endpoint1 = endpoint;
                this.clock.RegisterActionAtTime (MathHelper.CalculateTime (packet.Data.Length, this.Speed),
                                                 () => {
                                                     this.State = StateMock.FREE;
                                                     this.OnTransmit (this, packet);
                                                     endpoint1.ReceivePacket (packet);
                                                 });
            }
        }
예제 #8
0
 public void ProcessPacket(IPacket packet, IInterfaceView from)
 {
 }
예제 #9
0
 public abstract void SendPacket(IPacket packet, IInterfaceView from);
 public void SendPacket(IPacket packet, IInterfaceView from)
 {
     Contract.Requires <ArgumentNullException> (packet != null);
     Contract.Requires <ArgumentNullException> (from != null);
 }
예제 #11
0
 public abstract void ProcessPacket(IPacket packet, IInterfaceView from);
예제 #12
0
        /// <inheritdoc />
        public virtual void DetachEndPoint(IInterfaceView iface)
        {
            if (iface.Backbone != this || ! this.endpoints.Contains (iface))
                throw new InterfaceNotAttachedToBackboneException (iface.Name, this.Name);

            this.endpoints.Remove (iface);
        }
예제 #13
0
        /// <inheritdoc />
        public virtual void AttachEndPoint(IInterfaceView iface)
        {
            if (iface.Backbone != null || this.endpoints.Contains (iface))
                throw new InterfaceAlreadyAttachedToBackboneException (iface.Name);

            if (this.EndPointsCount >= this.EndPointsCapacity)
                throw new EndPointsOverflowException (this.Name, this.EndPointsCapacity);

            this.endpoints.Add (iface);
        }
예제 #14
0
 public void ProcessPacket(IPacket packet, IInterfaceView from)
 {
     Contract.Requires <ArgumentNullException> (packet != null);
     Contract.Requires <ArgumentNullException> (from != null);
     Contract.Requires <InterfaceNotAttachedToDeviceException> (Contract.Exists (this.Interfaces, i => i == from));
 }
예제 #15
0
 public void SendPacket(IPacket packet, IInterfaceView from)
 {
 }
예제 #16
0
 public virtual void DispatchPacket(IPacket packet, IInterfaceView iface)
 {
 }
예제 #17
0
 public void DetachEndPoint(IInterfaceView iface)
 {
 }
 public void DispatchPacket(IPacket packet, IInterfaceView iface)
 {
     Contract.Requires <ArgumentNullException> (packet != null);
     Contract.Requires <ArgumentNullException> (iface != null);
 }
예제 #19
0
        public void DetachEndPoint(IInterfaceView iface)
        {
            if (iface == null)
                throw new ArgumentNullException ();

            if (iface.Backbone != this || ! this.endpoints.Contains (iface))
                throw new ArgumentException ();

            for (var i = 0; i < this.endpoints.Count; ++ i) {
                if (this.endpoints [i] == iface) {
                    this.endpoints [i] = null;
                    break;
                }
            }
        }
예제 #20
0
        public void ProcessPacket(IPacket packet, IInterfaceView from)
        {
            if (packet == null || from == null)
                throw new ArgumentNullException ();

            if (! this.interfaces.Contains (from))
                throw new ArgumentException ();

            if (this.OnBeforeProcessPacket != null)
                this.OnBeforeProcessPacket.Invoke (this);

            if (this.OnProcessPacket != null)
                this.OnProcessPacket.Invoke (packet, from);
        }
예제 #21
0
        public void AttachEndPoint(IInterfaceView iface)
        {
            if (iface == null)
                throw new ArgumentNullException ();

            if (iface.Backbone != null)
                throw new ArgumentException ();

            for (var i = 0; i < this.endpoints.Count; ++ i) {
                if (this.endpoints [i] == null) {
                    this.endpoints [i] = iface;
                    return;
                }
            }

            throw new EndPointsOverflowException (this.Name, this.EndPointsCapacity);
        }
예제 #22
0
 public void DispatchPacket(IPacket packet, IInterfaceView iface)
 {
     // todo
 }