Пример #1
0
    def send_gre_nsh(self):
        # create a raw socket
        try:
            s = socket.socket(
                socket.AF_INET, socket.SOCK_RAW,
                socket.IPPROTO_GRE)  # set port to GRE encapsulation

        except socket.error as msg:
            print('Socket could not be created. Error Code : ' + str(msg[0]) +
                  ' Message ' + msg[1])
            sys.exit()

        # Building client packet to send to SFF
        packet = build_nsh_eth_header(self.encapsulate_header_values,
                                      self.base_header_values,
                                      self.ctx_header_values,
                                      self.ethernet_values)

        udp_inner_packet = build_udp_packet("172.20.33.195", "10.0.1.1", 10000,
                                            self.dest_port,
                                            "test".encode('utf-8'))
        gre_nsh_ethernet_packet = packet + udp_inner_packet
        logger.info("Sending %s packet to SFF: %s", self.encapsulate_type,
                    self.dest_addr)
        logger.debug("Packet dump: %s",
                     binascii.hexlify(gre_nsh_ethernet_packet))

        s.sendto(gre_nsh_ethernet_packet, (self.dest_addr, 0))
Пример #2
0
    def connection_made(self, transport):
        self.transport = transport
        # Building client IP packet to send to SFF
        packet = build_nsh_eth_header(self.encapsulate_header_values,
                                      self.base_header_values,
                                      self.ctx_header_values,
                                      self.ethernet_values)

        # VXLAN header is now built as part of nsh_eth header
        # packet = build_vxlan_header(self.encapsulate_header_values,
        # self.ethernet_values)
        udp_inner_packet = build_udp_packet(self.inner_header.inner_src_ip,
                                            self.inner_header.inner_dest_ip,
                                            self.inner_header.inner_src_port,
                                            self.inner_header.inner_dest_port,
                                            "test".encode('utf-8'))

        gpe_nsh_ethernet_packet = packet + udp_inner_packet
        logger.debug("Ethernet dump: ",
                     binascii.hexlify(gpe_nsh_ethernet_packet))
        logger.info("Sending %s packet to SFF: %s", self.encapsulate_type,
                    (self.remote_sff_ip, self.remote_sff_port))
        # Send the packet
        signal.signal(signal.SIGALRM, self.alarm_handler)
        signal.alarm(5)
        try:
            self.transport.sendto(gpe_nsh_ethernet_packet,
                                  (self.remote_sff_ip, self.remote_sff_port))
        except socket.error as msg:
            print('Failed to send packet. Error Code : ' + str(msg))
            sys.exit()
Пример #3
0
    def connection_made(self, transport):
        self.transport = transport
        # Building client IP packet to send to SFF
        packet = build_nsh_eth_header(self.encapsulate_header_values,
                                      self.base_header_values,
                                      self.ctx_header_values,
                                      self.ethernet_values)

        # VXLAN header is now built as part of nsh_eth header
        # packet = build_vxlan_header(self.encapsulate_header_values,
        # self.ethernet_values)
        udp_inner_packet = build_udp_packet(self.inner_header.inner_src_ip, self.inner_header.inner_dest_ip,
                                            self.inner_header.inner_src_port,
                                            self.inner_header.inner_dest_port, "test".encode('utf-8'))

        gpe_nsh_ethernet_packet = packet + udp_inner_packet
        logger.debug("Ethernet dump: ", binascii.hexlify(gpe_nsh_ethernet_packet))
        logger.info("Sending %s packet to SFF: %s", self.encapsulate_type, (self.remote_sff_ip, self.remote_sff_port))
        # Send the packet
        signal.signal(signal.SIGALRM, self.alarm_handler)
        signal.alarm(5)
        try:
            self.transport.sendto(gpe_nsh_ethernet_packet, (self.remote_sff_ip, self.remote_sff_port))
        except socket.error as msg:
            print('Failed to send packet. Error Code : ' + str(msg))
            sys.exit()
Пример #4
0
    def send_gre_nsh(self):
        # create a raw socket
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_GRE)  # set port to GRE encapsulation

        except socket.error as msg:
            print('Socket could not be created. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
            sys.exit()

        # Building client packet to send to SFF
        packet = build_nsh_eth_header(self.encapsulate_header_values,
                                      self.base_header_values,
                                      self.ctx_header_values,
                                      self.ethernet_values)

        udp_inner_packet = build_udp_packet("172.20.33.195", "10.0.1.1", 10000, self.dest_port, "test".encode('utf-8'))
        gre_nsh_ethernet_packet = packet + udp_inner_packet
        logger.info("Sending %s packet to SFF: %s", self.encapsulate_type, self.dest_addr)
        logger.debug("Packet dump: %s", binascii.hexlify(gre_nsh_ethernet_packet))

        s.sendto(gre_nsh_ethernet_packet, (self.dest_addr, 0))