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

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

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

@ -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()
@ -78,6 +78,7 @@ def main():
arr[200][165] = 100
print(arr, "after")
position = None
while True:
val = arr[current_x][current_y]
# if position has target, stop