예제 #1
0
def network_alt(env):
    simpynet.PointToPoint.unique_number=0
    simpynet.Switch.unique_number=0
    h0 = simpynet.Host(env , simpynet.Mac("00.00.00.00.00") , simpynet.IP("192.0.0.0"))
    h1 = simpynet.Host(env , simpynet.Mac("00.00.00.00.01") , simpynet.IP("192.0.0.1"))

    link0 = simpynet.PointToPoint(env, lambda x,y:PROPAGATION_DELAY, lambda src,trg,l: TRANSMISSION_DELAY)
    link1 = simpynet.PointToPoint(env, lambda x,y:PROPAGATION_DELAY, lambda src,trg,l: TRANSMISSION_DELAY)

    switch = simpynet.Switch( env, lambda x, y : PROCESSING_DELAY )

    simpynet.physical.plug(link0,h0)
    simpynet.physical.plug(link0,switch)
    simpynet.physical.plug(link1,switch)
    simpynet.physical.plug(link1,h1)

    env.add_collector_functions( 'received_frames', switch.collector_receivedframes , TIME_INCREMENT )
    env.add_collector_functions( 'sent_frames', switch.collector_sentframes , TIME_INCREMENT )

    protocol0 = selective_repeat.Selective_Repeat( env, 10 )
    protocol0.timeout_time = 30
    protocol1 = selective_repeat.Selective_Repeat( env, 10 )
    protocol1.timeout_time = 30
    protocol0.add_handler( h0.add_transport_handler( protocol0.get_handler() ) )
    protocol1.add_handler( h1.add_transport_handler( protocol1.get_handler() ) )
    protocol0.send( NUMBER_OF_PACKETS , simpynet.IP("192.0.0.1") )
예제 #2
0
def network(env):
    simpynet.PointToPoint.unique_number=0
    simpynet.Switch.unique_number=0
    h0 = simpynet.Host(env , simpynet.Mac("00.00.00.00.00") , simpynet.IP("192.0.0.0"))
    h1 = simpynet.Host(env , simpynet.Mac("00.00.00.00.01") , simpynet.IP("192.0.0.1"))

    link0 = simpynet.PointToPoint(env, lambda x,y:PROPAGATION_DELAY, lambda src,trg,l: TRANSMISSION_DELAY)
    link1 = simpynet.PointToPoint(env, lambda x,y:PROPAGATION_DELAY, lambda src,trg,l: TRANSMISSION_DELAY)

    switch = simpynet.Switch( env, lambda x, y : PROCESSING_DELAY )

    tc = TimeCollector(env)
    tc.reset()
    simpynet.physical.plug(link0,h0)
    tc.add_handlers( switch , link0 )
    tc.add_handlers( switch , link1 )
    simpynet.physical.plug(link1,h1)

    env.add_collector_functions( 'data', tc.collector , float('inf')  )

    protocol0 = selective_repeat.Selective_Repeat( env, 10 )
    protocol0.timeout_time = 30
    protocol1 = selective_repeat.Selective_Repeat( env, 10 )
    protocol1.timeout_time = 30
    protocol0.add_handler( h0.add_transport_handler( protocol0.get_handler() ) )
    protocol1.add_handler( h1.add_transport_handler( protocol1.get_handler() ) )
    protocol0.send( NUMBER_OF_PACKETS , simpynet.IP("192.0.0.1") )
예제 #3
0
def example1(env):
    """
    Example at the link level.

    h1----l1----| r1 |---l2----h2

    """

    h1 = spn.Host(env, spn.Mac("00.00.00.00.00"), spn.IP("192.0.0.0"))
    h2 = spn.Host(env, spn.Mac("00.00.00.00.01"), spn.IP("192.0.0.1"))

    l1 = spn.Link(env, lambda x, y: 3, lambda src, trg, l: 1)
    l2 = spn.Link(env, lambda x, y: 3, lambda src, trg, l: 1)

    def host_handler(data):
        print data

    def forwarding(datagram, src_mac):
        if datagram.dst_ip == spn.IP("192.0.0.0"):
            return spn.Mac("00.00.00.00.00")
        else:
            return spn.Mac("00.00.00.00.01")

    r1 = spn.Router(env, spn.Mac("00.00.00.00.02"), forwarding,
                    lambda x, y: 0.1)

    spn.physical.plug(l1, r1)
    spn.physical.plug(l2, r1)
    spn.physical.plug(l1, h1)
    spn.physical.plug(l2, h2)

    send1 = h1.add_transport_handler(host_handler)
    send2 = h2.add_transport_handler(host_handler)

    def funct():
        yield env.timeout(0)
        send1("Ciao inviato da host 1", spn.IP("192.0.0.1"))

    def funct2():
        yield env.timeout(1)
        yield env.timeout(10)
        send2("Ciao inviato da host 2", spn.IP("192.0.0.0"))

    r_r = r1.collector_receiveddatagrams
    r_s = r1.collector_sentdatagrams
    r_t = r1.collector_processingtime
    h2_r = h2.collector_receiveddatagrams
    h1_s = h1.collector_sentdatagrams

    env.add_collector_functions('router received', r_r, 1)
    env.add_collector_functions('router sent', r_s, 2)
    env.add_collector_functions('router proc. time', r_t, 1)
    env.add_collector_functions('h2 received', h2_r, 1)
    env.add_collector_functions('h1 sent', h1_s, 1)

    env.process(funct())
    env.process(funct2())
예제 #4
0
파일: dns.py 프로젝트: dido18/simpynet
 def forwarding(datagram, router):
     if datagram.dst_ip == simpynet.IP("192.0.0.0"):
         return simpynet.Mac("00.00.00.00.00")
     if datagram.dst_ip == simpynet.IP("192.0.0.1"):
         return simpynet.Mac("00.00.00.00.01")
     if datagram.dst_ip == simpynet.IP("192.0.0.50"):
         return simpynet.Mac("00.00.00.00.02")
     if datagram.dst_ip == simpynet.IP("192.0.0.80"):
         return simpynet.Mac("00.00.00.00.03")
     else:
         return None
예제 #5
0
def sr_network(env):
    h0 = simpynet.Host(env, simpynet.Mac("00.00.00.00.00"),
                       simpynet.IP("192.0.0.0"))
    h1 = simpynet.Host(env, simpynet.Mac("00.00.00.00.01"),
                       simpynet.IP("192.0.0.1"))

    link = simpynet.PointToPoint(env, lambda x, y: PROPAGATION_DELAY,
                                 lambda src, trg, l: PROPAGATION_DELAY,
                                 lambda src, trg, l: LOSS_PROBABILITY)
    simpynet.physical.plug(link, h0)
    simpynet.physical.plug(link, h1)
    protocol0 = Selective_Repeat(env, 10)
    protocol1 = Selective_Repeat(env, 10)
    protocol0.add_handler(h0.add_transport_handler(protocol0.get_handler()))
    protocol1.add_handler(h1.add_transport_handler(protocol1.get_handler()))
    protocol0.send(NUMBER_OF_PACKETS, simpynet.IP("192.0.0.1"))
예제 #6
0
 def __init__(self, environment, window_size):
     self.host_handler = None
     self.env = environment
     self.window_size = window_size
     self.window = []
     self.current = 0
     self.ip_addr = simpynet.IP()
     self.number_of_packets = 0
     self.timeout_time = TIMEOUT_TIME
예제 #7
0
    def send_DHCP_OFFER(self, diz_opt, ip_offer):

        mac_client = diz_opt['CHADDR']
        ip_client = diz_opt['CIADDR']
        offer_msg = DHCP_OFFER_message(self.host.ip_addr, mac_client, ip_offer,
                                       ip_client)

        self.host.default_gateway = mac_client

        self.send_udp(offer_msg, self.my_port, 67,
                      spn.IP())  #sent in broadcast
예제 #8
0
    def send_DHCP_REQUEST(self, diz_opt, ip_server):
        """
        send_DHCPREQUEST( diz_option) - In response to the DHCP offer,
        the client replies with a DHCP request,  broadcast to the server,
        requesting the offered address.
        """
        ip_offer = diz_opt['YIADDR']
        qst_msg = DHCP_REQUEST_message(self.host.mac_addr, self.host.ip_addr,
                                       ip_server, ip_offer)

        self.send_udp(qst_msg, self.client_port, 68, spn.IP('255.255.255.255'))
예제 #9
0
def example(env):
    """

    dhcp_client------l1------dhcp_server

    """
    # --------------------------------------------------------

    c_host = spn.Host(env, spn.Mac('aa.aa.aa.aa.aa.aa'), spn.IP('0.0.0.0'))
    s_host = spn.Host(env, spn.Mac('bb.bb.bb.bb.bb.bb'), spn.IP('192.168.1.1'))

    client = spn.DHCP_client(env, c_host)
    server = spn.DHCP_server(env, s_host)

    def choose_ip_server(lista_ip):
        if len(lista_ip) > 0:
            return lista_ip.pop(0)

        else:
            return None

    def choose_ip_for_client():
        return '123'

    server.add_function_choose(choose_ip_for_client)

    client.add_function_choose(choose_ip_server)

    l1 = spn.Link(env, lambda x, y: 1, lambda src, trg, l: 1)

    spn.physical.plug(l1, c_host)
    spn.physical.plug(l1, s_host)

    def funct():
        yield env.timeout(1)
        client.send_DHCP_DISCOVERED()

    env.process(funct())
예제 #10
0
    def send_DHCP_DISCOVERED(self):
        """
        send_DHCP_DISCOVERED() - send a DHCPdiscovered message in broadcast
        on its local physical subnet.
        """

        dscv_msg = DHCP_DISCOVERED_message(self.host.mac_addr,
                                           self.host.ip_addr)
        self.send_udp(dscv_msg, self.client_port, 68,
                      spn.IP('255.255.255.255'))
        self.lgr.log(
            spn.__APPLICATION_LOG_N__, "   " + str(float(self.env.now)) +
            '   DHCP client sends DHCP DISCOVERED message to : 255.255.255.255'
        )
예제 #11
0
def example2(env):
    """"
    example figure 5.17 p. 492 (Computer Networking, 6th edition, Kurose-Ross).

    c----l1-----|
                |
    b----l2--- |so|---l4---ro
                |
    a----l3-----|
    """

    env = spn.Environment()

    host_c = spn.Host(env, spn.Mac('1A:23:F9:CD:06:9B'),
                      spn.IP('222.222.222.220'))
    host_b = spn.Host(env, spn.Mac('5C:66:AB:90:75:B1'),
                      spn.IP('222.222.222.221'))
    host_a = spn.Host(env, spn.Mac('49:BD:D2:C7:56:2A'),
                      spn.IP('222.222.222.222'))

    l1 = spn.Link(env,
                  trm_delay=lambda name, data: 1,
                  prg_delay=lambda s, r, l: 1)
    l2 = spn.Link(env,
                  trm_delay=lambda name, data: 1,
                  prg_delay=lambda s, r, l: 1)
    l3 = spn.Link(env,
                  trm_delay=lambda name, data: 1,
                  prg_delay=lambda s, r, l: 1)
    l4 = spn.Link(env,
                  trm_delay=lambda name, data: 1,
                  prg_delay=lambda s, r, l: 1)

    s0 = spn.Switch(env)

    def frw(datagram, mac):
        print mac
        if mac == spn.Mac('88:B2:2F:54:1A:0F'):

            print 'forwanding'
            return spn.Mac('5C:66:AB:90:75:B1')
        else:
            print 'no fornarding'

    r0 = spn.Router(env, spn.Mac('88:B2:2F:54:1A:0F'), frw)

    spn.physical.plug(host_c, l1)

    spn.physical.plug(l1, s0)
    spn.physical.plug(host_b, l2)
    spn.physical.plug(l2, s0)
    spn.physical.plug(host_a, l3)
    spn.physical.plug(l3, s0)
    spn.physical.plug(r0, l4)
    spn.physical.plug(l4, r0)

    def tcp_handler(segment):
        print 'attivato tcp'

    def h_receiver(name, data, trm_delay):  # receiver' s handler
        def _new_handler(name, data, trm_delay):
            yield env.timeout(trm_delay)

        return env.process(_new_handler(name, data, trm_delay))

    f_send = host_c.add_transport_handler(tcp_handler)
    host_b.add_handler('rcv', h_receiver)

    def rcv_r():
        pass

    host_c.default_gateway = spn.Mac('88:B2:2F:54:1A:0F')

    def sender():
        yield env.timeout(0)
        f_send('ciao da host 1', spn.IP('222.222.222.220'))

    env.process(sender())
예제 #12
0
 def funct2():
     yield env.timeout(1)
     yield env.timeout(10)
     send2("Ciao inviato da host 2", spn.IP("192.0.0.0"))
예제 #13
0
 def funct():
     yield env.timeout(0)
     send1("Ciao inviato da host 1", spn.IP("192.0.0.1"))
예제 #14
0
 def forwarding(datagram, src_mac):
     if datagram.dst_ip == spn.IP("192.0.0.0"):
         return spn.Mac("00.00.00.00.00")
     else:
         return spn.Mac("00.00.00.00.01")
예제 #15
0
 def sender():
     yield env.timeout(0)
     f_send('ciao da host 1', spn.IP('222.222.222.220'))
예제 #16
0
파일: dns.py 프로젝트: dido18/simpynet
def network(env):

    domains = {
        "moogle.com": simpynet.IP("192.0.0.50"),
        "mybank.com": simpynet.IP("192.0.0.80")
    }

    def dns_function(name):
        if domains.has_key(name):
            return domains[name]
        else:
            return None

    def sender(env):
        client.send("Hello", "moogle.com")
        yield env.timeout(5)
        client.send("Hello", "mybank.com")
        yield env.timeout(5)
        client.send("Hello", "random.com")
        client.send("Hello again", "moogle.com")

    def forwarding(datagram, router):
        if datagram.dst_ip == simpynet.IP("192.0.0.0"):
            return simpynet.Mac("00.00.00.00.00")
        if datagram.dst_ip == simpynet.IP("192.0.0.1"):
            return simpynet.Mac("00.00.00.00.01")
        if datagram.dst_ip == simpynet.IP("192.0.0.50"):
            return simpynet.Mac("00.00.00.00.02")
        if datagram.dst_ip == simpynet.IP("192.0.0.80"):
            return simpynet.Mac("00.00.00.00.03")
        else:
            return None

    router = simpynet.Router(env, simpynet.Mac("00.00.00.00.10"), forwarding,
                             lambda x, y: PROCESSING_DELAY)
    host = simpynet.Host(env, simpynet.Mac("00.00.00.00.00"),
                         simpynet.IP("192.0.0.0"))
    dns_host = simpynet.Host(env, simpynet.Mac("00.00.00.00.01"),
                             simpynet.IP("192.0.0.1"))
    server_host0 = simpynet.Host(env, simpynet.Mac("00.00.00.00.02"),
                                 simpynet.IP("192.0.0.50"))
    server_host1 = simpynet.Host(env, simpynet.Mac("00.00.00.00.03"),
                                 simpynet.IP("192.0.0.80"))

    host.set_default_gateway(simpynet.Mac("00.00.00.00.10"))
    dns_host.set_default_gateway(simpynet.Mac("00.00.00.00.10"))
    server_host0.set_default_gateway(simpynet.Mac("00.00.00.00.10"))
    server_host1.set_default_gateway(simpynet.Mac("00.00.00.00.10"))

    client = Client(env, host, dns_host.ip_addr)
    dns = DNS_Server(env, dns_host, dns_function)
    moogle = Server(env, server_host0, "moogle.com")
    mybank = Server(env, server_host1, "mybank.com")

    link0 = simpynet.PointToPoint(env, lambda x, y: PROPAGATION_DELAY,
                                  lambda src, trg, l: PROPAGATION_DELAY)
    link1 = simpynet.PointToPoint(env, lambda x, y: PROPAGATION_DELAY,
                                  lambda src, trg, l: PROPAGATION_DELAY)
    link2 = simpynet.PointToPoint(env, lambda x, y: PROPAGATION_DELAY,
                                  lambda src, trg, l: PROPAGATION_DELAY)
    link3 = simpynet.PointToPoint(env, lambda x, y: PROPAGATION_DELAY,
                                  lambda src, trg, l: PROPAGATION_DELAY)

    simpynet.physical.plug(link0, host)
    simpynet.physical.plug(link0, router)
    simpynet.physical.plug(link1, dns_host)
    simpynet.physical.plug(link1, router)
    simpynet.physical.plug(link2, server_host0)
    simpynet.physical.plug(link2, router)
    simpynet.physical.plug(link3, server_host1)
    simpynet.physical.plug(link3, router)

    env.process(sender(env))