Beispiel #1
0
def publish_pathloss(session, src_nem, dest_nem, pathloss, verbose=False):
    ce = PathlossEvent()

    ce.append(dest_nem, forward=pathloss)
    if verbose:
        print 'Publishing to nem %d with event nem %d, ce=%s' % (
            src_nem, dest_nem, str(ce))

    session.emane.service.publish(src_nem, ce)
Beispiel #2
0
def update_8_9_13_14_15_16_pathloss(service):
    event = PathlossEvent()
    radios = (8, 9, 13, 14, 15, 16)
    pl = 9999  # just high number
    for radio in radios:
        event.append(radio, forward=pl)
        nextradio = radios.index(radio)+1
        for nextradio in radios:
            if radio != nextradio:
                service.publish(nextradio, event)
                print ("Pathloss " + str(radio) + " -> " + str(nextradio) + " : " + str(pl))
Beispiel #3
0
def update_radio_pathlosses(service):
    max_id = max([i.id for i in radioNEMs])
    matrix = np.zeros((max_id + 1, max_id + 1))
    for nemtx in radioNEMs:
        event = PathlossEvent()
        for nemrx in radioNEMs:
            if (nemrx.id != nemtx.id):
                pl = signalserver_pathloss(nemtx, nemrx)
                matrix[nemtx.id][nemrx.id] = pl
                event.append(nemrx.id, forward=pl)
        service.publish(nemtx.id, event)

    # fmatrix = np.zeros((max_id + 1, max_id + 1))
    # ematrix = np.zeros((max_id + 1, max_id + 1))
    # ssmatrix = np.zeros((max_id + 1, max_id + 1))
    # for nemtx in radioNEMs:
    #     for nemrx in radioNEMs:
    #         if (nemrx.id != nemtx.id):
    #             pl = freespace_pathloss(nemtx,nemrx)
    #             fmatrix[nemtx.id][nemrx.id] = pl
    # for nemtx in radioNEMs:
    #     for nemrx in radioNEMs:
    #         if (nemrx.id != nemtx.id):
    #             pl = egli_pathloss(nemtx,nemrx)
    #             ematrix[nemtx.id][nemrx.id] = pl
    # for nemtx in radioNEMs:
    #     for nemrx in radioNEMs:
    #         if (nemrx.id != nemtx.id):
    #             pl = signalserver_pathloss(nemtx,nemrx)
    #             ssmatrix[nemtx.id][nemrx.id] = pl
    # print "freespace:"
    # print np.array_str(fmatrix,max_line_width=200,precision=5)
    # print "egli:"
    # print np.array_str(ematrix,max_line_width=200, precision=5)
    # print "signalserver:"
    # print np.array_str(ssmatrix,max_line_width=200, precision=5)

    print "actual:"
    print np.array_str(matrix, max_line_width=200, precision=5)

    for nem in radioNEMs:
        print nem.id, nem.latitude, nem.longitude
    map_tools.draw_elevation(
        [32.7, 33.1], [34.9, 35.2],
        ([x.longitude for x in radioNEMs], [x.latitude for x in radioNEMs
                                            ], [str(x.id) for x in radioNEMs]))
Beispiel #4
0
def update_a2g_pathlosses(service):
    p = default_p_a2g
    radiosNEM = (a2gNEM8, a2gNEM9, a2gNEM13, a2gNEM14, a2gNEM15, a2gNEM16)
    radios = (8, 9, 13, 14, 15, 16)
    for radio in radiosNEM:
        pl = signalserver_pathloss(a2gNEM7, radio, p)
        event = PathlossEvent()
        event.append(radios[radiosNEM.index(radio)], forward=pl)
        service.publish(7, event)
        event = PathlossEvent()
        event.append(7, forward=pl)
        service.publish(radios[radiosNEM.index(radio)], event)
Beispiel #5
0
def update_radio_pathlosses(service):
    p = default_p_radio
    max_id = max([i.id for i in radioNEMs])
    matrix = np.zeros((max_id+1, max_id+1))
    for nemtx in radioNEMs:
        event = PathlossEvent()
        for nemrx in radioNEMs:
            if (nemrx.id != nemtx.id):
                pl = signalserver_pathloss(nemtx,nemrx,p)
                matrix[nemtx.id][nemrx.id] = pl
                event.append(nemrx.id, forward=pl)
        service.publish(nemtx.id, event)

    print "actual:"
    print np.array_str(matrix,max_line_width=200, precision=5)

    for nem in radioNEMs:
        print nem.id, nem.latitude, nem.longitude
    
    map_tools.draw_elevation([32.7, 33.1], [34.9, 35.2], ([x.longitude for x in radioNEMs],[x.latitude for x in radioNEMs], [str(x.id) for x in radioNEMs]))
Beispiel #6
0
    def setpathloss(self, numnodes):
        """ Send EMANE pathloss events to connect all NEMs in a chain.
        """
        if self.session.emane.version < self.session.emane.EMANE091:
            service = emaneeventservice.EventService()
            e = emaneeventpathloss.EventPathloss(1)
            old = True
        else:
            if self.session.emane.version == self.session.emane.EMANE091:
                dev = "lo"
            else:
                dev = self.session.obj("ctrlnet").brname
            service = EventService(eventchannel=("224.1.2.8", 45703, dev),
                                   otachannel=None)
            old = False

        for i in xrange(1, numnodes + 1):
            rxnem = i
            # inform rxnem that it can hear node to the left with 10dB noise
            txnem = rxnem - 1
            if txnem > 0:
                if old:
                    e.set(0, txnem, 10.0, 10.0)
                    service.publish(emaneeventpathloss.EVENT_ID,
                                    emaneeventservice.PLATFORMID_ANY, rxnem,
                                    emaneeventservice.COMPONENTID_ANY, e.export())
                else:
                    e = PathlossEvent()
                    e.append(txnem, forward=10.0, reverse=10.0)
                    service.publish(rxnem, e)
            # inform rxnem that it can hear node to the right with 10dB noise
            txnem = rxnem + 1
            if txnem > numnodes:
                continue
            if old:
                e.set(0, txnem, 10.0, 10.0)
                service.publish(emaneeventpathloss.EVENT_ID,
                                emaneeventservice.PLATFORMID_ANY, rxnem,
                                emaneeventservice.COMPONENTID_ANY, e.export())
            else:
                e = PathlossEvent()
                e.append(txnem, forward=10.0, reverse=10.0)
                service.publish(rxnem, e)
Beispiel #7
0
def update_89_pathloss(service):
    event = PathlossEvent()
    p = default_p_a2g
    pl89 = signalserver_pathloss(a2gNEM8, a2gNEM9, p)
    event.append(9, forward=pl89)
    service.publish(8, event)

    pl98 = signalserver_pathloss(a2gNEM9, a2gNEM8, p)
    event.append(8, forward=pl98)
    service.publish(9, event)
    print "Pathloss 8->9", pl89
    print "Pathloss 9->8", pl98
Beispiel #8
0
    def setpathloss(self, numnodes):
        """ Send EMANE pathloss events to connect all NEMs in a chain.
        """
        if self.session.emane.version < self.session.emane.EMANE091:
            service = emaneeventservice.EventService()
            e = emaneeventpathloss.EventPathloss(1)
            old = True
        else:
            if self.session.emane.version == self.session.emane.EMANE091:
                dev = "lo"
            else:
                dev = self.session.obj("ctrlnet").brname
            service = EventService(eventchannel=("224.1.2.8", 45703, dev),
                                   otachannel=None)
            old = False

        for i in range(1, numnodes + 1):
            rxnem = i
            # inform rxnem that it can hear node to the left with 10dB noise
            txnem = rxnem - 1
            if txnem > 0:
                if old:
                    e.set(0, txnem, 10.0, 10.0)
                    service.publish(emaneeventpathloss.EVENT_ID,
                                    emaneeventservice.PLATFORMID_ANY, rxnem,
                                    emaneeventservice.COMPONENTID_ANY,
                                    e.export())
                else:
                    e = PathlossEvent()
                    e.append(txnem, forward=10.0, reverse=10.0)
                    service.publish(rxnem, e)
            # inform rxnem that it can hear node to the right with 10dB noise
            txnem = rxnem + 1
            if txnem > numnodes:
                continue
            if old:
                e.set(0, txnem, 10.0, 10.0)
                service.publish(emaneeventpathloss.EVENT_ID,
                                emaneeventservice.PLATFORMID_ANY, rxnem,
                                emaneeventservice.COMPONENTID_ANY, e.export())
            else:
                e = PathlossEvent()
                e.append(txnem, forward=10.0, reverse=10.0)
                service.publish(rxnem, e)
Beispiel #9
0
#!/usr/bin/env python
from emanesh.events import EventService
from emanesh.events import PathlossEvent
#
# create the event service
service = EventService(('224.1.2.8', 45703, 'emanenode0'))
#
# create an event setting the pathloss between 1 & 10
event = PathlossEvent()
event.append(9, forward=900)
event.append(7, forward=900)
#
# publish the event
service.publish(9, event)
service.publish(7, event)
#
# create an event setting the pathloss between 9 & 10
event = PathlossEvent()
event.append(9, forward=90)
event.append(10, forward=90)
#
# publish the event
service.publish(9, event)
service.publish(10, event)
Beispiel #10
0
 def handlePathloss(nemId,eventId,data,uuid,sequence):
     e = PathlossEvent()
     e.restore(data)
     header(nemId,eventId,data,'Pathloss',uuid,sequence)
     for i in e:
         print "  ",i
Beispiel #11
0
def update_a2g_pathlosses(service):
    p = default_p_a2g
    pl78 = freespace_pathloss_a2g(a2gNEM7, a2gNEM8, p)
    pl79 = freespace_pathloss_a2g(a2gNEM7, a2gNEM9, p)
    print pl78, pl79

    event = PathlossEvent()
    event.append(8, forward=pl78)
    event.append(9, forward=pl79)
    service.publish(7, event)

    event = PathlossEvent()
    event.append(7, forward=pl78)
    service.publish(8, event)

    event = PathlossEvent()
    event.append(7, forward=pl78)
    service.publish(9, event)
Beispiel #12
0
def main():

    global conf_file
    global node_conf_file
    global ENABLE_TIMEKEEPER
    global max_tdf
    global topo_size

    os.system("sudo chmod -R 777 /tmp")
    os.system("sudo rm -rf /tmp/emane")

    if is_root() == 0:
        print "Must be run as root"
        sys.exit(-1)

    arg_list = sys.argv

    if len(arg_list) == 1:
        conf_file = cwd + "/conf/emane.conf"
        node_conf_file = cwd + "/conf/node.conf"
    else:
        i = 1
        while i < len(arg_list):
            if arg_list[i] == "-D":
                ENABLE_TIMEKEEPER = 0
            else:
                ENABLE_TIMEKEEPER = 1
                conf_files_dir = arg_list[1]
                if os.path.isdir(conf_files_dir) == True:
                    conf_file = conf_files_dir + "/emane.conf"
                    node_conf_file = conf_files_dir + "/node.conf"
                    if os.path.exists(conf_file) == False or os.path.exists(
                            node_conf_file) == False:
                        print "Config files do not exist"
                        sys.exit(-1)
                else:
                    print "Config directory specified is incorrect"
                    sys.exit(-1)
            i = i + 1

    Node, run_time, n_nodes, eventmanagergroup, timeslice = configure()
    topo_size = n_nodes

    # create experiment-data directory
    with open(cwd + "/experiment-data/exp-info.txt", "w") as f:
        f.write("Conf file path : " + conf_file + "\n")
        f.write("Node Conf file : " + node_conf_file + "\n")
        f.write("Run time       : " + str(run_time) + "\n")
        f.write("N_nodes        : " + str(n_nodes) + "\n")

    # copy node_config file and emane_conf file

    os.system("mkdir -p " + cwd + "/experiment-data")
    start_LXCs()
    print "Timeslice = ", timeslice
    print "Setting initial location values to all lxcs ..."
    nemid = 1
    temp_list = eventmanagergroup.split(":")
    eventmanagergroupaddress = temp_list[0]
    eventmanagergroupport = int(temp_list[1])
    service = EventService(
        (eventmanagergroupaddress, eventmanagergroupport, 'br0'))
    event = LocationEvent()

    i = 1

    while i <= n_nodes:
        pathlossevt = PathlossEvent()
        j = 1
        while j <= n_nodes:
            if i != j:
                pathlossevt.append(j, forward=90, reverse=90)
            j = j + 1
        i = i + 1

    while nemid <= n_nodes:
        event.append(nemid,
                     latitude=Node[nemid]["lattitude"],
                     longitude=Node[nemid]["longitude"],
                     altitude=Node[nemid]["altitude"])
        nemid = nemid + 1
    service.publish(0, event)

    time.sleep(2)
    print "Location events published. All nodes set to initial positions. Waiting for 30 sec for routing updates to stabilize"
    time.sleep(50)

    # Timekeeper portion
    freeze_quantum = 1000000  # in nano seconds

    nemid = 1

    while nemid <= n_nodes:
        pid = int(getpidfromname("node-" + str(nemid)))
        print "PID of node ", nemid, " = ", pid, " TDF = ", Node[nemid]["tdf"]
        if pid != -1 and ENABLE_TIMEKEEPER == 1:
            dilate_all(pid, Node[nemid]["tdf"])
            addToExp(pid)
        if max_tdf < Node[nemid]["tdf"]:
            max_tdf = Node[nemid]["tdf"]

        nemid += 1

    lxc_pid = int(getpidfromname("node-1"))
    if os.path.exists(cwd + "/exp_finished.txt"):
        os.unlink(cwd + "/exp_finished.txt")

    # send commands to execute to each LXC
    nemid = 1
    while nemid <= n_nodes:
        if nemid % 2 == 0:
            process = subprocess.Popen([
                "python", "lxc_command_dispatcher.py",
                str(0),
                str(nemid), Node[nemid]["cmd"]
            ])
        else:
            process = subprocess.Popen([
                "python", "lxc_command_dispatcher.py",
                str(1),
                str(nemid), Node[nemid]["cmd"]
            ])
        nemid += 1

    print "Set freeze_quantum = ", freeze_quantum * max_tdf
    if ENABLE_TIMEKEEPER == 1 and max_tdf >= 1:

        set_cpu_affinity(int(os.getpid()))
        set_cbe_experiment_timeslice(freeze_quantum * max_tdf)
        print "Timekeeper synchronizing ..."
        synchronizeAndFreeze()
        startExp()
        print "Synchronized CBE experiment started ..."
        start_time = int(get_current_virtual_time_pid(int(lxc_pid)))
        prev_time = start_time
        print "Experiment start time", start_time, " local Time = " + str(
            datetime.now())
        sys.stdout.flush()

    else:
        print "Experiment Started with TimeKeeper disabled - Ignoring TDF settings"

    try:

        k = 0
        while True:

            if ENABLE_TIMEKEEPER == 1:
                curr_time = int(get_current_virtual_time_pid(int(lxc_pid)))

                if curr_time - start_time >= run_time:
                    break
                else:
                    if curr_time - prev_time >= 1:
                        k = k + (curr_time - prev_time)
                        print k, " secs of virtual time elapsed"
                        prev_time = curr_time

            else:
                if k >= run_time:
                    break
                k = k + 1
                print k, " secs of real time elapsed"
            # sleep until runtime expires
            time.sleep(1)

    except KeyboardInterrupt:
        pass

    # stop Exp
    print "Stopping Synchronized experiment, local time = " + str(
        datetime.now())
    if ENABLE_TIMEKEEPER == 1:
        stopExp()
        time.sleep(10)

    stop_LXCs(max_tdf)
Beispiel #13
0
 def handlePathloss(nemId, eventId, data, uuid, sequence):
     e = PathlossEvent()
     e.restore(data)
     header(nemId, eventId, data, 'Pathloss', uuid, sequence)
     for i in e:
         print "  ", i
Beispiel #14
0
#!/usr/bin/env python
from emanesh.events import EventService
from emanesh.events import PathlossEvent

# create the event service
service = EventService(('224.1.2.8',45703,'emanenode0'))

# create an event setting the pathloss between 1 & 10
event = PathlossEvent()
event.append(1,forward=90)
event.append(10,forward=90)

# publish the event
service.publish(1,event)
service.publish(10,event)

# create an event setting the pathloss between 9 & 10
event = PathlossEvent()
event.append(9,forward=90)
event.append(10,forward=90)

# publish the event
service.publish(9,event)
service.publish(10,event)