summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/helper-scripts/demo-scripts/tx_rate.py
blob: 112b583af7dc30f16d03f1760c11060a244e6a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/env python2.7

##
## Copyright (c) 2010-2017 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##

from prox import *
from decimal import *
from time import *

class data_point:
    value = 0;
    tsc = 0;
    def __init__(self, value, tsc):
        self.value = value;
        self.tsc = tsc;

def measure_tx(prox_instance, port_id):
    port_tx_pkt = "port(" + str(port_id) + ").tx.packets"
    port_tsc = "port(" + str(port_id) + ").tsc";
    cmd = "stats " + port_tx_pkt + "," + port_tsc;
    reply = prox_instance.send(cmd).recv().split(",");

    return data_point(int(reply[0]), int(reply[1]));

def get_rate(first, second, hz):
    tsc_diff = second.tsc - first.tsc;
    value_diff = second.value - first.value;

    return int(Decimal(value_diff * hz) / tsc_diff)

# make sure that prox has been started with the -t parameter
prox_instance = prox("127.0.0.1")
print "Connected to prox"

hz = int(prox_instance.send("stats hz").recv());

print "System is running at " + str(hz) + " Hz"

print "Showing TX pps on port 0"

update_interval = 0.1

print "Requesting new data every " + str(update_interval) + "s"

measure = measure_tx(prox_instance, 0);
while (True):
    sleep(update_interval)
    measure2 = measure_tx(prox_instance, 0);

    # since PROX takes measurements at a configured rate (through
    # update interval command or throw -r command line parameter), it
    # might be possible that two consecutive measurements report the
    # same. To get updates at a frequency higher than 1 Hz,
    # reconfigure prox as mentioned above.

    if (measure.tsc == measure2.tsc):
        continue;

    print get_rate(measure, measure2, hz);

    measure = measure2;
_2, .driver_data = (unsigned long)&zorro7xx_driver_data[2], }, { .id = ZORRO_PROD_GVP_GFORCE_040_060, .driver_data = (unsigned long)&zorro7xx_driver_data[3], }, { 0 } }; MODULE_DEVICE_TABLE(zorro, zorro7xx_zorro_tbl); static int zorro7xx_init_one(struct zorro_dev *z, const struct zorro_device_id *ent) { struct Scsi_Host *host; struct NCR_700_Host_Parameters *hostdata; struct zorro_driver_data *zdd; unsigned long board, ioaddr; board = zorro_resource_start(z); zdd = (struct zorro_driver_data *)ent->driver_data; if (zdd->absolute) { ioaddr = zdd->offset; } else { ioaddr = board + zdd->offset; } if (!zorro_request_device(z, zdd->name)) { printk(KERN_ERR "zorro7xx: cannot reserve region 0x%lx, abort\n", board); return -EBUSY; } hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); if (!hostdata) { printk(KERN_ERR "zorro7xx: Failed to allocate host data\n"); goto out_release; } /* Fill in the required pieces of hostdata */ if (ioaddr > 0x01000000) hostdata->base = ioremap(ioaddr, zorro_resource_len(z)); else hostdata->base = ZTWO_VADDR(ioaddr); hostdata->clock = 50; hostdata->chip710 = 1; /* Settings for at least WarpEngine 40xx */ hostdata->ctest7_extra = CTEST7_TT1; zorro7xx_scsi_driver_template.name = zdd->name; /* and register the chip */ host = NCR_700_detect(&zorro7xx_scsi_driver_template, hostdata, &z->dev); if (!host) { printk(KERN_ERR "zorro7xx: No host detected; " "board configuration problem?\n"); goto out_free; } host->this_id = 7; host->base = ioaddr; host->irq = IRQ_AMIGA_PORTS; if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "zorro7xx-scsi", host)) { printk(KERN_ERR "zorro7xx: request_irq failed\n"); goto out_put_host; } zorro_set_drvdata(z, host); scsi_scan_host(host); return 0; out_put_host: scsi_host_put(host); out_free: if (ioaddr > 0x01000000) iounmap(hostdata->base); kfree(hostdata); out_release: zorro_release_device(z); return -ENODEV; } static void zorro7xx_remove_one(struct zorro_dev *z) { struct Scsi_Host *host = zorro_get_drvdata(z); struct NCR_700_Host_Parameters *hostdata = shost_priv(host); scsi_remove_host(host); NCR_700_release(host); kfree(hostdata); free_irq(host->irq, host); zorro_release_device(z); } static struct zorro_driver zorro7xx_driver = { .name = "zorro7xx-scsi", .id_table = zorro7xx_zorro_tbl, .probe = zorro7xx_init_one, .remove = zorro7xx_remove_one, }; static int __init zorro7xx_scsi_init(void) { return zorro_register_driver(&zorro7xx_driver); } static void __exit zorro7xx_scsi_exit(void) { zorro_unregister_driver(&zorro7xx_driver); } module_init(zorro7xx_scsi_init); module_exit(zorro7xx_scsi_exit);