#  udpXnet.dml
#  2 X 2  network with UDP clients and servers, interfaces in NHI addressing
#
#   client 11(0)------1(1)                           2(1)------12(0) client
#                        \                          /
#                        [R1] 1(0)------------2(0)[R2]
#                        /                          \
#   server 21(0)------1(2)                           2(2)------22(0) server


Net [

  frequency 1000000000    # 1 nanosecond time resolution
  
  randomstream [
    generator "MersenneTwister"
    stream "seedstartingstring1234567890"
    reproducibility_level "host"
  ]
    
  # ROUTERS AND POINT-TO-POINT LINKS -----------------------------------
  
  router [ 
    idrange [from 1 to 2]
    graph [ProtocolSession [name ip use SSF.OS.IP]]
    interface [ id 0 buffer 8000 _extends .dictionary.100BaseT]
    interface [ idrange [from 1 to 3] buffer 16000 _extends .dictionary.10BaseT]
    route [dest default interface 0]
  ]

  link [attach 1(0) attach 2(0) delay 0.005]

  link [attach 1(1) attach 11(0) delay 0.001]
  link [attach 1(2) attach 21(0) delay 0.001]

  link [attach 2(1) attach 12(0) delay 0.001]
  link [attach 2(2) attach 22(0) delay 0.001]

 # CLIENTS AND SERVERS -------------------------------------------------

  host [ idrange [from 11 to 12]
    _extends .dictionary.standardClient
  ]
  host [ idrange [from 21 to 22]
    _extends .dictionary.standardServer
  ]
  
 # CLIENTS-SERVER TRAFFIC PATTERN --------------------------------------
 
  # "left side" client can request data from any server
  # "right side" client can request data only from "left side" server
  
  traffic [
    pattern [
      client 11
      servers [nhi_range [from 21(0) to 22(0)] port 1600]
    ]
    pattern [
      client 12
      servers [nhi 21(0) port 1600]
    ]
  ]
 
] # end of Net

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

dictionary [

  # standard network interfaces
  10BaseT [
    bitrate 10000000
    latency 0.0001
  ]
  100BaseT [
    bitrate 100000000
    latency 0.0001
  ]

  udpinit [
    max_datagram_size 10000 # max UDP datagram size (payload bytes)
    debug false             # print verbose UDP diagnostics
  ]

  # the UDP client-server protocol needs to agree on some things
  appsession [
    request_size 256        # client request datagram size (bytes)
    datagram_size 1000      # server datagram payload size (bytes)
    send_interval 0.1       # time interval between consecutive server datagrams in seconds,
                            # if undefined, datagrams are sent back to back 
    show_report true        # print client-server session summary report
    debug true              # print verbose client/server diagnostics
  ]
  
  standardClient [
    interface [id 0 _extends .dictionary.10BaseT]
    route [dest default interface 0]
    graph [
      ProtocolSession [
        name client use SSF.OS.UDP.test.udpStreamClient
        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 1000000   # requested file size (payload bytes)
        _find .dictionary.appsession.request_size
        _find .dictionary.appsession.datagram_size
        _find .dictionary.appsession.show_report
        _find .dictionary.appsession.debug
      ]
      ProtocolSession [name socket use SSF.OS.Socket.socketMaster]
      ProtocolSession [name udp use SSF.OS.UDP.udpSessionMaster
                       _find .dictionary.udpinit]
      ProtocolSession [name ip use SSF.OS.IP]
    ]
  ]
  standardServer [
    interface [id 0 _extends .dictionary.10BaseT]
    route [dest default interface 0]
    graph [
      ProtocolSession [
        name server use SSF.OS.UDP.test.udpStreamServer
        port 1600            # server's well known port
        client_limit  10   # max number of contemporaneously allowed clients
        _find .dictionary.appsession.request_size
        _find .dictionary.appsession.datagram_size
        _find .dictionary.appsession.send_interval
        _find .dictionary.appsession.show_report
        _find .dictionary.appsession.debug
      ]
      ProtocolSession [name socket use SSF.OS.Socket.socketMaster]
      ProtocolSession [name udp use SSF.OS.UDP.udpSessionMaster
                           _find .dictionary.udpinit]
      ProtocolSession [name ip use SSF.OS.IP]
    ]
  ]
 
] # end of dictionary