#  client-server-3.dml
#
#  a simple two-host network running a trivial client/server protocol using TCP transport. 
#  At a random time in the interval (10 sec, 20 sec) of simulated time the client opens
#  a TCP connection to server and requests "file_size" bytes of data. The the server will
#  do just that. That's it.
#
#  server                              client
#             100 Mbs / 2 ms delay 
#  1(0)---------------------------------2(0) 
#

Net [

  frequency 1000000000    # 1 nanosecond time resolution

  # new feature since ssfnet_0.9 - control of random number streams.
  # In this example, used by class SSF.OS.TCP.tcpSessionMaster to randomize
  # the TCP system clock phases across all hosts
  
  randomstream [
    generator "MersenneTwister"
    stream "seedstarter1"
    reproducibility_level "timeline"
  ]

  host [
    id 2
    interface [id 0 bitrate 100000000 latency 0.0]
    _extends .dictionary.typicalClient
  ]
      
  host [
    id 1
    interface [id 0 bitrate 100000000 latency 0.0]
    _extends .dictionary.typicalServer
  ]
  
  link [attach 1(0) attach 2(0) delay 0.002]

  traffic [
    pattern [
      client 2
      servers [nhi 1(0) port 1600]
    ]
  ]

] # end of Net

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# it is efficient to isolate repeating attribute patterns and keep them in a "design dictionary"
# which is just another DML attribute,
# and use the _find keyword to substitute them by key pathname wherever you need them,
# or inherit from them using the _extends keyword.

dictionary [

  typicalClient [
    graph [
      ProtocolSession [
        name client use SSF.OS.TCP.test.tcpClient
        start_time 1.0            # earliest time to send request to server
        start_window 1.0          # send request to server at randomly chosen time
                                  # in interval [start_time, start_time+start_window]
        file_size 10000000        # requested file size (payload bytes)
        _find .dictionary.appsession.request_size
        _find .dictionary.appsession.show_report
        _find .dictionary.appsession.debug
      ]
      ProtocolSession [name socket use SSF.OS.Socket.socketMaster]
      ProtocolSession [name tcp use SSF.OS.TCP.tcpSessionMaster
                       _find .dictionary.tcpinit]
      ProtocolSession [name ip use SSF.OS.IP]
    ]
  ]
  
  typicalServer [
    graph [
      ProtocolSession [
        name server use SSF.OS.TCP.test.tcpServer
        port 1600          # server's well known port
        client_limit  10   # max number of contemporaneously allowed clients
                           # if omitted, default is no limit
        _find .dictionary.appsession.request_size
        _find .dictionary.appsession.show_report
        _find .dictionary.appsession.debug
      ]
      ProtocolSession [name socket use SSF.OS.Socket.socketMaster]
      ProtocolSession [name tcp use SSF.OS.TCP.tcpSessionMaster
                           _find .dictionary.tcpinit]
      ProtocolSession [name ip use SSF.OS.IP]
    ]
  ]
  
  # shared TCP configuration
  
  tcpinit[
    ISS 10000               # initial sequence number
    MSS 1000                # maximum segment size
    RcvWndSize  32          # receive buffer size
    SendWndSize 32          # maximum send window size
    SendBufferSize 128      # send buffer size
    MaxRexmitTimes 12       # maximum retransmission times before drop 
    TCP_SLOW_INTERVAL 0.5   # granularity of TCP slow timer
    TCP_FAST_INTERVAL 0.2   # granularity of TCP fast(delay-ack) timer
    MSL 60.0                # maximum segment lifetime
    MaxIdleTime 600.0       # maximum idle time for drop a connection
    delayed_ack false       # delayed ack option
    fast_recovery true      # implement fast recovery algorithm 
    show_report true        # print a summary connection report
  ]

  # the client-server protocol needs to agree on some things
  
  appsession [
    request_size  4         # client request datagram size (in bytes)
    show_report true        # print client-server session summary report
    debug false             # print verbose client/server diagnostics
  ]
]