当前位置: 首页>>代码示例>>Python>>正文


Python icmp.icmp函数代码示例

本文整理汇总了Python中ryu.lib.packet.icmp.icmp函数的典型用法代码示例。如果您正苦于以下问题:Python icmp函数的具体用法?Python icmp怎么用?Python icmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了icmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_Packet_in_2_icmpEcho1

    def test_Packet_in_2_icmpEcho1(self):
        print "*** Case2: HOST2のMAC未学習の時、HOST1からICMP Echoを受信 ***"

        sr = SimpleForward()
        dstMac = ROUTER_MACADDR1
        srcMac = HOST_MACADDR1
        srcIp = HOST_IPADDR1
        dstIp = HOST_IPADDR2
        targetMac = dstMac
        targetIp = dstIp
        ttl = 64

        datapath = _Datapath()
        e = ethernet(dstMac, srcMac, ether.ETH_TYPE_IP)

        iph = ipv4(4, 5, 0, 0, 0, 2, 0, ttl, 1, 0, srcIp, dstIp)
        echo = icmp.echo(1, 1, 'unit test')
        icmph = icmp.icmp(8, 0, 0, echo)

        p = Packet()
        p.add_protocol(e)
        p.add_protocol(iph)
        p.add_protocol(icmph)
        p.serialize()

        packetIn = OFPPacketIn(datapath, match=OFPMatch(in_port=1), data=buffer(p.data))

        ev = ofp_event.EventOFPPacketIn(packetIn)

        result = sr.packet_in_handler(ev)
        self.assertEqual(result, 1)
        print ""
开发者ID:TakeshiTseng,项目名称:simpleRouter,代码行数:32,代码来源:test_SimpleForward.py

示例2: _handle_icmp

    def _handle_icmp(self, ev, subname):
        msg = ev.msg
        datapath = msg.datapath
        pkt = packet.Packet(data=msg.data)
        pkt_ethernet = pkt.get_protocol(ethernet.ethernet)
        pkt_ipv4 = pkt.get_protocol(ipv4.ipv4)
        pkt_icmp = pkt.get_protocol(icmp.icmp)
        in_port = msg.match['in_port']
         
        # ignore icmp of other than icmp_echo_request
        if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST:
            return
        # make packet object to return
        this_subnet=self.subnet[datapath.id][subname]
        pkt = packet.Packet()
        pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
            dst=pkt_ethernet.src,
            src=this_subnet['mac']))
#             if vid != None:
#             pkt.add_protocol(vlan.vlan(vid=vid, ethertype = 0x0800))
        pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src,
            src=this_subnet['ip'],
            proto=pkt_ipv4.proto))
        pkt.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
            code=icmp.ICMP_ECHO_REPLY_CODE,
            csum=0,
            data=pkt_icmp.data))
        self._send_packet(datapath, in_port, pkt)
        self.logger.info("icmp reply is sent: %s-%s via port=%s" % (pkt_ethernet.src, pkt_ipv4.src, in_port) )      
开发者ID:ktmrmshk,项目名称:OpenFlowRyuSwitches,代码行数:29,代码来源:basic_router.py

示例3: test_default_args

    def test_default_args(self):
        ic = icmp.icmp()
        buf = ic.serialize(bytearray(), None)
        res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))

        eq_(res[0], 8)
        eq_(res[1], 0)
        eq_(buf[4:], b'\x00\x00\x00\x00')

        # with data
        ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
        buf = ic.serialize(bytearray(), None)
        res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))

        eq_(res[0], 3)
        eq_(res[1], 0)
        eq_(buf[4:], b'\x00\x00\x00\x00')
开发者ID:5g-empower,项目名称:empower-ryu,代码行数:17,代码来源:test_icmp.py

示例4: _handle_icmp

    def _handle_icmp(self, msg, pkt, icmp_pkt):
        """
            reply to ICMP_ECHO_REQUEST(i.e. ping);
            may handle other types of ICMP msg in the future;
            return True if send a response
        """
        LOG.debug('Handling ICMP packet %s', icmp_pkt)

        if icmp_pkt.type != icmp.ICMP_ECHO_REQUEST:
            return False

        in_port_no = msg.in_port
        switch = self.dpid_to_switch[msg.datapath.id]
        ipv4_layer = self.find_packet(pkt, 'ipv4')
        ip_src = netaddr.IPAddress(ipv4_layer.src)
        ip_dst = netaddr.IPAddress(ipv4_layer.dst)

        if ip_dst == netaddr.IPAddress(util.bgper_config['local_ipv4']):
            self.write_to_tap(pkt.data, modifyMacAddress=True)
            LOG.debug('Forward ICMP packet to tap port.')
            return True

        need_reply = False
        for _k, p in switch.ports.iteritems():
            if p.gateway and p.gateway.gw_ip == ip_dst:
                need_reply = True
                break
        if not need_reply:
            return False

        echo_id = icmp_pkt.data.id
        echo_seq = icmp_pkt.data.seq
        echo_data = bytearray(icmp_pkt.data.data)

        icmp_data = icmp.echo(id_=echo_id, seq=echo_seq, data=echo_data)

        #send a echo reply packet
        ether_layer = self.find_packet(pkt, 'ethernet')
        ether_dst = ether_layer.src
        ether_src = str(switch.ports[in_port_no].hw_addr)
        e = ethernet.ethernet(ether_dst, ether_src, ether.ETH_TYPE_IP)
        #csum calculation should be paid attention to
        i = ipv4.ipv4(version=4, header_length=5, tos=0, total_length=0,
            identification=0, flags=0x000, offset=0, ttl=64, proto=1, csum=0,
            src=str(ip_dst), dst=str(ip_src), option=None)
        ic = icmp.icmp(type_=0, code=0, csum=0, data=icmp_data)
        p = packet.Packet()
        p.add_protocol(e)
        p.add_protocol(i)
        p.add_protocol(ic)
        p.serialize()
        datapath = msg.datapath
        datapath.send_packet_out(in_port=ofproto_v1_0.OFPP_NONE,
                actions=[datapath.ofproto_parser.OFPActionOutput(in_port_no)],
                data=p.data)
        LOG.debug('Ping replied %s -> %s', ip_dst, ip_src)
        return True
开发者ID:cannium,项目名称:openflow_routing_framework,代码行数:57,代码来源:routing.py

示例5: _handle_icmp

 def _handle_icmp(self, datapath, port, pkt_ethernet, pkt_ipv4, pkt_icmp):
     if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST:
         return
     pkt = packet.Packet()
     pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype, dst=pkt_ethernet.src, src=self.hw_addr))
     pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src, src=self.ip_addr, proto=pkt_ipv4.proto))
     pkt.add_protocol(
         icmp.icmp(type_=icmp.ICMP_ECHO_REPLY, code=icmp.ICMP_ECHO_REPLY_CODE, csum=0, data=pkt_icmp.data)
     )
     self._send_packet(datapath, port, pkt)
开发者ID:shinpeimuraoka,项目名称:ryu-book,代码行数:10,代码来源:ping_responder.py

示例6: setUp

    def setUp(self):
        self.type_ = icmp.ICMP_ECHO_REQUEST
        self.code = 0
        self.csum = 0
        self.data = None

        self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)

        self.buf = bytearray(struct.pack(icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
        self.csum_calc = packet_utils.checksum(self.buf)
        struct.pack_into("!H", self.buf, 2, self.csum_calc)
开发者ID:John-Lin,项目名称:ryu,代码行数:11,代码来源:test_icmp.py

示例7: setUp_with_TimeExceeded

    def setUp_with_TimeExceeded(self):
        self.te_data = b"abc"
        self.te_data_len = len(self.te_data)
        self.data = icmp.TimeExceeded(data_len=self.te_data_len, data=self.te_data)

        self.type_ = icmp.ICMP_TIME_EXCEEDED
        self.code = 0
        self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)

        self.buf = bytearray(struct.pack(icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
        self.buf += self.data.serialize()
        self.csum_calc = packet_utils.checksum(self.buf)
        struct.pack_into("!H", self.buf, 2, self.csum_calc)
开发者ID:John-Lin,项目名称:ryu,代码行数:13,代码来源:test_icmp.py

示例8: send_ping

    def send_ping(self, ip_dst):
        pkt = packet.Packet()
        if ip_dst in self.arp_table:
            mac_dst = self.arp_table[ip_dst]
        else:
            return
        pkt.add_protocol(ethernet.ethernet(ethertype=0x800,dst=mac_dst,\
                                                           src=self.hw_addr))

        pkt.add_protocol(ipv4.ipv4(dst= ip_dst, src=self.ip_addr,proto=1))
        pkt.add_protocol(icmp.icmp(type_= 8, code=0, csum=0))#Not sure about echo
        print("Ping packet sent")
        self._flood_packet(pkt)
开发者ID:npsccw,项目名称:SDN-Applications,代码行数:13,代码来源:ControlNode.py

示例9: _handle_icmp

    def _handle_icmp(self, msg, pkt, icmp_pkt):
        '''
            reply to ICMP_ECHO_REQUEST(i.e. ping);
            may handle other types of ICMP msg in the future;
            return True if send a responce
        '''
        #print 'icmp', icmp_pkt
        if icmp_pkt.type != icmp.ICMP_ECHO_REQUEST:
            return False

        in_port_no = msg.in_port
        switch = self.dpid_to_switch[msg.datapath.id]
        ipv4_layer = self.find_packet(pkt, 'ipv4')
        ip_src = ipv4_layer.src
        ip_dst = ipv4_layer.dst

        need_reply = False
        for _k, p in switch.ports.iteritems():
            if p.gateway and p.gateway.gw_ip == ip_dst:
                need_reply = True
                break
        if not need_reply:
            return False

        echo_id = icmp_pkt.data.id
        echo_seq = icmp_pkt.data.seq
        echo_data = bytearray(icmp_pkt.data.data)

        icmp_data = icmp.echo(id_=echo_id,seq=echo_seq,data=echo_data)

        #send a echo reply packet
        ether_layer = self.find_packet(pkt, 'ethernet')
        ether_dst = ether_layer.src
        ether_src = switch.ports[in_port_no].hw_addr
        e = ethernet.ethernet(ether_dst,ether_src,ether.ETH_TYPE_IP)
        #csum calculation should be paied attention
        i = ipv4.ipv4(version=4,header_length=5,tos=0,total_length=0,
            identification=0,flags=0x000,offset=0,ttl=64,proto=1,csum=0,
            src=ip_dst,dst=ip_src,option=None)
        ic = icmp.icmp(type_= 0,code=0,csum=0,data=icmp_data)
        p = packet.Packet()
        p.add_protocol(e)
        p.add_protocol(i)
        p.add_protocol(ic)
        p.serialize()
        datapath = msg.datapath
        datapath.send_packet_out(in_port=ofproto_v1_0.OFPP_NONE,
                actions=[datapath.ofproto_parser.OFPActionOutput(in_port_no)],
                data=p.data)
        print 'send a ping replay'
        return True
开发者ID:carriercomm,项目名称:openflow_routing,代码行数:51,代码来源:routing.py

示例10: _build_pkt

    def _build_pkt(self, fields, ops):
        pkt_out = packet.Packet()
        pkt_ipv4 = pkt_out.get_protocol(ipv4.ipv4)
        pkt_icmp = pkt_out.get_protocol(icmp.icmp)

        def addIPv4(pkt_out, fields):
            pkt_out.add_protocol(ipv4.ipv4(dst=fields['dstip'],
                                 src=fields['srcip'],
                                 proto=fields['proto']))
            return pkt_out

        pkt_out.add_protocol(ethernet.ethernet(ethertype=fields['ethtype'],
                                               dst=fields['dstmac'],
                                               src=fields['srcmac']))
        # Add if ARP                                           
        if 'arp' in fields['ptype']:
            pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                                 src_mac=fields['srcmac'],
                                 src_ip=fields['srcip'],
                                 dst_mac=fields['dstmac'],
                                 dst_ip=fields['dstip']))
        # Add if IPv4
        if 'ipv4' in fields['ptype']:
            pkt_out = addIPv4(pkt_out,fields)
            
        # Add if ICMP
        if 'icmp' in fields['ptype']:
            pkt_out = addIPv4(pkt_out,fields)
            
            pkt_out.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
                                 code=icmp.ICMP_ECHO_REPLY_CODE,
                                 csum=0,
                                 data=None))
        # Add if UDP    
        if 'udp' in fields['ptype']:
            pkt_out = addIPv4(pkt_out,fields)
            pkt_out.add_protocol(udp.udp(dst_port=fields['dstport'],
				bits=fields['bits'],option=fields['opt'],
                                src_port=fields['srcport']))
        # Add if TCP                         	 
        if 'tcp' in fields['ptype']:
            pkt_out = addIPv4(pkt_out,fields)
            pkt_out.add_protocol(tcp.tcp(dst_port=fields['dstport'],
				bits=fields['bits'],option=fields['opt'],
                                src_port=fields['srcport']))
        #Add covert channel information                    
        if fields['com'] != None:
            pkt_out.add_protocol(fields['com'])
            
        #Send crafted packet            
        self._send_packet(fields['dp'], ops['newport'], pkt_out)
开发者ID:Ryuretic,项目名称:Ryuretic,代码行数:51,代码来源:Ryuretic.py

示例11: _handle_icmp

    def _handle_icmp(self, datapath, port, pkt_ethernet, pkt_ipv4, pkt_icmp):
        if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST:
            return
        if pkt_ipv4.dst in self.arp_table1:
           # index = self.ip_addr.index(pkt_ipv4.dst)

            pkt = packet.Packet()
            pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
                                           dst=pkt_ethernet.src, src=self.arp_table1[pkt_ipv4.dst]))
            pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src, src=pkt_ipv4.dst,
                                       proto=pkt_ipv4.proto))
            pkt.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
                                       code=icmp.ICMP_ECHO_CODE, csum=0, datapath=pkt_icmp.data))
            self._send_packet(datapath, port, pkt)
开发者ID:hyqdvd,项目名称:ryuCode,代码行数:14,代码来源:arp_dc1.py

示例12: _build_echo

    def _build_echo(self, _type, echo):
        e = self._build_ether(ether.ETH_TYPE_IP)
        ip = ipv4.ipv4(version=4, header_length=5, tos=0, total_length=84,
                       identification=0, flags=0, offset=0, ttl=64,
                       proto=inet.IPPROTO_ICMP, csum=0,
                       src=self.RYU_IP, dst=self.HOST_IP)
        ping = icmp.icmp(_type, code=0, csum=0, data=echo)

        p = packet.Packet()
        p.add_protocol(e)
        p.add_protocol(ip)
        p.add_protocol(ping)
        p.serialize()
        return p
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:14,代码来源:test_arp.py

示例13: setUp_with_dest_unreach

    def setUp_with_dest_unreach(self):
        self.unreach_mtu = 10
        self.unreach_data = b"abc"
        self.unreach_data_len = len(self.unreach_data)
        self.data = icmp.dest_unreach(data_len=self.unreach_data_len, mtu=self.unreach_mtu, data=self.unreach_data)

        self.type_ = icmp.ICMP_DEST_UNREACH
        self.code = icmp.ICMP_HOST_UNREACH_CODE
        self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)

        self.buf = bytearray(struct.pack(icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
        self.buf += self.data.serialize()
        self.csum_calc = packet_utils.checksum(self.buf)
        struct.pack_into("!H", self.buf, 2, self.csum_calc)
开发者ID:John-Lin,项目名称:ryu,代码行数:14,代码来源:test_icmp.py

示例14: createPacketIpv4

 def createPacketIpv4(self, datapath, port, pkt_ethernet, pkt_ipv, pkt_icmp):
     # create send packet
     sendpkt = packet.Packet()
     sendpkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
                                       dst=pkt_ethernet.dst,
                                        src=pkt_ethernet.src))
     sendpkt.add_protocol(ipv4.ipv4(dst=pkt_ipv.src,
                                src=pkt_ethernet.src,
                                proto=pkt_ipv.proto))
     sendpkt.add_protocol(icmp.icmp(type_=icmp.ICMP_ECHO_REPLY,
                                code=icmp.ICMP_ECHO_REPLY_CODE,
                                csum=0,
                                data=pkt_icmp.data))
     sendpkt.serialize()
     return sendpkt
开发者ID:takeuchi17401,项目名称:performance_test,代码行数:15,代码来源:send_persec_ipv4.py

示例15: send_ping

    def send_ping(self, datapath, src_mac, dst_mac, src_ip, dst_ip, outport=1, seq=0):
        ttl = 64

        e = ethernet.ethernet(dst_mac, src_mac, ether.ETH_TYPE_IP)
        iph = ipv4.ipv4(4, 5, 0, 0, 0, 2, 0, ttl, 1, 0, src_ip, dst_ip)
        echo = icmp.echo(1, seq, data=None)
        icmph = icmp.icmp(8, 0, 0, echo)
        
        pkt = packet.Packet()
        pkt.add_protocol(e)
        pkt.add_protocol(iph)
        pkt.add_protocol(icmph)
        
        self._send_packet(datapath, outport, pkt)
        self.logger.info("icmp echo req is sent: to %s" % (dst_ip,) )  
开发者ID:ktmrmshk,项目名称:OpenFlowRyuSwitches,代码行数:15,代码来源:basic_router.py


注:本文中的ryu.lib.packet.icmp.icmp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。