コード例 #1
0
 def __init__(self, name, hasGps=True):
     self.name = name
     if _HAVE_GPSPUB is False:
         # Disable gps regardless of our init flag if
         # the gps module is not available
         hasGps = False
     self.hasGps = hasGps
     if self.hasGps:
         self.gpsKey = os.getcwd() + '/gpsKey'
         self.gpsHandle = gpsPub.GPSPublishInit(self.gpsKey)
         self.sender = mgen.Controller(name, self.gpsKey)
         self.gpsLat = None
         self.gpsLon = None
         self.gpsAlt = None
     else:
         self.sender = mgen.Controller(name)
コード例 #2
0
    def __init__(self, bind_address, bind_port, mult_address, multi_port):
        self.logger = logging.getLogger('ZMQServer')
        self.logger.debug('__init__')

        self.bind_address = bind_address
        self.bind_port = bind_port

        self.multicast_address = mult_address
        self.multicast_port = multi_port

        self.mgen_sender = mgen.Controller("sender")
コード例 #3
0
    def __init__(self,
                 bind_address,
                 bind_port,
                 dest_address="localhost",
                 dest_port=5354):
        self.logger = logging.getLogger('MGEN')
        self.logger.debug('__init__')

        self.bind_address = bind_address
        self.bind_port = bind_port
        self.dest_address = str(dest_address)
        self.dest_port = int(dest_port)

        self.mgen_sender = mgen.Controller("sender" + str(bind_port))
        self.mgen_sender.send_command("ipv4")
コード例 #4
0
ファイル: mgen_fifo1.py プロジェクト: lihebi/heavy-ball
def mgen_flow(starttime, nodeid, numnodes):
    """generate mgen control flow.

    """
    sender = mgen.Controller()
    sender.send_command("output tmp/mgen.{}.out".format(nodeid))
    sender.send_command("start " + starttime)
    sender.send_command("txlog")

    rates = get_init_rate(nodeid, numnodes)
    print "sending initial rate .."
    send_init_rate(sender, rates)

    global g_q
    # A separate thread for consuming the queue and sending to plot
    t = threading.Thread(target=queue_worker)
    t.daemon = True
    t.start()

    init_t = -1
    print 'entering emane read loop ..'
    while True:
        data = read_emane_fifo()
        if init_t is -1:
            # The first read from emane, the mgen start
            init_t = time.time()
        print datetime.datetime.now(), "Reader: ", data
        newrates, rate, ql = process_data(data, rates)
        if not newrates == rates:
            rates = newrates
            # send new rates if changing
            send_mod_rate(sender, newrates)
        # I actually should spin a thread rather than not blocking
        # here. Otherwise, emane might very well stopped because
        # nobody is reading the pipe. Also, the time here would be
        # inaccurate.
        #
        # send_to_plot(time.time() - init_t, rate, ql)
        g_q.put((time.time() - init_t, rate, ql))
        # TODO magic number 10 seconds to run
        if time.time() - init_t > 10:
            # send closing message
            print 'Sending closing message 0:0:0 and returning ..'
            g_q.put((0,0,0))
            return
        print 'Length of data queue:', g_q.qsize()
コード例 #5
0
    def __init__(self, target_method, bind_address="localhost", bind_port=5354,
                 multicast_address="224.1.2.3", multicast_port=5459):
        self.is_running = False
        self.target_method = target_method
        self.logger = logging.getLogger('MGENServer')
        self.logger.debug('__init__')

        self.bind_address = bind_address

        self.bind_port = bind_port
        self.mymgen=mgen.Controller()
        self.mymgen.send_command("ipv4")

        join_command="join " + str(multicast_address) + " port " + str(multicast_port) + " interface " + bind_address
        self.mymgen.send_event(join_command)
        listen_command = "listen udp " + str(multicast_port) + " interface " + multicast_address
        self.mymgen.send_event(listen_command)
コード例 #6
0
    def __init__(self,
                 target_method,
                 bind_address="localhost",
                 bind_port=5354):
        self.is_running = False
        self.target_method = target_method
        self.logger = logging.getLogger('MGENServer')
        self.logger.debug('__init__')

        self.bind_address = bind_address
        self.bind_port = bind_port
        self.mymgen = mgen.Controller()
        self.mymgen.send_command("ipv4")

        # listen_command = "listen udp " + str(bind_address) + " interface " + str(bind_port) + " LOG /tmp/mgen.drc"
        listen_command = "listen udp " + str(
            bind_port) + " output /tmp/mgen.drc"
        print "Receiving usign event " + listen_command
        self.mymgen.send_event(listen_command)
コード例 #7
0
import mgen
import datetime

sender = mgen.Controller("sender")

sender.send_event(
    "0.0 ON 1 UDP SRC 5000 DST 192.168.0.2/5000 PERIODIC [100 1024] TOS 0x1e")
sender.send_event(
    "0.0 ON 2 UDP SRC 5001 DST 192.168.0.2/5000 PERIODIC [100 1024] TOS 0x16")
sender.send_event(
    "0.0 ON 3 UDP SRC 5002 DST 192.168.0.2/5000 PERIODIC [100 1024] TOS 0x0e")
sender.send_event(
    "0.0 ON 4 UDP SRC 5003 DST 192.168.0.2/5000 PERIODIC [100 1024] TOS 0x04")
sender.send_event(
    "0.0 ON 5 UDP SRC 5004 DST 192.168.0.2/5000 PERIODIC [100 1024] TOS 0x00")
sender.send_event("1.0 OFF 5")
sender.send_event("1.0 OFF 1")
sender.send_event("1.0 OFF 2")
sender.send_event("1.0 OFF 3")
sender.send_event("1.0 OFF 4")

#
# flow1 = mgen.Flow(1, sender)
# flow1.set_protocol('UDP')
# flow1.set_source('5000')
# flow1.set_destination('192.168.0.2', 5000)
# flow1.set_pattern('PERIODIC [100 1024]')
# flow1.set_tos('0x1e')
# flow1.set_count('100')
# # now1 = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
# # payload1 = mgen.get_payload_from_string(now1)
コード例 #8
0
numnodes = int(sys.argv[3])

PKT_SIZE = 512
INIT_FLOW = 5

# i = 1
A_MAX = 100.0
EPSILON = 0.50
K_PARA = 200.0

curr_rates = {}
for i in range(1, numnodes + 1):
    if i != nodeid:
        curr_rates[i] = INIT_FLOW

sender = mgen.Controller()
sender.send_command("output persist/{}/var/log/mgen.out".format(nodeid))
sender.send_command("start " + starttime)
sender.send_command("txlog")
print "start mgen"

# "Manually"  start a flow from this sender
# sender.send_event("on 1 udp dst 127.0.0.1/5000 per [1 1024]")

for ind, rate in curr_rates.iteritems():
    onevent = "1.0 ON {} UDP SRC 5001 DST 10.100.0.{}/5001 PERIODIC [{} {}] INTERFACE bmf0".format(
        ind, ind, rate, PKT_SIZE)
    print onevent
    sender.send_event(onevent)

print(datetime.datetime.now())
コード例 #9
0
import mgen

receiver = mgen.Controller("receiver")

receiver.send_event("listen udp 5000")

updateCount = 1
for line in receiver:
    event = mgen.Event(line)
    # print the line received
    print line,
    # print payload content, if applicable
    if event.data:
        print "   (payload content is \"%s\")" % event.data
import mgen
import time

# Create an MgenController instance
# (an underlying "mgen" process is instantiated)
receiver = mgen.Controller()

# Send a global command
receiver.send_command("ipv4")

# Send a script event to enact immediately (mgen udp receiver)
receiver.send_event("listen udp 5000")

receiver.send_event("txlog")

# Create a second Mgen (will act as sender to above mgen udp receiver)
sender = mgen.Controller("sender")


# Set first byte to high values to indicate mgen payload
# direct receiver to listen to port 5010
payload = mgen.GetPayloadFromString("FFLISTEN UDP 5010")
if payload is not None:
    sender.send_event("ON 11 udp dst 127.0.0.1/5000 periodic [1 2048] data [%s] count 1" %payload)

# Set first byte to high values to indicate mgen payload
# direct receiver to start an udp flow
payload = mgen.GetPayloadFromString("FFON 21 udp dst 127.0.0.1/5010 periodic [1 512]")
if payload is not None:
    sender.send_event("ON 12 udp dst 127.0.0.1/5000 periodic [1 4096] data [%s] count 1" %payload)
コード例 #11
0
                addr = tmp[1]
                weight = int(tmp[2])
            elif len(tmp) > 1:
                weight = int(tmp[1])
            else:
                weight = 1
            if weight > 0:
                print "adding respondent name:%s addr:%s weight:%d" % (
                    name, addr, weight)
                responder.add_respondent(name, addr, weight)
    else:
        print "mgenResponder error: invalid command: \"%s\"" % cmd
        sys.exit(-1)
    i += 1

controller = mgen.Controller()

controller.send_command("ipv4")
controller.send_event("listen udp " + str(port))
if groupAddress is not None:
    controller.send_event("join " + groupAddress)

flow = mgen.Flow(1, controller)
flow.set_protocol('udp')
if groupAddress is not None:
    flow.set_destination(groupAddress, port)
flow.set_pattern('periodic [1 %d]' % msgSize)
flow.set_count(1)
flow.set_sequence(1)

if msgRate > 0.0: