Exemple #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;
 }
Exemple #2
0
 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));
 }
        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());
        }
        private void RecordDequeueAndTransmit(NodeIdentifier nodeId, PacketIdentifier packetId, LinkIdentifier linkId)
        {
            Record(new NetworkEvent.PacketDequeued(nodeId));

            Record(new NetworkEvent.PacketTransmissionStarted(packetId, linkId));
        }
 private bool IsLinkFull(LinkIdentifier linkId)
 => State.Links[linkId].IsFull;
Exemple #6
0
 public Connected(PortDirection port, LinkIdentifier linkId, ConnectionDirection direction) : base(port)
 {
     LinkId    = linkId ?? throw new ArgumentNullException(nameof(linkId));
     Direction = direction;
 }
Exemple #7
0
 public PacketTransmissionFinished(PacketIdentifier packetId, LinkIdentifier linkId)
 {
     PacketId = packetId ?? throw new System.ArgumentNullException(nameof(packetId));
     LinkId   = linkId ?? throw new System.ArgumentNullException(nameof(linkId));
 }
Exemple #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()
     );