Esempio n. 1
0
def main():
    seed = 123
    tx_range = 100
    num_data = 1
    ROUND = 1
    random.seed(seed)
    sim = wsp.Simulator(timescale=0, until=50, terrain_size=(700, 700), visual=False)
    nodes = generate_node(seed)
    for px, py in nodes:
        sim.add_node(PhaseI, (px, py))
    # sim.master = master
    sim.master = random.randint(0, 99)
    sim.tx_range = tx_range
    sim.run()

    sim2 = wsp.Simulator(timescale=3, until=50, terrain_size=(700, 700), visual=True)
    
    # copy data from PhaseI to PhaseII
    for n in sim.nodes:
        sim2.add_node(PhaseII, n.pos)
    for i in range(len(sim.nodes)):
        if sim2.nodes[i].id != sim.nodes[i].my_master:
            sim2.nodes[i].my_master = sim.nodes[i].my_master
            sim2.nodes[i].prev = sim.nodes[i].prev
        else:
            sim2.nodes[i].my_master = sim.nodes[i].my_master
            sim2.nodes[i].P = sim.nodes[i].P
            sim2.nodes[i].I = sim.nodes[i].I
            sim2.nodes[i].T = sim.nodes[i].T
        sim2.nodes[i].tx_range = sim.nodes[i].tx_range
    sim2.source, _ = generate_data(4, num_data, 99)
    sim2.ROUND = ROUND
    sim2.run()
def runsim(seed, tx_range, num_data, ROUND):
    random.seed(seed)
    sim = wsp.Simulator(timescale=0, until=50, terrain_size=(700, 700), visual=False)
    # sim = wsp.Simulator(timescale=0.1, until=50, terrain_size=(700, 700), visual=True)
    # place 100 nodes on 10x10 grid space
    nodes = generate_node(seed)
    for px, py in nodes:
        sim.add_node(PhaseI, (px, py))
    # sim.master = master
    sim.master = random.randint(0, 99)
    sim.tx_range = tx_range
    sim.run()

    sim2 = wsp.Simulator(timescale=0, until=50, terrain_size=(700, 700), visual=False)
    
    # copy data from PhaseI to PhaseII
    for n in sim.nodes:
        sim2.add_node(PhaseII, n.pos)
    for i in range(len(sim.nodes)):
        if sim2.nodes[i].id != sim.nodes[i].my_master:
            sim2.nodes[i].my_master = sim.nodes[i].my_master
            sim2.nodes[i].prev = sim.nodes[i].prev
        else:
            sim2.nodes[i].my_master = sim.nodes[i].my_master
            sim2.nodes[i].P = sim.nodes[i].P
            sim2.nodes[i].I = sim.nodes[i].I
            sim2.nodes[i].T = sim.nodes[i].T
        sim2.nodes[i].tx_range = sim.nodes[i].tx_range
    sim2.source, _ = generate_data(seed, num_data, 99)
    sim2.ROUND = ROUND
    sim2.run()

    s1 = sum([n.send_packets for n in sim.nodes])
    s2 = sum([n.send_packets for n in sim2.nodes])
    return s1 + s2
def runsim(seed, u, v, tx_range, ROUND):
    random.seed(seed)
    sim = wsp.Simulator(until=100,
                        timescale=0,
                        visual=False,
                        terrain_size=(700, 700),
                        title="AODV Demo")

    # define a line style for parent links
    sim.scene.linestyle("parent", color=(0, .8, 0), arrow="tail", width=2)
    sim.SOURCE = u
    sim.DEST = v
    sim.ROUND = ROUND
    # place nodes over 100x100 grids
    nodes = generate_node(seed)
    for px, py in nodes:
        node = sim.add_node(MyNode, (px, py))
        node.tx_range = tx_range
        node.logging = True

    # start the simulation
    sim.run()

    packets = sum([n.send_packets for n in sim.nodes])
    return packets
def main():
    seed = 123
    tx_range = 100
    random.seed(seed)
    sim = wsp.Simulator(timescale=1,
                        until=50,
                        terrain_size=(700, 700),
                        visual=True)
    nodes = generate_node(seed)
    for px, py in nodes:
        sim.add_node(PhaseI, (px, py))
    sim.master = random.randint(0, 99)
    sim.tx_range = tx_range
    sim.run()
Esempio n. 5
0
                        #line2 = self.scene.line(x+5,y-5,x-5,y+5,line="wsnsimpy:collision")
                        #self.delayed_exec(1,self.scene.delshape,line1)
                        #self.delayed_exec(1,self.scene.delshape,line2)
                        #


#not sure if can remove
debugNodeId = 3
scale = 100
tsx, tsy = (500, 1200)
tsx *= 2
tsy *= 2
terrSize = (tsx, tsy)
sim = wsp.Simulator(until=100000,
                    timescale=0,
                    visual=True,
                    terrain_size=terrSize,
                    title="LoraTree")
# place nodes

sim.add_node(LoraSink, (0, 0), .4)
sim.add_node(RelayNode, (300, 0), .4)
sim.add_node(RelayNode, (600, 0), .4)
sim.add_node(RelayNode, (900, 0), .4)
sim.add_node(LoraEDNode, (1200, 0), .4)

sim.scene.linestyle("parent", color=(0, .8, 0), arrow="tail", width=2)
sim.run()
sen = 0
rec = 0
coll = 0
Esempio n. 6
0
    scale = .15
else:
    scale = args.scale / 100

xGrid, yGrid = args.gridSize

sinksNo = args.gw
#not sure if can remove
debugNodeId = 3

tsx, tsy = args.terrSize

terrSize = (tsx, tsy)
sim = wsp.Simulator(until=args.simTime,
                    timescale=0,
                    visual=args.visual,
                    terrain_size=terrSize,
                    title="LoraTree")
# place nodes

relNo = args.relay
ran = list(range(xGrid * yGrid - 1))
sinksIds = np.random.choice(range(xGrid * yGrid - 1), sinksNo, replace=False)
rel = [nid for nid in ran if nid not in sinksIds]
relayIds = np.random.choice(rel, relNo, replace=False)
nodeID = 0
for x in range(xGrid):
    for y in range(yGrid):
        px = x * (terrSize[0] / xGrid) + random.uniform(
            -(terrSize[0] / (xGrid * 6)), (terrSize[0] / (xGrid * 6)))
        py = y * (terrSize[1] / yGrid) + random.uniform(
Esempio n. 7
0
                    instances = (distance[0], neighbor)
                    distances.append(instances)
        return min(distances)[1].id

    def start_send(self):
        print(self.id)
        self.scene.clearlinks()
        seq = 0
        while True:
            yield self.timeout(1)
            self.log(f"start send from source with seq {seq}")
            self.forward(self.id, seq)
            seq += 1


###########################################################
sim = wsp.Simulator(until=100,
                    timescale=1,
                    visual=True,
                    terrain_size=(700, 700),
                    title="Flooding Demo")
for x in range(10):
    for y in range(10):
        px = 50 + x * 60 + random.uniform(-20, 20)
        py = 50 + y * 60 + random.uniform(-20, 20)
        node = sim.add_node(MyNode, (px, py))
        node.tx_range = 100
        node.logging = True

sim.run()