Exemplo n.º 1
0
def getPeriodicStats(dp):
    """show periodic stats on screen

    :param dp: the datapath from which the stats shall be shown for network debugging and Malicious attacks """
    waiters = {}
    while True:
        get_flow_stats(dp, waiters)
        get_port_stats(dp, waiters)
        time.sleep(1)
Exemplo n.º 2
0
def getPeriodicStats(dp):
    """show periodic stats on screen

    :param dp: the datapath from which the stats shall be shown
    """
    waiters = {}
    while True:
        get_flow_stats(dp, waiters)
        get_port_stats(dp, waiters)
        time.sleep(1)
Exemplo n.º 3
0
 def getPorts(self, dpid):
     dp = self.dpset.get(int(dpid))
     if dp is None:
         return None
     if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
         ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
         ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
         ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
     else:
         LOG.debug('Unsupported OF protocol')
         return None
     return ports
Exemplo n.º 4
0
 def getPorts(self, dpid):
     dp = self.dpset.get(int(dpid))
     if dp is None:
         return None
     if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
         ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
         ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
     elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
         ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
     else:
         LOG.debug('Unsupported OF protocol')
         return None
     return ports
Exemplo n.º 5
0
    def get_port_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(ports)
        return (Response(content_type='application/json', body=body))
    def get_port_stats(self, req, dpid, **_kwargs):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return Response(status=404)

        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

        body = json.dumps(ports)
        return (Response(content_type='application/json', body=body))
Exemplo n.º 7
0
    def port_stats_reply_handler_API(self, dpid):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
        else:
            LOG.debug("Unsupported OF protocol")
            return None

        print "----------------------portAPI----------------------"

        for key in ports:
            for port in ports[key]:
                portstatsReplyAPI = {
                    "controller": controllerName,
                    "port": str(port["port_no"]),
                    "rxbyte": str(port["rx_bytes"]),
                    "rxpacket": str(port["rx_packets"]),
                    "txbyte": str(port["tx_bytes"]),
                    "txpacket": str(port["tx_packets"]),
                }

                temp = "%016x" % int(key)
                temp = map(str, temp)
                for i in range(2, 23, 3):
                    temp.insert(i, ":")
                portstatsReplyAPI["dpid"] = "".join(temp)
                portstatsReplyAPI["capacity"] = (
                    self.port_to_feature[portstatsReplyAPI["dpid"]][portstatsReplyAPI["port"]]
                    if portstatsReplyAPI["port"] in self.port_to_feature[portstatsReplyAPI["dpid"]]
                    else "0"
                )

                print json.dumps(portstatsReplyAPI)
                tmpIP = "http://" + coreIP + ":" + corePort + "/publish/port"
                self.post_json_to_core(tmpIP, json.dumps(portstatsReplyAPI))
        return ports
Exemplo n.º 8
0
    def port_stats_reply_handler_API(self, dpid):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return None

        print '----------------------portAPI----------------------'

        for key in ports:
            for port in ports[key]:
                portstatsReplyAPI = {
                    'controller': controllerName,
                    'port': str(port['port_no']),
                    'rxbyte': str(port['rx_bytes']),
                    'rxpacket': str(port['rx_packets']),
                    'txbyte': str(port['tx_bytes']),
                    'txpacket': str(port['tx_packets'])
                }

                temp = "%016x" % int(key)
                temp = map(str, temp)
                for i in range(2, 23, 3):
                    temp.insert(i, ':')
                portstatsReplyAPI["dpid"] = ''.join(temp)
                portstatsReplyAPI["capacity"] = self.port_to_feature[
                    portstatsReplyAPI['dpid']][
                        portstatsReplyAPI['port']] if portstatsReplyAPI[
                            'port'] in self.port_to_feature[
                                portstatsReplyAPI['dpid']] else '0'

                print json.dumps(portstatsReplyAPI)
                tmpIP = coreURL + "/publish/port"
                self.post_json_to_core(tmpIP, json.dumps(portstatsReplyAPI))
        return ports
Exemplo n.º 9
0
    def port_stats_reply_handler_API(self, dpid):
        dp = self.dpset.get(int(dpid))
        if dp is None:
            return None
        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
            ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return None

        print '----------------------portAPI----------------------'

        for key in ports:
            for port in ports[key]:
                portstatsReplyAPI = {
                    'controller': controllerName,
                    'port': str(port['port_no']),
                    'rxbyte': str(port['rx_bytes']),
                    'rxpacket': str(port['rx_packets']),
                    'txbyte': str(port['tx_bytes']),
                    'txpacket': str(port['tx_packets'])
                }

                temp = "%016x" %int(key)
                temp = map(str, temp)
                for i in range(2, 23, 3):
                    temp.insert(i, ':')
                portstatsReplyAPI["dpid"] = ''.join(temp)
                portstatsReplyAPI["capacity"] = self.port_to_feature[portstatsReplyAPI['dpid']][portstatsReplyAPI['port']] if portstatsReplyAPI['port'] in self.port_to_feature[portstatsReplyAPI['dpid']] else '0'

                print json.dumps(portstatsReplyAPI)
                tmpIP = coreURL + "/publish/port"
                self.post_json_to_core(tmpIP, json.dumps(portstatsReplyAPI))
        return ports