diff --git a/Election.md b/Election.md deleted file mode 100644 index fd350fa..0000000 --- a/Election.md +++ /dev/null @@ -1,36 +0,0 @@ -### Leader Election - -#### Introduction -Election algorithms mainly aim to select one process among other process to act as the organizer of some distributed task. In the election algorithms, it is assumed that every active process in the distributed system has a unique priority number. Election algorithms provides following properties - -#### Election Algorithm: Echo algorithm with Extinction - -In this section, the detailed information about echo algorithm with extinction is given. Behind this algorithm, there exist simple idea which is each initiator run the echo algorithm tagged with its ID. The wave started with highest ID completes. After that, that process, initiator becomes leader. -If there exist a non-initiator in the system, it joins the first wave that hits them. For example, consider two process, process p and process q, participating a wave tagged with their names. The process takes a wave message from q tagged with its ID - -\begin{itemize} - \item If q $>$ p, then p makes the process q, the sender, its parent and changes to wave tagged with p. After that, it behaves the incoming messages accordingly. - \item If p $>$ q, then p continues with the wave tagged with q. - \item If p $=$ q, then treats the incoming message by depending on the algorithm implemented of the wave tagged with q. -\end{itemize} - -#### Minimum Spanning Trees: The Gallager-Humblet-Spira algorithm - -First, if we consider the definition of minimum spanning tree, it is a tree that contains every process in the network and keeps the sum of the weights of channels minimum. It is assumed that different channels in the network have different weights in the network. - -The Gallager-Humblet-Spira algorithm is distributed version of Kruskal's algorithm which provides computing minimum spanning trees in a uni-processor setting. Kruskal's algorithm is based on choosing the lowest-weight edge in the network. In the implementation of Kruskal's algorithm cycles are not allowed, because it would be a contradiction with nature of minimum spanning trees. - -In distributed systems, it becomes harder for processes to decide whether its channels are outgoing edge or not. In the Gallager-Humblet-Spira algorithm, each fragment carries fragment name which is non-negative real number,and level which is greater or equal to 0. - -- sleep : If a processor in the sleep state, as happened in the election algorithm, it wakes up as soon as a message arrives -- find : If a processor in the find state, there can be 2 options: - - It might be waiting for report from its children for lowest-weight outgoing edge, - - Or, it is looking for its lowest-weight outgoing edge. -- found : If a processor is in the found state, it informed its parent about its lowest-weight outgoing edge and it is aware of to its parent. - -In addition there also exist status for channels of processes to maintain status, which are - -- basic edge : if an edge marked as a basic edge, then it is undecided whether it will be in the channel or not. -- branch edge : If the channel is a part of the minimum spanning tree, then it is a branch edge -- rejected : The rejected status means the channel is not a part of the minimum spanning tree -\end{itemize} \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100755 index 7accd06..0000000 --- a/test.py +++ /dev/null @@ -1,189 +0,0 @@ -import os -import sys -import time -import random -from enum import Enum -sys.path.insert(0, os.getcwd()) - -import networkx as nx -import matplotlib.pyplot as plt - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -import logging - -# define your own message types -class ApplicationLayerMessageTypes(Enum): - PROPOSE = "PROPOSE" - ACCEPT = "ACCEPT" - - -# define your own message header structure -class ApplicationLayerMessageHeader(GenericMessageHeader): - def __str__(self) -> str: - return "ApplicationLayerMessageHeader" - - -# define your own message payload structure -class ApplicationLayerMessagePayload(GenericMessagePayload): - def __str__(self) -> str: - return "ApplicationLayerMessagePayload" - - -class ApplicationLayerComponent(GenericModel): - - - def send_message(self): - destination = 1 - hdr = ApplicationLayerMessageHeader(ApplicationLayerMessageTypes.PROPOSE, self.componentinstancenumber, - destination) - payload = ApplicationLayerMessagePayload("23") - proposalmessage = GenericMessage(hdr, payload) - self.send_self(Event(self, "propose", proposalmessage)) - - def on_init(self, eventobj: Event): - if self.componentinstancenumber == 0: - self.t = AHCTimer(0.1, self.send_message) - self.t.start() - else: - pass - - def on_message_from_bottom(self, eventobj: Event): - try: - applmessage = eventobj.eventcontent - hdr = applmessage.header - if hdr.messagetype == ApplicationLayerMessageTypes.ACCEPT: - logger.applog( - f"Node-{self.componentinstancenumber} says Node-{hdr.messagefrom} has sent {hdr.messagetype} message") - elif hdr.messagetype == ApplicationLayerMessageTypes.PROPOSE: - logger.applog( - f"Node-{self.componentinstancenumber} says Node-{hdr.messagefrom} has sent {hdr.messagetype} message") - except AttributeError: - logger.error("Attribute Error") - - # logger.applog(f"{self.componentname}.{self.componentinstancenumber}: Gotton message {eventobj.content} ") - # value = eventobj.content.value - # value += 1 - # newmsg = MessageContent( value ) - # myevent = Event( self, "agree", newmsg ) - # self.trigger_event(myevent) - - def on_propose(self, eventobj: Event): - destination = 1 - hdr = ApplicationLayerMessageHeader(ApplicationLayerMessageTypes.ACCEPT, self.componentinstancenumber, - destination) - payload = ApplicationLayerMessagePayload("23") - proposalmessage = GenericMessage(hdr, payload) - self.send_down(Event(self, EventTypes.MFRT, proposalmessage)) - - def on_agree(self, eventobj: Event): - logger.applog(f"Agreed on {eventobj.eventcontent}") - - def on_timer_expired(self, eventobj: Event): - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - self.eventhandlers["propose"] = self.on_propose - self.eventhandlers["agree"] = self.on_agree - self.eventhandlers["timerexpired"] = self.on_timer_expired - - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - #logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - self.appl = ApplicationLayerComponent("ApplicationLayer", componentinstancenumber, topology=topology) - self.net = GenericNetworkLayer("NetworkLayer", componentinstancenumber, topology=topology) - self.link = GenericLinkLayer("LinkLayer", componentinstancenumber, topology=topology) - # self.failuredetect = GenericFailureDetector("FailureDetector", componentid) - - self.components.append(self.appl) - self.components.append(self.net) - self.components.append(self.link) - - ##Connect the bottom component to the composite component.... - ## CONNECTION USING INFIX OPERATAORS - self.appl |D| self.net - self.net |D| self.link - self.link |D| self - - self |U| self.link - self.link |U| self.net - self.net |U| self.appl - - ## CONNECTION using U (up) D (down) P (peer) functions - - # self.appl.D(self.net) - # self.net.D(self.link) - # self.link.D(self) - - # self.U(self.link) - # self.link.U(self.net) - # self.net.U(self.appl) - - ## CONNECTION USING direct function - # self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.net) - # self.net.connect_me_to_component(ConnectorTypes.UP, self.appl) - # self.net.connect_me_to_component(ConnectorTypes.DOWN, self.link) - # self.link.connect_me_to_component(ConnectorTypes.UP, self.net) - # self.link.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.UP, self.link) - - -def main(): - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - #setAHCLogLevel(25) - setAHCLogLevel(logging.INFO) - # G = nx.Graph() - # G.add_nodes_from([1, 2]) - # G.add_edges_from([(1, 2)]) - # nx.draw(G, with_labels=True, font_weight='bold') - # plt.draw() - #G = nx.random_geometric_graph(4, 0.1) - G =nx.Graph() - G.add_node(0) - G.add_node(1) - G.add_node(2) - G.add_edge(0,1) - G.add_edge(1,0) - G.add_edge(0,2) - G.add_edge(2,0) - G.add_edge(1,2) - G.add_edge(2,1) - - #nx.draw(G, with_labels=True, font_weight='bold') - #plt.draw() - # logger.debug("debug") - # logger.info("info") - # logger.warning("warning") - # logger.error("error") - # logger.critical("critical") - topo = Topology() - topo.construct_from_graph(G, AdHocNode, GenericChannel) - - topo.start() - - #plt.show() # while (True): pass - time.sleep(1) - logger.applog(str(topo)) - topo.exit() - -if __name__ == "__main__": - main() diff --git a/testAHCManager.py b/testAHCManager.py deleted file mode 100644 index 4dffd81..0000000 --- a/testAHCManager.py +++ /dev/null @@ -1,57 +0,0 @@ - - -import queue -from multiprocessing.managers import BaseManager -from multiprocessing.context import BaseContext -from multiprocessing import Queue - -import sys, os, signal -import argparse -import configparser -from adhoccomputing.Distribution.AHCManager import AHCManager, AHCManagerType -from adhoccomputing.Generics import * - -def parse_args(argv): - config = configparser.ConfigParser() - if argv is None: - logger.applog(f"Usage: {__name__} -c (--config_file)") - else: - argv = sys.argv - conf_parser = argparse.ArgumentParser( - description=__doc__, # printed with -h/--help - # Don't mess with format of description - formatter_class=argparse.RawDescriptionHelpFormatter, - # Turn off help, so we print all options in response to -h - add_help=False - ) - conf_parser.add_argument("-c", "--conf_file", - help="Specify config file", metavar="FILE") - conf_parser.add_argument("-s", "--section", - help="Specify config file", metavar="FILE") - - args, remaining_argv = conf_parser.parse_known_args() - DomainName = "localhost" - Port = 9000 - if args.conf_file: - config.read(args.conf_file) - logger.applog(f"{config.sections()}") - if (args.section in config): - conf = config[args.section] - DomainName = conf['DomainName'] - Port = conf['Port'] - - logger.applog(f"{DomainName}:{Port} will be the manager address") - address = (DomainName, Port) - return address - - -def main(argv): - setAHCLogLevel(21) - ahcmanager = AHCManager(AHCManagerType.AHC_CLIENT, argv) - ahcmanager.connect() - queue = ahcmanager.get_queue(10) - logger.applog(f"{queue.get()}") - -if __name__ == "__main__": - # freeze_support() - main(sys.argv) \ No newline at end of file diff --git a/testBladeRF.py b/testBladeRF.py deleted file mode 100644 index 3ff4e29..0000000 --- a/testBladeRF.py +++ /dev/null @@ -1,95 +0,0 @@ -import os -import sys, getopt -import time -import signal -sys.path.insert(0, os.getcwd()) - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.PhysicalLayer.BladeRFOfdmFlexFramePhy import BladeRFOfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.PingPongApplicationLayer import * -import logging - - -class BladeRFNode(GenericModel): - counter = 0 - def on_init(self, eventobj: Event): - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None, child_conn=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology, child_conn) - # SUBCOMPONENTS - - macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) - sdrconfig = SDRConfiguration(freq =2484000000, bandwidth = 1500000, chan = 0, hw_tx_gain = 30, hw_rx_gain = 39, sw_tx_gain = -12.0) - - - self.appl = PingPongApplicationLayer("PingPongApplicationLayer", componentinstancenumber, topology=topology) - self.phy = BladeRFOfdmFlexFramePhy("BladeRFOfdmFlexFramePhy", componentinstancenumber, usrpconfig=sdrconfig, topology=topology) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.phy) - self.components.append(self.mac) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -topo = Topology() -def main(argv): - - setAHCLogLevel(logging.INFO) - num_nodes = 1 -# Note that the topology has to specific: usrp winslab_b210_0 is run by instance 0 of the component -# Therefore, the usrps have to have names winslab_b210_x where x \in (0 to nodecount-1) - topo.construct_winslab_topology_without_channels(num_nodes, BladeRFNode) - #topo.mp_construct_sdr_topology_without_channels(num_nodes, BladeRFNode) - #topo.construct_winslab_topology_with_channels(2, UsrpNode, FIFOBroadcastPerfectChannel) - - # time.sleep(1) - # topo.nodes[0].send_self(Event(topo.nodes[0], UsrpNodeEventTypes.STARTBROADCAST, None)) - - topo.start() - time.sleep(1) - i = 1 - while(i<10000): - topo.nodes[0].appl.send_self(Event(topo.nodes[0], PingPongApplicationLayerEventTypes.STARTBROADCAST, "BMSG-")) - i += 1 - time.sleep(0.1) - - - time.sleep(3) - topo.exit() - - - -def ctrlc_signal_handler(sig, frame): - topo.exit() - time.sleep(1) - sys.exit(0) - - -def segfault_signal_handler(sig, frame): - topo.exit() - time.sleep(5) - sys.exit(0) - -if __name__ == "__main__": - - signal.signal(signal.SIGINT, ctrlc_signal_handler) - signal.signal(signal.SIGSEGV, segfault_signal_handler) - main(sys.argv[1:]) diff --git a/testDirectionalChannel.py b/testDirectionalChannel.py deleted file mode 100644 index 1792f1e..0000000 --- a/testDirectionalChannel.py +++ /dev/null @@ -1,67 +0,0 @@ -import os -import sys -import time -import pdb, traceback, sys - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel - - -import networkx as nx -import matplotlib.pyplot as plt - - -class SenderReceiver(GenericModel): - def on_init(self, eventobj: Event): - logger.applog(f"Initialized {self.componentname}-{self.componentinstancenumber}") - - if self.componentinstancenumber == 0: - self.send_self(Event(self, "generatemessage", "...")) - - def sendmessage(self): - self.sentcnt = self.sentcnt + 1 - msg = GenericMessage(GenericMessageHeader("AL", 0, 1), str(self.sentcnt)) - self.send_down(Event(self, EventTypes.MFRT, msg)) - - def on_generate_message(self, eventobj: Event): - self.sendmessage() - time.sleep(0.001) - self.send_self(Event(self, "generatemessage", "...")) - - def on_message_from_bottom(self, eventobj: Event): - logger.debug(f"{self.componentname} {self.componentinstancenumber} RECEIVED {str(eventobj)}") - self.recvcnt = self.recvcnt + 1 - sentcounter = int(eventobj.eventcontent.payload) - logger.applog(f"{self.componentinstancenumber}: ratio={self.recvcnt / sentcounter} [{self.recvcnt}, {sentcounter}]") - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - self.eventhandlers["generatemessage"] = self.on_generate_message - self.sentcnt = 0 - self.recvcnt = 0 - - -def main(): - setAHCLogLevel(21) - topo = Topology() - topo.construct_sender_receiver_directional(SenderReceiver, SenderReceiver, GenericChannel) - #nx.draw(topo.G, with_labels=True, font_weight='bold') - #plt.draw() - - # topo.computeForwardingTable() - - topo.start() - time.sleep(5) - topo.exit() - - -if __name__ == "__main__": - try: - main() - except: - extype, value, tb = sys.exc_info() - traceback.print_exc() - pdb.post_mortem(tb) diff --git a/testLogServer.py b/testLogServer.py deleted file mode 100644 index 9ec39fe..0000000 --- a/testLogServer.py +++ /dev/null @@ -1,22 +0,0 @@ -from http.server import BaseHTTPRequestHandler, HTTPServer -log = "LOG" -class handler(BaseHTTPRequestHandler): - - def do_GET(self): - global log - self.send_response(200) - self.send_header('Content-type','text/html') - self.end_headers() - - message = log - self.wfile.write(bytes(message, "utf8")) - print(message) - def do_POST(self): - global log - self.send_response(200) - self.send_header('Content-type','text/html') - self.end_headers() - log += str(self.rfile.read()) - -with HTTPServer(('', 8000), handler) as server: - server.serve_forever() \ No newline at end of file diff --git a/testUsrp.py b/testUsrp.py deleted file mode 100644 index 3ba1697..0000000 --- a/testUsrp.py +++ /dev/null @@ -1,95 +0,0 @@ -import os -import sys -import time, random, math -from enum import Enum -from pickle import FALSE - - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.PhysicalLayer.UsrpB210OfdmFlexFramePhy import UsrpB210OfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.PingPongApplicationLayer import * -import logging - -class UsrpNode(GenericModel): - counter = 0 - - def send_message(self): - #logger.applog(f"{self.componentname} {self.componentinstancenumber} sending broadcast message") - self.appl.send_self(Event(self, PingPongApplicationLayerEventTypes.STARTBROADCAST, "BMSG")) - - def on_init(self, eventobj: Event): - self.t = AHCTimer(1, self.send_message) - if self.componentinstancenumber == 0: - self.t.start() - - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None, child_conn=None, node_queues=None, channel_queues=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology, child_conn, node_queues, channel_queues) - # SUBCOMPONENTS - - macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -50) - #sdrconfig = SDRConfiguration(freq =900000000.0, bandwidth = 250000, chan = 0, hw_tx_gain = 70.0, hw_rx_gain = 20.0, sw_tx_gain = -12.0) - #sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 2000000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 70, sw_tx_gain = -12.0) - #sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 20000000, chan = 0, hw_tx_gain = 76, hw_rx_gain = 20, sw_tx_gain = -12.0) - #sdrconfig = SDRConfiguration(freq =2484000000.0, bandwidth = 1000000, chan = 0, hw_tx_gain = 76, hw_rx_gain = 30, sw_tx_gain = -12.0) - #bladerfconfig = SDRConfiguration(freq =900000000.0, bandwidth = 1048576, chan = 0, hw_tx_gain = 50.0, hw_rx_gain = 20.0, sw_tx_gain = -12.0) - - #macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) - #sdrconfig = SDRConfiguration(freq =2484000000.0, bandwidth = 1500000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 30, sw_tx_gain = -12.0) - sdrconfig = SDRConfiguration(freq =912000000.0, bandwidth = 1000000.0, chan = 0, hw_tx_gain = 70.0, hw_rx_gain = 20.0, sw_tx_gain = -12.0) - - self.appl = PingPongApplicationLayer("PingPongApplicationLayer", componentinstancenumber, topology=topology) - self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, usrpconfig=sdrconfig, topology=topology) - print(self.phy.sdrdev) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev,topology=topology) - - self.components.append(self.appl) - self.components.append(self.phy) - self.components.append(self.mac) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - - -def main(): - setAHCLogLevel(logging.INFO) - topo = Topology() -# Note that the topology has to specific: usrp winslab_b210_0 is run by instance 0 of the component -# Therefore, the usrps have to have names winslab_b210_x where x \in (0 to nodecount-1) - topo.construct_winslab_topology_without_channels(2, UsrpNode) - #topo.mp_construct_sdr_topology_without_channels(2,UsrpNode) - # topo.construct_winslab_topology_with_channels(2, UsrpNode, FIFOBroadcastPerfectChannel) - - # time.sleep(1) - # topo.nodes[0].send_self(Event(topo.nodes[0], UsrpNodeEventTypes.STARTBROADCAST, None)) - - topo.start() - i = 0 - while(i < 100): - #topo.nodes[1].appl.send_self(Event(topo.nodes[1], PingPongApplicationLayerEventTypes.STARTBROADCAST, "BMSG1")) - #time.sleep(0.1) - #topo.nodes[0].appl.send_self(Event(topo.nodes[0], PingPongApplicationLayerEventTypes.STARTBROADCAST, "BMSG0-")) - time.sleep(1) - i = i + 1 - topo.exit() - - -if __name__ == "__main__": - main() diff --git a/testUsrpBladeRF.py b/testUsrpBladeRF.py deleted file mode 100644 index 49289d7..0000000 --- a/testUsrpBladeRF.py +++ /dev/null @@ -1,115 +0,0 @@ -import os -import sys -import time, random, math -from enum import Enum -from pickle import FALSE - - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.PhysicalLayer.UsrpB210OfdmFlexFramePhy import UsrpB210OfdmFlexFramePhy -from adhoccomputing.Networking.PhysicalLayer.BladeRFOfdmFlexFramePhy import BladeRFOfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.PingPongApplicationLayer import * -import logging -import random - -macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) -bladerfconfig = SDRConfiguration(freq =2484000000, bandwidth = 1500000, chan = 0, hw_tx_gain = 30, hw_rx_gain = 39, sw_tx_gain = -12.0) -usrpconfig = SDRConfiguration(freq =2484000000.0, bandwidth = 1500000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 39, sw_tx_gain = -12.0) - -class UsrpNode(GenericModel): - counter = 0 - def on_init(self, eventobj: Event): - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - self.appl = PingPongApplicationLayer("PingPongApplicationLayer", componentinstancenumber, topology=topology) - self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, usrpconfig=usrpconfig, topology=topology) - print(self.phy.sdrdev) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev,topology=topology) - - self.components.append(self.appl) - self.components.append(self.phy) - self.components.append(self.mac) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -class BladeRFNode(GenericModel): - counter = 0 - def on_init(self, eventobj: Event): - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None, child_conn=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology, child_conn) - # SUBCOMPONENTS - - self.appl = PingPongApplicationLayer("PingPongApplicationLayer", componentinstancenumber, topology=topology) - self.phy = BladeRFOfdmFlexFramePhy("BladeRFOfdmFlexFramePhy", componentinstancenumber, usrpconfig=bladerfconfig, topology=topology) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.phy) - self.components.append(self.mac) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - - -def main(): - setAHCLogLevel(logging.INFO) - topo = Topology() -# Note that the topology has to specific: usrp winslab_b210_0 is run by instance 0 of the component -# Therefore, the usrps have to have names winslab_b210_x where x \in (0 to nodecount-1) - topo.construct_winslab_topology_usrp_bladerf(1,1, UsrpNode, BladeRFNode) - # topo.construct_winslab_topology_with_channels(2, UsrpNode, FIFOBroadcastPerfectChannel) - - # time.sleep(1) - # topo.nodes[0].send_self(Event(topo.nodes[0], UsrpNodeEventTypes.STARTBROADCAST, None)) - - topo.start() - time.sleep(1) - i = 0 - while(i < 10000): - topo.nodes[0].appl.send_self(Event(topo.nodes[0], PingPongApplicationLayerEventTypes.STARTBROADCAST, "USRP-BMSG-")) - time.sleep(random.uniform(0, 1)) - topo.nodes[1].appl.send_self(Event(topo.nodes[1], PingPongApplicationLayerEventTypes.STARTBROADCAST, "BLADERF-BMSG-")) - time.sleep(random.uniform(0, 1)) - #topo.nodes[1].appl.send_self(Event(topo.nodes[1], PingPongApplicationLayerEventTypes.STARTBROADCAST, None)) - #time.sleep(0.1) - i = i + 1 - topo.exit() - - -if __name__ == "__main__": - main() diff --git a/testUsrpIndividually.py b/testUsrpIndividually.py deleted file mode 100644 index 86a9295..0000000 --- a/testUsrpIndividually.py +++ /dev/null @@ -1,101 +0,0 @@ -import os -import sys, getopt -import time -import signal -sys.path.insert(0, os.getcwd()) - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.PhysicalLayer.UsrpB210OfdmFlexFramePhy import UsrpB210OfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.PingPongApplicationLayer import * -import logging - - -class UsrpNode(GenericModel): - counter = 0 - def on_init(self, eventobj: Event): - pass - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) - sdrconfig = SDRConfiguration(freq =2484000000.0, bandwidth = 1500000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 30, sw_tx_gain = -12.0) - - self.appl = PingPongApplicationLayer("PingPongApplicationLayer", componentinstancenumber, topology=topology) - self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, topology=topology,usrpconfig=sdrconfig ) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.phy) - self.components.append(self.mac) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -topo = Topology() - -def main(argv): - setAHCLogLevel(logging.INFO) - id = 0 #default 0 if arg -i is not given - try: - opts, args = getopt.getopt(argv,"hi:",["id="]) - except getopt.GetoptError: - logger.error ("testUsrpIndividually.py -i ") - sys.exit(2) - for opt, arg in opts: - if opt == '-h': - logger.error ("testUsrpIndividually.py -i ") - sys.exit() - elif opt in ("-i", "--ifile"): - id = arg - - -# Note that the topology has to specific: usrp winslab_b210_0 is run by instance 0 of the component -# Therefore, the usrps have to have names winslab_b210_x where x \in (0 to nodecount-1) - topo.construct_winslab_topology_without_channels_for_docker(UsrpNode, id) - # topo.construct_winslab_topology_with_channels(2, UsrpNode, FIFOBroadcastPerfectChannel) - - # time.sleep(1) - # topo.nodes[0].send_self(Event(topo.nodes[0], UsrpNodeEventTypes.STARTBROADCAST, None)) - - topo.start() - time.sleep(1) - while(True): - topo.nodes[0].appl.send_self(Event(topo.nodes[0], PingPongApplicationLayerEventTypes.STARTBROADCAST, "BMSG-")) - time.sleep(0.1) - - #time.sleep(5) - #topo.exit() - - -def ctrlc_signal_handler(sig, frame): - topo.exit() - time.sleep(5) - sys.exit(0) - - -def segfault_signal_handler(sig, frame): - topo.exit() - time.sleep(5) - sys.exit(0) - -if __name__ == "__main__": - signal.signal(signal.SIGINT, ctrlc_signal_handler) - signal.signal(signal.SIGSEGV, segfault_signal_handler) - main(sys.argv[1:]) diff --git a/testVideoStreaming.py b/testVideoStreaming.py deleted file mode 100644 index 86ffc90..0000000 --- a/testVideoStreaming.py +++ /dev/null @@ -1,85 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import time -import cv2 - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -from adhoccomputing.Networking.ApplicationLayer.OpenCVVideoStreamingApp import * -from adhoccomputing.Networking.ApplicationLayer.MessageSegmentation import * - -appconfig = OpenCVVideoStreamingAppConfig(10) - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - self.appl = OpenCVVideoStreamingApp("OpenCVVideoStreamingApp", componentinstancenumber, topology=topology, configurationparameters=appconfig) - self.seg = MessageSegmentation("MessageSegmentation", componentinstancenumber, topology=topology) - - self.components.append(self.appl) - self.components.append(self.seg) - - ##Connect the bottom component to the composite component.... - ## CONNECTION USING INFIX OPERATAORS - self.appl |D| self.seg - self.seg |D| self - - self |U| self.seg - self.seg |U| self.appl - -def main(): - - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - setAHCLogLevel(25) - setAHCLogLevel(LOG_LEVEL_APPLOG) - topo = Topology() - topo.construct_sender_receiver(AdHocNode, AdHocNode, GenericChannel) - topo.start() - topo.nodes[0].appl.trigger_event(Event(None, OpenCVVideoStreamingAppEventTypes.STARTSTREAMING, "")) - - cap = cv2.VideoCapture(0) - #cap.set(3,640) - #cap.set(4,480) - - #fourcc = cv2.VideoWriter_fourcc(*'MP4V') - #out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) - - while(True): - frame = topo.nodes[1].appl.frame - if frame is not None: - #out.write(frame) - #frameresized = cv2.resize(frame, (640,480)) - frameresized = frame - cv2.imshow('frame', frameresized) - c = cv2.waitKey(1) - if c & 0xFF == ord('q'): - break - - cap.release() - #out.release() - cv2.destroyAllWindows() - - topo.exit() - time.sleep(5) - -if __name__ == "__main__": - main() diff --git a/testVideoStreamingBladeRF.py b/testVideoStreamingBladeRF.py deleted file mode 100644 index 960aed3..0000000 --- a/testVideoStreamingBladeRF.py +++ /dev/null @@ -1,115 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import time -import cv2 - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -from adhoccomputing.Networking.ApplicationLayer.OpenCVVideoStreamingApp import * -from adhoccomputing.Networking.PhysicalLayer.BladeRFOfdmFlexFramePhy import BladeRFOfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.MessageSegmentation import * -import logging - - -macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) -#sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 4000000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 30, sw_tx_gain = -12.0) -sdrconfig = SDRConfiguration(freq =2484000000, bandwidth = 1500000, chan = 0, hw_tx_gain = 30, hw_rx_gain = 39, sw_tx_gain = -12.0) - -appconfig = OpenCVVideoStreamingAppConfig(10) - - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - self.appl = OpenCVVideoStreamingApp("OpenCVVideoStreamingApp", componentinstancenumber, topology=topology, configurationparameters=appconfig) - self.seg = MessageSegmentation("MessageSegmentation", componentinstancenumber, topology=topology) - self.phy = BladeRFOfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, topology=topology,usrpconfig=sdrconfig, ) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.mac) - self.components.append(self.seg) - #self.components.append(self.phy) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.seg) - - self.seg.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.seg.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.seg) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -def main(): - - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - setAHCLogLevel(25) - setAHCLogLevel(logging.INFO) - topo = Topology() - #topo.construct_sender_receiver(AdHocNode, AdHocNode, GenericChannel) - topo.construct_winslab_topology_without_channels_for_docker(AdHocNode, 0) - - - - - cap = cv2.VideoCapture(0) - cap.set(3,640) - cap.set(4,480) - #cv2.startWindowThread() - fourcc = cv2.VideoWriter_fourcc(*'MP4V') - #out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) - cv2.namedWindow('frame') - logger.applog(f"Frame rate will be {appconfig.framerate}") - topo.start() - time.sleep(3) - topo.nodes[0].phy.trigger_event(Event(None, EventTypes.INIT, "")) - topo.nodes[0].appl.send_self(Event(None, OpenCVVideoStreamingAppEventTypes.STARTSTREAMING, "")) - while(True): - frame = topo.nodes[0].appl.frame - if frame is not None: - #out.write(frame) - #frameresized = cv2.resize(frame, (640,480)) - cv2.imshow('frame', frame) - c = cv2.waitKey(1) - if c & 0xFF == ord('q'): - break - - cap.release() - #out.release() - cv2.destroyAllWindows() - - topo.exit() - time.sleep(5) - -if __name__ == "__main__": - main() diff --git a/testVideoStreamingTwoBladeRFs.py b/testVideoStreamingTwoBladeRFs.py deleted file mode 100644 index 89aa77e..0000000 --- a/testVideoStreamingTwoBladeRFs.py +++ /dev/null @@ -1,126 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import time -import cv2 - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -from adhoccomputing.Networking.ApplicationLayer.OpenCVVideoStreamingApp import * -from adhoccomputing.Networking.PhysicalLayer.BladeRFOfdmFlexFramePhy import BladeRFOfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.MessageSegmentation import * -import logging - - -macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -30) -#sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 20000000, chan = 0, hw_tx_gain = 76, hw_rx_gain = 20, sw_tx_gain = -12.0) -sdrconfig = SDRConfiguration(freq =2484000000, bandwidth = 2000000, chan = 0, hw_tx_gain = 0, hw_rx_gain = 39, sw_tx_gain = -12.0) -appconfig = OpenCVVideoStreamingAppConfig(20) - - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - self.appl = OpenCVVideoStreamingApp("OpenCVVideoStreamingApp", componentinstancenumber, topology=topology, configurationparameters=appconfig) - self.seg = MessageSegmentation("MessageSegmentation", componentinstancenumber, topology=topology) - self.phy = BladeRFOfdmFlexFramePhy("BladeRFOfdmFlexFramePhy", componentinstancenumber, usrpconfig=sdrconfig, topology=topology) -# self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, topology=topology,usrpconfig=sdrconfig, ) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.mac) - self.components.append(self.seg) - #self.components.append(self.phy) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.seg) - - self.seg.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.seg.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.seg) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -def main(): - - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - setAHCLogLevel(25) - setAHCLogLevel(logging.INFO) - topo = Topology() - #topo.construct_sender_receiver(AdHocNode, AdHocNode, GenericChannel) - num_nodes = 2 - topo.construct_winslab_topology_without_channels(num_nodes, AdHocNode, 0) - - - - - cap = cv2.VideoCapture(0) - cap.set(3,640) - cap.set(4,480) - cv2.startWindowThread() - #fourcc = cv2.VideoWriter_fourcc(*'MP4V') - #out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) - cv2.namedWindow('frame0') - cv2.namedWindow('frame1') - cv2.namedWindow('frame2') - #ret, frame = cap.read() - #cv2.imshow('frame', frame ) - #c = cv2.waitKey(1) - logger.applog(f"Frame rate will be {appconfig.framerate}") - topo.start() - # - time.sleep(3) - for i in range(num_nodes): - topo.nodes[i].phy.trigger_event(Event(None, EventTypes.INIT, "")) - #topo.nodes[1].phy.trigger_event(Event(None, EventTypes.INIT, "")) - # - topo.nodes[0].appl.send_self(Event(None, OpenCVVideoStreamingAppEventTypes.STARTSTREAMING, "")) - while(True): - for i in range(num_nodes): - frame = topo.nodes[i].appl.frame - if frame is not None: - #out.write(frame) - f = cv2.resize(frame, (640,480)) - cv2.imshow('frame'+str(i), f) - c = cv2.waitKey(1) - if c & 0xFF == ord('q'): - break - - cap.release() - #out.release() - cv2.destroyAllWindows() - - topo.exit() - time.sleep(5) - -if __name__ == "__main__": - main() diff --git a/testVideoStreamingTwoUSRPs.py b/testVideoStreamingTwoUSRPs.py deleted file mode 100644 index 0b23b1b..0000000 --- a/testVideoStreamingTwoUSRPs.py +++ /dev/null @@ -1,122 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import time -import cv2 - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -from adhoccomputing.Networking.ApplicationLayer.OpenCVVideoStreamingApp import * -from adhoccomputing.Networking.PhysicalLayer.UsrpB210OfdmFlexFramePhy import UsrpB210OfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.MessageSegmentation import * -import logging - - -macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -30) -sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 20000000, chan = 0, hw_tx_gain = 76, hw_rx_gain = 20, sw_tx_gain = -12.0) -appconfig = OpenCVVideoStreamingAppConfig(20) - - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - self.appl = OpenCVVideoStreamingApp("OpenCVVideoStreamingApp", componentinstancenumber, topology=topology, configurationparameters=appconfig) - self.seg = MessageSegmentation("MessageSegmentation", componentinstancenumber, topology=topology) - self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, topology=topology,usrpconfig=sdrconfig, ) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.mac) - self.components.append(self.seg) - #self.components.append(self.phy) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.seg) - - self.seg.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.seg.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.seg) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -def main(): - - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - setAHCLogLevel(25) - setAHCLogLevel(logging.INFO) - topo = Topology() - #topo.construct_sender_receiver(AdHocNode, AdHocNode, GenericChannel) - topo.construct_winslab_topology_without_channels(2, AdHocNode, 0) - - - - - cap = cv2.VideoCapture(0) - cap.set(3,640) - cap.set(4,480) - cv2.startWindowThread() - #fourcc = cv2.VideoWriter_fourcc(*'MP4V') - #out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) - cv2.namedWindow('frame0') - cv2.namedWindow('frame1') - #ret, frame = cap.read() - #cv2.imshow('frame', frame ) - #c = cv2.waitKey(1) - logger.applog(f"Frame rate will be {appconfig.framerate}") - topo.start() - # - time.sleep(3) - topo.nodes[0].phy.trigger_event(Event(None, EventTypes.INIT, "")) - topo.nodes[1].phy.trigger_event(Event(None, EventTypes.INIT, "")) - # - topo.nodes[0].appl.send_self(Event(None, OpenCVVideoStreamingAppEventTypes.STARTSTREAMING, "")) - while(True): - frame = topo.nodes[1].appl.frame - if frame is not None: - #out.write(frame) - f0 = cv2.resize(topo.nodes[0].appl.frame, (640,480)) - f1 = cv2.resize(topo.nodes[1].appl.frame, (640,480)) - cv2.imshow('frame0', f0) - cv2.imshow('frame1', f1) - c = cv2.waitKey(1) - if c & 0xFF == ord('q'): - break - - cap.release() - #out.release() - cv2.destroyAllWindows() - - topo.exit() - time.sleep(5) - -if __name__ == "__main__": - main() diff --git a/testVideoStreamingUSRP.py b/testVideoStreamingUSRP.py deleted file mode 100644 index e77e629..0000000 --- a/testVideoStreamingUSRP.py +++ /dev/null @@ -1,116 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import time -import cv2 - - -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LinkLayer.GenericLinkLayer import GenericLinkLayer -from adhoccomputing.Networking.NetworkLayer.GenericNetworkLayer import GenericNetworkLayer -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -from adhoccomputing.Networking.ApplicationLayer.OpenCVVideoStreamingApp import * -from adhoccomputing.Networking.PhysicalLayer.UsrpB210OfdmFlexFramePhy import UsrpB210OfdmFlexFramePhy -from adhoccomputing.Networking.MacProtocol.CSMA import MacCsmaPPersistent, MacCsmaPPersistentConfigurationParameters -from adhoccomputing.Networking.ApplicationLayer.MessageSegmentation import * -import logging - - -macconfig = MacCsmaPPersistentConfigurationParameters(0.5, -40) -#sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 4000000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 30, sw_tx_gain = -12.0) -#sdrconfig = SDRConfiguration(freq =915000000.0, bandwidth = 1500000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 30, sw_tx_gain = -12.0) -sdrconfig = SDRConfiguration(freq =2484000000.0, bandwidth = 1500000, chan = 0, hw_tx_gain = 70, hw_rx_gain = 39, sw_tx_gain = -12.0) - -appconfig = OpenCVVideoStreamingAppConfig(10) - - -class AdHocNode(GenericModel): - - def on_init(self, eventobj: Event): - logger.applog(f"Initializing {self.componentname}.{self.componentinstancenumber}") - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(eventobj) - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(eventobj) - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology) - # SUBCOMPONENTS - - self.appl = OpenCVVideoStreamingApp("OpenCVVideoStreamingApp", componentinstancenumber, topology=topology, configurationparameters=appconfig) - self.seg = MessageSegmentation("MessageSegmentation", componentinstancenumber, topology=topology) - self.phy = UsrpB210OfdmFlexFramePhy("UsrpB210OfdmFlexFramePhy", componentinstancenumber, topology=topology,usrpconfig=sdrconfig, ) - self.mac = MacCsmaPPersistent("MacCsmaPPersistent", componentinstancenumber, configurationparameters=macconfig, sdr=self.phy.sdrdev, topology=topology) - - self.components.append(self.appl) - self.components.append(self.mac) - self.components.append(self.seg) - #self.components.append(self.phy) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.appl.connect_me_to_component(ConnectorTypes.UP, self) #Not required if nodemodel will do nothing - self.appl.connect_me_to_component(ConnectorTypes.DOWN, self.seg) - - self.seg.connect_me_to_component(ConnectorTypes.UP, self.appl) - self.seg.connect_me_to_component(ConnectorTypes.DOWN, self.mac) - - self.mac.connect_me_to_component(ConnectorTypes.UP, self.seg) - self.mac.connect_me_to_component(ConnectorTypes.DOWN, self.phy) - - # Connect the bottom component to the composite component.... - self.phy.connect_me_to_component(ConnectorTypes.UP, self.mac) - self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - - # self.phy.connect_me_to_component(ConnectorTypes.DOWN, self) - # self.connect_me_to_component(ConnectorTypes.DOWN, self.appl) - - -def main(): - - #NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL - setAHCLogLevel(25) - setAHCLogLevel(logging.INFO) - topo = Topology() - #topo.construct_sender_receiver(AdHocNode, AdHocNode, GenericChannel) - topo.construct_winslab_topology_without_channels_for_docker(AdHocNode, 0) - - - - - cap = cv2.VideoCapture(0) - cap.set(3,640) - cap.set(4,480) - #cv2.startWindowThread() - fourcc = cv2.VideoWriter_fourcc(*'MP4V') - #out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) - cv2.namedWindow('frame') - logger.applog(f"Frame rate will be {appconfig.framerate}") - topo.start() - time.sleep(3) - topo.nodes[0].phy.trigger_event(Event(None, EventTypes.INIT, "")) - topo.nodes[0].appl.send_self(Event(None, OpenCVVideoStreamingAppEventTypes.STARTSTREAMING, "")) - while(True): - frame = topo.nodes[0].appl.frame - if frame is not None: - #out.write(frame) - #frameresized = cv2.resize(frame, (640,480)) - cv2.imshow('frame', frame) - c = cv2.waitKey(1) - if c & 0xFF == ord('q'): - break - - cap.release() - #out.release() - cv2.destroyAllWindows() - - topo.exit() - time.sleep(5) - -if __name__ == "__main__": - main() diff --git a/test_mp_composition.py b/test_mp_composition.py deleted file mode 100755 index b40e327..0000000 --- a/test_mp_composition.py +++ /dev/null @@ -1,99 +0,0 @@ -import os -import sys -import time -sys.path.insert(0, os.getcwd()) -import networkx as nx -from adhoccomputing.GenericModel import GenericModel -from adhoccomputing.Generics import * -from adhoccomputing.Experimentation.Topology import Topology -from adhoccomputing.Networking.LogicalChannels.GenericChannel import GenericChannel -import queue -from multiprocessing import Manager, freeze_support -from adhoccomputing.Distribution.AHCManager import AHCManager, AHCManagerType - -CRED = '\033[91m' -CEND = '\033[0m' - -class A(GenericModel): - counter = 0 - def send_message(self): - self.counter += 1 - evt = Event(self, EventTypes.MFRT, "TO CHANNEL" + str(self.counter)) - self.send_down(evt) - logger.applog(f"I am {self.componentname}-{self.componentinstancenumber}, {str(evt)}") - - def on_init(self, eventobj: Event): - logger.applog(f"I am {self.componentname}-{self.componentinstancenumber}, will run on_init") - - if self.componentinstancenumber == 0: - self.t = AHCTimer(1, self.send_message) # 1 SECOND - self.t.start() - logger.applog(f"I am {self.componentname}-{self.componentinstancenumber}, started message sending thread with AHCTimer") - - - def on_message_from_bottom(self, eventobj: Event): - logger.applog(f"I am {self.componentname}-{self.componentinstancenumber}, eventcontent={eventobj.eventcontent}") - -class Node(GenericModel): - def on_init(self, eventobj: Event): - pass - - def on_message_from_top(self, eventobj: Event): - self.send_down(Event(self, EventTypes.MFRT, eventobj.eventcontent)) - logger.applog(f"{self.componentname}.{self.componentinstancenumber} RECEIVED {str(eventobj)}") - - - def on_message_from_bottom(self, eventobj: Event): - self.send_up(Event(self, EventTypes.MFRB, eventobj.eventcontent)) - logger.applog(f"{self.componentname}.{self.componentinstancenumber} RECEIVED {str(eventobj)}") - - def __init__(self, componentname, componentinstancenumber, context=None, configurationparameters=None, num_worker_threads=1, topology=None, child_conn=None, node_queues=None, channel_queues=None): - super().__init__(componentname, componentinstancenumber, context, configurationparameters, num_worker_threads, topology, child_conn, node_queues, channel_queues) - # SUBCOMPONENTS - - self.A = A("A", componentinstancenumber, topology=topology) - self.components.append(self.A) - - # CONNECTIONS AMONG SUBCOMPONENTS - self.A.connect_me_to_component(ConnectorTypes.DOWN, self) - self.connect_me_to_component(ConnectorTypes.UP, self.A) - -def main(argv): - setAHCLogLevel(DEBUG) - set_start_method = "fork"; - topo = Topology() - - # numnodes = 10 - # topo.mp_construct_sdr_topology_without_channels( numnodes, Node ) - # topo.start() - # time.sleep(1) - # topo.exit() - - #G = nx.random_geometric_graph(4, 1) - G =nx.Graph() - G.add_node(0) - G.add_node(1) - G.add_node(2) - G.add_edge(0,1) - G.add_edge(1,0) - G.add_edge(0,2) - G.add_edge(2,0) - G.add_edge(1,2) - G.add_edge(2,1) - - ahcmanager = AHCManager(AHCManagerType.AHC_CLIENT, argv) - try: - ahcmanager.connect() - except Exception as ex: - logger.critical("Could not connect to AHCManager that helps distributing processes over different machines.") - topo.mp_construct_sdr_topology(G, Node, GenericChannel,ahcmanager) - logger.applog("Will start the emulation") - topo.start() - while(True): - time.sleep(1) - topo.exit() - - -if __name__ == "__main__": - freeze_support() - main(sys.argv)