docs: updated formatting on tutorial files
This commit is contained in:
parent
81230edac3
commit
cbc35b74f8
13 changed files with 73 additions and 39 deletions
|
@ -11,7 +11,7 @@ send a simple message and the server will log receipt of the message.
|
||||||
Below is the list of files used for this tutorial.
|
Below is the list of files used for this tutorial.
|
||||||
|
|
||||||
* scenario.xml - 3 node CORE xml scenario file (wireless)
|
* scenario.xml - 3 node CORE xml scenario file (wireless)
|
||||||
* scenario.py - 3 node CORE gRPC python script (wireless)
|
* scenario.py - 3 node CORE gRPC python script (wireless)
|
||||||
|
|
||||||
## Running with the XML Scenario File
|
## Running with the XML Scenario File
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ Below is the list of files used for this tutorial.
|
||||||
|
|
||||||
* movements1.txt - a NS2 mobility input file
|
* movements1.txt - a NS2 mobility input file
|
||||||
* scenario.xml - 3 node CORE xml scenario file (wireless)
|
* scenario.xml - 3 node CORE xml scenario file (wireless)
|
||||||
* scenario.py - 3 node CORE gRPC python script (wireless)
|
* scenario.py - 3 node CORE gRPC python script (wireless)
|
||||||
* printout.py - event listener
|
* printout.py - event listener
|
||||||
|
|
||||||
## Running with XML file using NS2 Movement
|
## Running with XML file using NS2 Movement
|
||||||
|
|
||||||
This section will cover running this sample tutorial using the XML scenario
|
This section will cover running this sample tutorial using the XML scenario
|
||||||
file, leveraging an NS2 file for mobility.
|
file, leveraging an NS2 file for mobility.
|
||||||
|
|
||||||
* Make sure the **core-daemon** is running a terminal
|
* Make sure the **core-daemon** is running a terminal
|
||||||
```shell
|
```shell
|
||||||
|
@ -67,7 +67,8 @@ This section will cover running this sample tutorial using the XML scenario
|
||||||
* You can now click play to start the session
|
* You can now click play to start the session
|
||||||
* Select the play button on the Mobility Player to start mobility
|
* Select the play button on the Mobility Player to start mobility
|
||||||
* Observe movement of the nodes
|
* Observe movement of the nodes
|
||||||
* Note that OSPF routing protocol is included in the scenario to build routing table so that routes to other nodes are known and when the routes are discovered, ping will work
|
* Note that OSPF routing protocol is included in the scenario to build routing table so that routes to other nodes are
|
||||||
|
known and when the routes are discovered, ping will work
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="/static/tutorial3/motion_from_ns2_file.png" width="80%" >
|
<img src="/static/tutorial3/motion_from_ns2_file.png" width="80%" >
|
||||||
|
|
|
@ -44,7 +44,8 @@ This section covers using the saved **scenario.xml** file to get and up and runn
|
||||||
```shell
|
```shell
|
||||||
ip route add 192.168.0.0/24 via 10.0.0.20
|
ip route add 192.168.0.0/24 via 10.0.0.20
|
||||||
```
|
```
|
||||||
* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface connected to the associated interface assigned to the RJ45 node
|
* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface
|
||||||
|
connected to the associated interface assigned to the RJ45 node
|
||||||
```shell
|
```shell
|
||||||
# if enp0s3 is ssigned 192.168.0.6/24
|
# if enp0s3 is ssigned 192.168.0.6/24
|
||||||
route add 10.0.0.0 mask 255.255.255.0 192.168.0.6
|
route add 10.0.0.0 mask 255.255.255.0 192.168.0.6
|
||||||
|
@ -119,7 +120,8 @@ This section covers leveraging the gRPC script to get up and running.
|
||||||
```shell
|
```shell
|
||||||
ip route add 192.168.0.0/24 via 10.0.0.20
|
ip route add 192.168.0.0/24 via 10.0.0.20
|
||||||
```
|
```
|
||||||
* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface connected to the associated interface assigned to the RJ45 node
|
* On the Windows host using Windows command prompt with administrator privilege, add a route that uses the interface
|
||||||
|
connected to the associated interface assigned to the RJ45 node
|
||||||
```shell
|
```shell
|
||||||
# if enp0s3 is ssigned 192.168.0.6/24
|
# if enp0s3 is ssigned 192.168.0.6/24
|
||||||
route add 10.0.0.0 mask 255.255.255.0 192.168.0.6
|
route add 10.0.0.0 mask 255.255.255.0 192.168.0.6
|
||||||
|
|
|
@ -21,12 +21,17 @@ class ChatClient:
|
||||||
def run(self):
|
def run(self):
|
||||||
server = socket.create_connection((self.address, self.port))
|
server = socket.create_connection((self.address, self.port))
|
||||||
sockname = server.getsockname()
|
sockname = server.getsockname()
|
||||||
print(f"connected to server({self.address}:{self.port}) as client({sockname[0]}:{sockname[1]})")
|
print(
|
||||||
|
f"connected to server({self.address}:{self.port}) as "
|
||||||
|
f"client({sockname[0]}:{sockname[1]})"
|
||||||
|
)
|
||||||
sockets = [sys.stdin, server]
|
sockets = [sys.stdin, server]
|
||||||
prompt()
|
prompt()
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
read_sockets, write_socket, error_socket = select.select(sockets, [], [])
|
read_sockets, write_socket, error_socket = select.select(
|
||||||
|
sockets, [], []
|
||||||
|
)
|
||||||
for sock in read_sockets:
|
for sock in read_sockets:
|
||||||
if sock == server:
|
if sock == server:
|
||||||
message = server.recv(READ_SIZE)
|
message = server.recv(READ_SIZE)
|
||||||
|
@ -53,7 +58,9 @@ def main():
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
)
|
)
|
||||||
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
||||||
parser.add_argument("-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT)
|
parser.add_argument(
|
||||||
|
"-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
client = ChatClient(args.address, args.port)
|
client = ChatClient(args.address, args.port)
|
||||||
client.run()
|
client.run()
|
||||||
|
|
|
@ -27,14 +27,17 @@ class ChatServer:
|
||||||
self.sockets.append(server)
|
self.sockets.append(server)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
read_sockets, write_sockets, error_sockets = select.select(self.sockets, [], [])
|
read_sockets, write_sockets, error_sockets = select.select(
|
||||||
|
self.sockets, [], []
|
||||||
|
)
|
||||||
for sock in read_sockets:
|
for sock in read_sockets:
|
||||||
if sock == server:
|
if sock == server:
|
||||||
client_sock, addr = server.accept()
|
client_sock, addr = server.accept()
|
||||||
self.sockets.append(client_sock)
|
self.sockets.append(client_sock)
|
||||||
name = f"{addr[0]}:{addr[1]}"
|
name = f"{addr[0]}:{addr[1]}"
|
||||||
print(f"[server] {name} joining")
|
print(f"[server] {name} joining")
|
||||||
self.broadcast({server, client_sock}, f"[server] {name} entered room\n")
|
self.broadcast({server, client_sock},
|
||||||
|
f"[server] {name} entered room\n")
|
||||||
else:
|
else:
|
||||||
peer = sock.getpeername()
|
peer = sock.getpeername()
|
||||||
name = f"{peer[0]}:{peer[1]}"
|
name = f"{peer[0]}:{peer[1]}"
|
||||||
|
@ -45,12 +48,14 @@ class ChatServer:
|
||||||
self.broadcast({server, sock}, f"[{name}] {data}\n")
|
self.broadcast({server, sock}, f"[{name}] {data}\n")
|
||||||
else:
|
else:
|
||||||
print(f"[server] {name} leaving")
|
print(f"[server] {name} leaving")
|
||||||
self.broadcast({server, sock}, f"[server] {name} leaving\n")
|
self.broadcast({server, sock},
|
||||||
|
f"[server] {name} leaving\n")
|
||||||
sock.close()
|
sock.close()
|
||||||
self.sockets.remove(sock)
|
self.sockets.remove(sock)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
print(f"[server] {name} leaving")
|
print(f"[server] {name} leaving")
|
||||||
self.broadcast({server, sock}, f"[server] {name} leaving\n")
|
self.broadcast({server, sock},
|
||||||
|
f"[server] {name} leaving\n")
|
||||||
sock.close()
|
sock.close()
|
||||||
self.sockets.remove(sock)
|
self.sockets.remove(sock)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@ -62,8 +67,12 @@ def main():
|
||||||
description="chat app server",
|
description="chat app server",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
)
|
)
|
||||||
parser.add_argument("-a", "--address", help="address to listen on", default=DEFAULT_ADDRESS)
|
parser.add_argument(
|
||||||
parser.add_argument("-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT)
|
"-a", "--address", help="address to listen on", default=DEFAULT_ADDRESS
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
server = ChatServer(args.address, args.port)
|
server = ChatServer(args.address, args.port)
|
||||||
server.run()
|
server.run()
|
||||||
|
|
|
@ -4,7 +4,8 @@ from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24",
|
||||||
|
ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
|
@ -15,7 +16,8 @@ def main():
|
||||||
|
|
||||||
# create nodes
|
# create nodes
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan = session.add_node(1, name="wlan1", _type=NodeType.WIRELESS_LAN, position=position)
|
wlan = session.add_node(1, name="wlan1", _type=NodeType.WIRELESS_LAN,
|
||||||
|
position=position)
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = session.add_node(2, name="n2", model="mdr", position=position)
|
node1 = session.add_node(2, name="n2", model="mdr", position=position)
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
|
|
|
@ -14,7 +14,7 @@ def main():
|
||||||
|
|
||||||
print("sessions=", sessions)
|
print("sessions=", sessions)
|
||||||
for i in range(300):
|
for i in range(300):
|
||||||
position = Position(x= 100, y = 100 + i)
|
position = Position(x=100, y=100 + i)
|
||||||
core.move_node(sessions[0].id, 2, position=position)
|
core.move_node(sessions[0].id, 2, position=position)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print("press enter to quit")
|
print("press enter to quit")
|
||||||
|
@ -23,10 +23,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,10 @@ from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(
|
||||||
|
ip4_prefix="10.0.0.0/24",
|
||||||
|
ip6_prefix="2001::/64",
|
||||||
|
)
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
|
@ -17,7 +20,12 @@ def main():
|
||||||
|
|
||||||
# create nodes
|
# create nodes
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan = session.add_node(3, name="wlan3", _type=NodeType.WIRELESS_LAN, position=position)
|
wlan = session.add_node(
|
||||||
|
3,
|
||||||
|
name="wlan3",
|
||||||
|
_type=NodeType.WIRELESS_LAN,
|
||||||
|
position=position,
|
||||||
|
)
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = session.add_node(1, name="n1", model="mdr", position=position)
|
node1 = session.add_node(1, name="n1", model="mdr", position=position)
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from core.emulator.coreemu import CoreEmu
|
from core.emulator.coreemu import CoreEmu
|
||||||
from core.emulator.data import IpPrefixes
|
from core.emulator.data import IpPrefixes
|
||||||
from core.emulator.enumerations import EventTypes
|
from core.emulator.enumerations import EventTypes
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from core.emulator.data import IpPrefixes, LinkOptions
|
from core.emulator.data import IpPrefixes, LinkOptions
|
||||||
from core.emulator.session import Session
|
from core.emulator.session import Session
|
||||||
from core.errors import CoreCommandError
|
from core.errors import CoreCommandError
|
||||||
|
|
|
@ -20,12 +20,17 @@ class ChatClient:
|
||||||
def run(self):
|
def run(self):
|
||||||
server = socket.create_connection((self.address, self.port))
|
server = socket.create_connection((self.address, self.port))
|
||||||
sockname = server.getsockname()
|
sockname = server.getsockname()
|
||||||
print(f"connected to server({self.address}:{self.port}) as client({sockname[0]}:{sockname[1]})")
|
print(
|
||||||
|
f"connected to server({self.address}:{self.port}) as "
|
||||||
|
f"client({sockname[0]}:{sockname[1]})"
|
||||||
|
)
|
||||||
sockets = [server]
|
sockets = [server]
|
||||||
prompt()
|
prompt()
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
read_sockets, write_socket, error_socket = select.select(sockets, [], [], 10)
|
read_sockets, write_socket, error_socket = select.select(
|
||||||
|
sockets, [], [], 10
|
||||||
|
)
|
||||||
for sock in read_sockets:
|
for sock in read_sockets:
|
||||||
if sock == server:
|
if sock == server:
|
||||||
message = server.recv(READ_SIZE)
|
message = server.recv(READ_SIZE)
|
||||||
|
@ -50,7 +55,8 @@ def main():
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
)
|
)
|
||||||
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
parser.add_argument("-a", "--address", help="address to listen on", required=True)
|
||||||
parser.add_argument("-p", "--port", type=int, help="port to listen on", default=DEFAULT_PORT)
|
parser.add_argument("-p", "--port", type=int, help="port to listen on",
|
||||||
|
default=DEFAULT_PORT)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
client = ChatClient(args.address, args.port)
|
client = ChatClient(args.address, args.port)
|
||||||
client.run()
|
client.run()
|
||||||
|
|
|
@ -5,12 +5,15 @@ from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if (len(sys.argv) != 2):
|
if len(sys.argv) != 2:
|
||||||
print("usage core-python scenario.py <interface-name>")
|
print("usage core-python scenario.py <interface-name>")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(
|
||||||
|
ip4_prefix="10.0.0.0/24",
|
||||||
|
ip6_prefix="2001::/64",
|
||||||
|
)
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
|
|
|
@ -19,14 +19,14 @@ def find_next_position(arr, start_row):
|
||||||
print(f"search_y={y}")
|
print(f"search_y={y}")
|
||||||
val = arr[x][y]
|
val = arr[x][y]
|
||||||
if (val == 0) or (val == 100):
|
if (val == 0) or (val == 100):
|
||||||
return x,y
|
return x, y
|
||||||
else:
|
else:
|
||||||
search_x = cols - (x - min_cols + 1)
|
search_x = cols - (x - min_cols + 1)
|
||||||
print(f"search_x={search_x}")
|
print(f"search_x={search_x}")
|
||||||
print(f"search_y={y}")
|
print(f"search_y={y}")
|
||||||
val = arr[search_x][y]
|
val = arr[search_x][y]
|
||||||
if val == 0:
|
if val == 0:
|
||||||
return search_x,y
|
return search_x, y
|
||||||
|
|
||||||
|
|
||||||
def move(current_x, current_y, to_x, to_y):
|
def move(current_x, current_y, to_x, to_y):
|
||||||
|
@ -49,7 +49,7 @@ def move(current_x, current_y, to_x, to_y):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
n = len(sys.argv)
|
n = len(sys.argv)
|
||||||
if (n < 3):
|
if n < 3:
|
||||||
print("Usage: core-python demo.py <node num> <total search nodes>")
|
print("Usage: core-python demo.py <node num> <total search nodes>")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ def main():
|
||||||
# get session
|
# get session
|
||||||
sessions = core.get_sessions()
|
sessions = core.get_sessions()
|
||||||
rows_per_zone = (499 - 25) / num_search_nodes
|
rows_per_zone = (499 - 25) / num_search_nodes
|
||||||
node_number = int(sys.argv[1])
|
node_number = int(sys.argv[1])
|
||||||
y_start = (node_number - 1) * int(rows_per_zone)
|
y_start = (node_number - 1) * int(rows_per_zone)
|
||||||
current_x = 25
|
current_x = 25
|
||||||
current_y = y_start
|
current_y = y_start
|
||||||
|
|
||||||
# max x and y
|
# max x and y
|
||||||
rows, cols = (470, 900)
|
rows, cols = (470, 900)
|
||||||
|
@ -78,20 +78,21 @@ def main():
|
||||||
arr[200][165] = 100
|
arr[200][165] = 100
|
||||||
print(arr, "after")
|
print(arr, "after")
|
||||||
|
|
||||||
|
position = None
|
||||||
while True:
|
while True:
|
||||||
val = arr[current_x][current_y]
|
val = arr[current_x][current_y]
|
||||||
# if position has target, stop
|
# if position has target, stop
|
||||||
if val == 100:
|
if val == 100:
|
||||||
print(f"found target, position={position}")
|
print(f"found target, position={position}")
|
||||||
else:
|
else:
|
||||||
#update one element for this starting position
|
# update one element for this starting position
|
||||||
arr[current_x][current_y] = 1
|
arr[current_x][current_y] = 1
|
||||||
# move
|
# move
|
||||||
to_x, to_y = find_next_position(arr, y_start)
|
to_x, to_y = find_next_position(arr, y_start)
|
||||||
print(f"next x={to_x}, next y={to_y}")
|
print(f"next x={to_x}, next y={to_y}")
|
||||||
x, y = move(current_x, current_y, to_x, to_y)
|
x, y = move(current_x, current_y, to_x, to_y)
|
||||||
# command the move
|
# command the move
|
||||||
position = Position(x , y)
|
position = Position(x, y)
|
||||||
print(f"move to position {position}")
|
print(f"move to position {position}")
|
||||||
core.move_node(sessions[0].id, node_number, position=position)
|
core.move_node(sessions[0].id, node_number, position=position)
|
||||||
current_x = x
|
current_x = x
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue