예제 #1
0
파일: Topology.py 프로젝트: smbz/vns
 def send_ping_from_node(self, node_name, intf_name, dst_ip):
     """Sends a ping from the request node's specified interface.  If the
     node or port is invalid, TIBadNodeOrPort is raised."""
     _, intf = self.get_node_and_intf_with_link(node_name, intf_name)
     mac_dst = intf.link.get_other(intf).mac
     mac_src = intf.mac
     mac_type = '\x08\x00'
     ethernet_hdr = mac_dst + mac_src + mac_type
     src_ip = intf.ip
     ip_hdr = Packet.cksum_ip_hdr('\x45\x00\x00\x54\x00\x00\x40\x00\x40\x01\x00\x00' + src_ip + dst_ip)
     # 56 bytes of data needed since IP tlen field set to expect a 64B payload (8B ICMP hdr + 56B data)
     icmp_data = 'This echo request sent through VNS for a topo interactor'
     icmp = Packet.cksum_icmp_pkt('\x08\x00\x00\x00\x00\x00\x00\x01' + icmp_data)
     ethernet_frame = ethernet_hdr + ip_hdr + icmp
     intf.link.send_to_other(intf, ethernet_frame)
예제 #2
0
파일: Topology.py 프로젝트: yhyan/vns
 def send_ping_from_node(self, node_name, intf_name, dst_ip):
     """Sends a ping from the request node's specified interface.  If the
     node or port is invalid, TIBadNodeOrPort is raised."""
     _, intf = self.get_node_and_intf_with_link(node_name, intf_name)
     mac_dst = intf.link.get_other(intf).mac
     mac_src = intf.mac
     mac_type = '\x08\x00'
     ethernet_hdr = mac_dst + mac_src + mac_type
     src_ip = intf.ip
     ip_hdr = Packet.cksum_ip_hdr('\x45\x00\x00\x54\x00\x00\x40\x00\x40\x01\x00\x00' + src_ip + dst_ip)
     # 56 bytes of data needed since IP tlen field set to expect a 64B payload (8B ICMP hdr + 56B data)
     icmp_data = 'This echo request sent through VNS for a topo interactor'
     icmp = Packet.cksum_icmp_pkt('\x08\x00\x00\x00\x00\x00\x00\x01' + icmp_data)
     ethernet_frame = ethernet_hdr + ip_hdr + icmp
     intf.link.send_to_other(intf, ethernet_frame)
예제 #3
0
    def handle_packet_from_outside(data):
        logging.debug('--------------------------------------------------')
        logging.debug('--------------------------------------------------')
        logging.debug('got packet: %s' % pktstr(data))
        pkt = Packet(data)

        if pkt.is_tcp() and pkt.is_valid_tcp():
            logging.debug('passing on tcp packet ...')
            tcp_conn = server.handle_tcp(pkt)
            if tcp_conn:
                tcp_pts = tcp_conn.get_packets_to_send()
                if tcp_pts:
                    for tcp, data in tcp_pts:
                        eth = pkt.get_reversed_eth()
                        ip = pkt.get_reversed_ip(new_ttl=64,
                                                 new_tlen=pkt.ip_hlen +
                                                 len(tcp) + len(data))
                        p = eth + ip + Packet.cksum_tcp_hdr(ip, tcp,
                                                            data) + data
                        logging.debug('sending packet: %s' % pktstr(p))
                        try:
                            raw_socket.send(p)
                        except socket.error:
                            logging.exception('failed to send packet')
                            sys.exit(-1)
                else:
                    logging.debug('no packets to send back')
예제 #4
0
파일: Topology.py 프로젝트: smbz/vns
 def send_packets(self):
     """Send any waiting packets"""
     if self.intf and self.pkt:
         for (_, tcp_conn) in self.http_server.connections.iteritems():
             if tcp_conn and not tcp_conn.dead:
                 tcp_pts = tcp_conn.get_packets_to_send()
                 for tcp, data in tcp_pts:
                     eth = self.pkt.get_reversed_eth()
                     ip = self.pkt.get_reversed_ip(new_ttl=64, new_tlen=self.pkt.ip_hlen+len(tcp)+len(data))
                     pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                     logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
                     self.intf.link.send_to_other(self.intf, pkt_out)
예제 #5
0
파일: Topology.py 프로젝트: yhyan/vns
 def handle_http_request(self, intf, pkt):
     """Forward the received packet from an HTTP client to the web server."""
     tcp_conn = self.http_server.handle_tcp(pkt)
     if tcp_conn:
         tcp_pts = tcp_conn.get_packets_to_send()
         if tcp_pts:
             for tcp, data in tcp_pts:
                 eth = pkt.get_reversed_eth()
                 ip = pkt.get_reversed_ip(new_ttl=64, new_tlen=pkt.ip_hlen+len(tcp)+len(data))
                 pkt_out = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                 logging.debug('%s sending packet from HTTP server: %s' % (self, pktstr(pkt_out)))
                 intf.link.send_to_other(intf, pkt_out)
예제 #6
0
파일: HTTPServer.py 프로젝트: dound/vns
    def handle_packet_from_outside(data):
        logging.debug('--------------------------------------------------')
        logging.debug('--------------------------------------------------')
        logging.debug('got packet: %s' % pktstr(data))
        pkt = Packet(data)

        if pkt.is_tcp() and pkt.is_valid_tcp():
            logging.debug('passing on tcp packet ...')
            tcp_conn = server.handle_tcp(pkt)
            if tcp_conn:
                tcp_pts = tcp_conn.get_packets_to_send()
                if tcp_pts:
                    for tcp, data in tcp_pts:
                        eth = pkt.get_reversed_eth()
                        ip = pkt.get_reversed_ip(new_ttl=64, new_tlen=pkt.ip_hlen+len(tcp)+len(data))
                        p = eth + ip + Packet.cksum_tcp_hdr(ip, tcp, data) + data
                        logging.debug('sending packet: %s' % pktstr(p))
                        try:
                            raw_socket.send(p)
                        except socket.error:
                            logging.exception('failed to send packet')
                            sys.exit(-1)
                else:
                    logging.debug('no packets to send back')