docs: updated formatting on tutorial files

This commit is contained in:
Blake Harnden 2023-06-08 14:43:02 -07:00
parent 81230edac3
commit cbc35b74f8
13 changed files with 73 additions and 39 deletions

View file

@ -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.
* 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

View file

@ -11,13 +11,13 @@ Below is the list of files used for this tutorial.
* movements1.txt - a NS2 mobility input file
* 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
## Running with XML file using NS2 Movement
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
```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
* Select the play button on the Mobility Player to start mobility
* 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">
<img src="/static/tutorial3/motion_from_ns2_file.png" width="80%" >

View file

@ -44,7 +44,8 @@ This section covers using the saved **scenario.xml** file to get and up and runn
```shell
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
# if enp0s3 is ssigned 192.168.0.6/24
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
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
# if enp0s3 is ssigned 192.168.0.6/24
route add 10.0.0.0 mask 255.255.255.0 192.168.0.6

View file

@ -21,12 +21,17 @@ class ChatClient:
def run(self):
server = socket.create_connection((self.address, self.port))
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]
prompt()
try:
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:
if sock == server:
message = server.recv(READ_SIZE)
@ -53,7 +58,9 @@ def main():
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
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()
client = ChatClient(args.address, args.port)
client.run()

View file

@ -27,14 +27,17 @@ class ChatServer:
self.sockets.append(server)
try:
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:
if sock == server:
client_sock, addr = server.accept()
self.sockets.append(client_sock)
name = f"{addr[0]}:{addr[1]}"
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:
peer = sock.getpeername()
name = f"{peer[0]}:{peer[1]}"
@ -45,12 +48,14 @@ class ChatServer:
self.broadcast({server, sock}, f"[{name}] {data}\n")
else:
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()
self.sockets.remove(sock)
except socket.error:
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()
self.sockets.remove(sock)
except KeyboardInterrupt:
@ -62,8 +67,12 @@ def main():
description="chat app server",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("-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)
parser.add_argument(
"-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()
server = ChatServer(args.address, args.port)
server.run()

View file

@ -4,7 +4,8 @@ from core.api.grpc.wrappers import NodeType, Position
def main():
# 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
core = client.CoreGrpcClient()
@ -15,7 +16,8 @@ def main():
# create nodes
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)
node1 = session.add_node(2, name="n2", model="mdr", position=position)
position = Position(x=300, y=100)

View file

@ -14,7 +14,7 @@ def main():
print("sessions=", sessions)
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)
time.sleep(1)
print("press enter to quit")
@ -23,10 +23,3 @@ def main():
if __name__ == "__main__":
main()

View file

@ -6,7 +6,10 @@ from core.api.grpc.wrappers import NodeType, Position
def main():
# 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
core = client.CoreGrpcClient()
@ -17,7 +20,12 @@ def main():
# create nodes
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)
node1 = session.add_node(1, name="n1", model="mdr", position=position)
position = Position(x=300, y=100)

View file

@ -1,4 +1,5 @@
import pytest
from core.emulator.coreemu import CoreEmu
from core.emulator.data import IpPrefixes
from core.emulator.enumerations import EventTypes

View file

@ -1,4 +1,5 @@
import pytest
from core.emulator.data import IpPrefixes, LinkOptions
from core.emulator.session import Session
from core.errors import CoreCommandError

View file

@ -20,12 +20,17 @@ class ChatClient:
def run(self):
server = socket.create_connection((self.address, self.port))
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]
prompt()
try:
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:
if sock == server:
message = server.recv(READ_SIZE)
@ -50,7 +55,8 @@ def main():
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
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()
client = ChatClient(args.address, args.port)
client.run()

View file

@ -5,12 +5,15 @@ from core.api.grpc.wrappers import NodeType, Position
def main():
if (len(sys.argv) != 2):
if len(sys.argv) != 2:
print("usage core-python scenario.py <interface-name>")
exit()
# 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
core = client.CoreGrpcClient()

View file

@ -19,14 +19,14 @@ def find_next_position(arr, start_row):
print(f"search_y={y}")
val = arr[x][y]
if (val == 0) or (val == 100):
return x,y
return x, y
else:
search_x = cols - (x - min_cols + 1)
print(f"search_x={search_x}")
print(f"search_y={y}")
val = arr[search_x][y]
if val == 0:
return search_x,y
return search_x, 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():
n = len(sys.argv)
if (n < 3):
if n < 3:
print("Usage: core-python demo.py <node num> <total search nodes>")
exit()
@ -63,10 +63,10 @@ def main():
# get session
sessions = core.get_sessions()
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)
current_x = 25
current_y = y_start
current_y = y_start
# max x and y
rows, cols = (470, 900)
@ -78,20 +78,21 @@ def main():
arr[200][165] = 100
print(arr, "after")
position = None
while True:
val = arr[current_x][current_y]
# if position has target, stop
if val == 100:
print(f"found target, position={position}")
else:
#update one element for this starting position
# update one element for this starting position
arr[current_x][current_y] = 1
# move
to_x, to_y = find_next_position(arr, y_start)
print(f"next x={to_x}, next y={to_y}")
x, y = move(current_x, current_y, to_x, to_y)
# command the move
position = Position(x , y)
position = Position(x, y)
print(f"move to position {position}")
core.move_node(sessions[0].id, node_number, position=position)
current_x = x