예제 #1
0
 public PortAssigned(NodeIdentifier nodeId, PortDirection port, LinkIdentifier linkId, ConnectionDirection direction)
 {
     NodeId    = nodeId ?? throw new System.ArgumentNullException(nameof(nodeId));
     Port      = port;
     LinkId    = linkId ?? throw new System.ArgumentNullException(nameof(linkId));
     Direction = direction;
 }
예제 #2
0
파일: Link.cs 프로젝트: deimors/PacketFlow
 public Link(LinkIdentifier id, NodeIdentifier source, NodeIdentifier sink, LinkAttributes attributes, ImmutableList <PacketIdentifier> content)
 {
     Id         = id ?? throw new ArgumentNullException(nameof(id));
     Source     = source ?? throw new ArgumentNullException(nameof(source));
     Sink       = sink ?? throw new ArgumentNullException(nameof(sink));
     Attributes = attributes ?? throw new ArgumentNullException(nameof(attributes));
     Content    = content ?? throw new ArgumentNullException(nameof(content));
 }
예제 #3
0
        private Maybe <NetworkError> LinkNodes(NetworkCommand.LinkNodes command)
        {
            var newLinkId = new LinkIdentifier();

            return(this.BuildCommand <NetworkEvent, NetworkError>()
                   .FailIf(() => !State.Nodes.ContainsKey(command.Source), () => NetworkError.UnknownNode)
                   .FailIf(() => !State.Nodes.ContainsKey(command.Sink), () => NetworkError.UnknownNode)
                   .FailIf(() => !State.Nodes[command.Source].Ports.IsDisconnected(command.SourcePort), () => NetworkError.PortFull)
                   .FailIf(() => !State.Nodes[command.Sink].Ports.IsDisconnected(command.SinkPort), () => NetworkError.PortFull)
                   .Record(() => new NetworkEvent.LinkAdded(new Link(newLinkId, command.Source, command.Sink, command.Attributes, ImmutableList <PacketIdentifier> .Empty)))
                   .Record(() => new NetworkEvent.PortAssigned(command.Source, command.SourcePort, newLinkId, ConnectionDirection.Output))
                   .Record(() => new NetworkEvent.PortAssigned(command.Sink, command.SinkPort, newLinkId, ConnectionDirection.Input))
                   .Execute());
        }
예제 #4
0
        private void RecordDequeueAndTransmit(NodeIdentifier nodeId, PacketIdentifier packetId, LinkIdentifier linkId)
        {
            Record(new NetworkEvent.PacketDequeued(nodeId));

            Record(new NetworkEvent.PacketTransmissionStarted(packetId, linkId));
        }
예제 #5
0
 private bool IsLinkFull(LinkIdentifier linkId)
 => State.Links[linkId].IsFull;
예제 #6
0
 public Connected(PortDirection port, LinkIdentifier linkId, ConnectionDirection direction) : base(port)
 {
     LinkId    = linkId ?? throw new ArgumentNullException(nameof(linkId));
     Direction = direction;
 }
예제 #7
0
 public PacketTransmissionFinished(PacketIdentifier packetId, LinkIdentifier linkId)
 {
     PacketId = packetId ?? throw new System.ArgumentNullException(nameof(packetId));
     LinkId   = linkId ?? throw new System.ArgumentNullException(nameof(linkId));
 }
예제 #8
0
 public NodePortSet ConnectPort(PortDirection port, LinkIdentifier linkId, ConnectionDirection direction)
 => new NodePortSet(
     _ports
     .Select((p, i) => i == (int)port ? new NodePort.Connected(port, linkId, direction) : p)
     .ToArray()
     );