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); }); }
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)); }
public void DispatchPacket_ToInterface(IPacket packet, IInterfaceView iface) { if (packet == null) throw new ArgumentNullException ("packet"); if (iface == null) throw new ArgumentNullException ("iface"); }
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 (); }
/// <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); }); } }
public void ProcessPacket(IPacket packet, IInterfaceView from) { }
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); }
public abstract void ProcessPacket(IPacket packet, IInterfaceView from);
/// <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); }
/// <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); }
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)); }
public void SendPacket(IPacket packet, IInterfaceView from) { }
public virtual void DispatchPacket(IPacket packet, IInterfaceView iface) { }
public void DetachEndPoint(IInterfaceView iface) { }
public void DispatchPacket(IPacket packet, IInterfaceView iface) { Contract.Requires <ArgumentNullException> (packet != null); Contract.Requires <ArgumentNullException> (iface != null); }
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; } } }
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); }
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); }
public void DispatchPacket(IPacket packet, IInterfaceView iface) { // todo }