Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pim_dm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
pim_dm
Commits
aa6ee266
Commit
aa6ee266
authored
Sep 24, 2017
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change topology -> one more client connected to 2 routers
parent
d618be3f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
250 additions
and
17 deletions
+250
-17
emulation/client1/root/client.py
emulation/client1/root/client.py
+62
-0
emulation/client1/root/server.py
emulation/client1/root/server.py
+26
-13
emulation/client2.startup
emulation/client2.startup
+9
-0
emulation/client2/etc/resolv.conf
emulation/client2/etc/resolv.conf
+2
-0
emulation/client2/root/client.py
emulation/client2/root/client.py
+62
-0
emulation/client2/root/server.py
emulation/client2/root/server.py
+57
-0
emulation/lab.conf
emulation/lab.conf
+14
-3
emulation/lab.dep
emulation/lab.dep
+3
-1
emulation/switch1.startup
emulation/switch1.startup
+13
-0
emulation/switch1/etc/resolv.conf
emulation/switch1/etc/resolv.conf
+2
-0
topology.png
topology.png
+0
-0
No files found.
emulation/client1/root/client.py
0 → 100644
View file @
aa6ee266
import
socket
import
struct
import
sys
import
netifaces
def
chooseInterface
():
interfaces
=
netifaces
.
interfaces
()
def
printInterfaces
():
print
(
'Indique a interface de captura:'
)
for
i
in
range
(
len
(
interfaces
)):
print
(
i
+
1
,
'-'
,
interfaces
[
i
])
if
len
(
interfaces
)
==
1
:
#user has just 1 interface and any
return
interfaces
[
0
]
else
:
printInterfaces
()
inputValue
=
input
(
'Numero da interface: '
)
if
int
(
inputValue
)
-
1
not
in
range
(
len
(
interfaces
)):
raise
Exception
(
'numero de interface invalida'
)
inputValue
=
interfaces
[
int
(
inputValue
)
-
1
]
return
inputValue
if
not
hasattr
(
socket
,
'SO_BINDTODEVICE'
):
socket
.
SO_BINDTODEVICE
=
25
multicast_group
=
'224.12.12.12'
server_address
=
(
''
,
10000
)
# Create the socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# Bind to the server address
sock
.
bind
(
server_address
)
#interface_name = input("interface name: ")
interface_name
=
chooseInterface
()
ip_interface
=
netifaces
.
ifaddresses
(
interface_name
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
# Tell the operating system to add the socket to the multicast group
# on all interfaces.
group
=
socket
.
inet_aton
(
multicast_group
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_ADD_MEMBERSHIP
,
socket
.
inet_aton
(
multicast_group
)
+
socket
.
inet_aton
(
ip_interface
))
#sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, str(interface_name + "\0").encode('utf-8'))
# Receive/respond loop
while
True
:
#print >>sys.stderr, '\nwaiting to receive message'
data
,
address
=
sock
.
recvfrom
(
10240
)
print
(
data
.
decode
(
"utf-8"
))
#print >>sys.stderr, 'received %s bytes from %s' % (len(data), address)
#print >>sys.stderr, data
#print >>sys.stderr, 'sending acknowledgement to', address
#sock.sendto('ack', address)
emulation/client1/root/server.py
View file @
aa6ee266
import
socket
import
struct
import
sys
#import trac
import
netifaces
import
traceback
def
chooseInterface
():
interfaces
=
netifaces
.
interfaces
()
def
printInterfaces
():
print
(
'Indique a interface de captura:'
)
for
i
in
range
(
len
(
interfaces
)):
print
(
i
+
1
,
'-'
,
interfaces
[
i
])
if
len
(
interfaces
)
==
1
:
#user has just 1 interface and any
return
interfaces
[
0
]
else
:
printInterfaces
()
inputValue
=
input
(
'Numero da interface: '
)
if
int
(
inputValue
)
-
1
not
in
range
(
len
(
interfaces
)):
raise
Exception
(
'numero de interface invalida'
)
inputValue
=
interfaces
[
int
(
inputValue
)
-
1
]
return
inputValue
#message = 'very important data'
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# Set a timeout so the socket does not block indefinitely when trying
# to receive data.
#sock.settimeout(0.2)
# Set the time-to-live for messages to 1 so they do not go past the
# local network segment.
ttl
=
struct
.
pack
(
'b'
,
12
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_MULTICAST_TTL
,
ttl
)
try
:
# Send data to the multicast group
#print >>sys.stderr, 'sending "%s"' % message
#sent = sock.sendto(message, multicast_group)
interface_name
=
chooseInterface
()
ip_interface
=
netifaces
.
ifaddresses
(
interface_name
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
sock
.
bind
((
ip_interface
,
10000
))
try
:
# Look for responses from all recipients
while
True
:
#print >>sys.stderr, 'waiting to receive'
input_msg
=
input
(
'msg --> '
)
try
:
#message = struct.pack("s", input_msg.encode('utf-8'))
msg
=
bytes
(
input_msg
,
"utf-8"
)
sock
.
sendto
(
msg
,
multicast_group
)
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
...
...
emulation/client2.startup
0 → 100644
View file @
aa6ee266
ip addr add dev eth0 10.0.2.10/24
ip link set dev eth0 up
#default route para obter conectividade internet
ip route add 0.0.0.0/0 via 10.0.2.3
# install python
apt-get update && apt-get --assume-yes install python3 python3-pip
emulation/client2/etc/resolv.conf
0 → 100644
View file @
aa6ee266
nameserver
8
.
8
.
8
.
8
nameserver
8
.
8
.
4
.
4
emulation/client2/root/client.py
0 → 100644
View file @
aa6ee266
import
socket
import
struct
import
sys
import
netifaces
def
chooseInterface
():
interfaces
=
netifaces
.
interfaces
()
def
printInterfaces
():
print
(
'Indique a interface de captura:'
)
for
i
in
range
(
len
(
interfaces
)):
print
(
i
+
1
,
'-'
,
interfaces
[
i
])
if
len
(
interfaces
)
==
1
:
#user has just 1 interface and any
return
interfaces
[
0
]
else
:
printInterfaces
()
inputValue
=
input
(
'Numero da interface: '
)
if
int
(
inputValue
)
-
1
not
in
range
(
len
(
interfaces
)):
raise
Exception
(
'numero de interface invalida'
)
inputValue
=
interfaces
[
int
(
inputValue
)
-
1
]
return
inputValue
if
not
hasattr
(
socket
,
'SO_BINDTODEVICE'
):
socket
.
SO_BINDTODEVICE
=
25
multicast_group
=
'224.12.12.12'
server_address
=
(
''
,
10000
)
# Create the socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# Bind to the server address
sock
.
bind
(
server_address
)
#interface_name = input("interface name: ")
interface_name
=
chooseInterface
()
ip_interface
=
netifaces
.
ifaddresses
(
interface_name
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
# Tell the operating system to add the socket to the multicast group
# on all interfaces.
group
=
socket
.
inet_aton
(
multicast_group
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_ADD_MEMBERSHIP
,
socket
.
inet_aton
(
multicast_group
)
+
socket
.
inet_aton
(
ip_interface
))
#sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, str(interface_name + "\0").encode('utf-8'))
# Receive/respond loop
while
True
:
#print >>sys.stderr, '\nwaiting to receive message'
data
,
address
=
sock
.
recvfrom
(
10240
)
print
(
data
.
decode
(
"utf-8"
))
#print >>sys.stderr, 'received %s bytes from %s' % (len(data), address)
#print >>sys.stderr, data
#print >>sys.stderr, 'sending acknowledgement to', address
#sock.sendto('ack', address)
emulation/client
1/root/multicast_client
.py
→
emulation/client
2/root/server
.py
View file @
aa6ee266
import
socket
import
struct
import
sys
import
netifaces
import
traceback
message
=
'very important data'
multicast_group
=
(
'224.3.29.71'
,
10000
)
def
chooseInterface
():
interfaces
=
netifaces
.
interfaces
()
def
printInterfaces
():
print
(
'Indique a interface de captura:'
)
for
i
in
range
(
len
(
interfaces
)):
print
(
i
+
1
,
'-'
,
interfaces
[
i
])
if
len
(
interfaces
)
==
1
:
#user has just 1 interface and any
return
interfaces
[
0
]
else
:
printInterfaces
()
inputValue
=
input
(
'Numero da interface: '
)
if
int
(
inputValue
)
-
1
not
in
range
(
len
(
interfaces
)):
raise
Exception
(
'numero de interface invalida'
)
inputValue
=
interfaces
[
int
(
inputValue
)
-
1
]
return
inputValue
#message = 'very important data'
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# Set a timeout so the socket does not block indefinitely when trying
# to receive data.
sock
.
settimeout
(
10
)
# Set the time-to-live for messages to 1 so they do not go past the
# local network segment.
ttl
=
struct
.
pack
(
'b'
,
12
)
sock
.
setsockopt
(
socket
.
IPPROTO_IP
,
socket
.
IP_MULTICAST_TTL
,
ttl
)
try
:
# Send data to the multicast group
#print >>sys.stderr, 'sending "%s"' % message
print
(
'sending "%s"'
%
message
)
sent
=
sock
.
sendto
(
str
.
encode
(
message
),
multicast_group
)
interface_name
=
chooseInterface
()
ip_interface
=
netifaces
.
ifaddresses
(
interface_name
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
sock
.
bind
((
ip_interface
,
10000
))
try
:
# Look for responses from all recipients
while
True
:
#print >>sys.stderr, 'waiting to receive'
print
(
'waiting to receive'
)
input_msg
=
input
(
'msg --> '
)
try
:
data
,
server
=
sock
.
recvfrom
(
16
)
except
socket
.
timeout
:
#print >>sys.stderr, 'timed out, no more responses'
print
(
'timed out, no more responses'
)
break
else
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
continue
#print >>sys.stderr, 'received "%s" from %s' % (data, server)
print
(
'received "%s" from %s'
%
(
data
,
server
))
finally
:
#print >>sys.stderr, 'closing socket'
print
(
'closing socket'
)
sock
.
close
()
emulation/lab.conf
View file @
aa6ee266
...
...
@@ -8,16 +8,27 @@ router1[mem]=256
router2
[
0
]=
A
router2
[
1
]=
C
router2
[
2
]=
D
router2
[
2
]=
F
router2
[
mem
]=
256
router3
[
0
]=
B
router3
[
1
]=
C
router3
[
1
]=
D
router3
[
mem
]=
256
#########################################
# Switch setup
#########################################
switch1
[
0
]=
C
switch1
[
1
]=
D
switch1
[
2
]=
E
#########################################
# Client setup
#########################################
client1
[
0
]=
D
client1
[
0
]=
F
client1
[
mem
]=
256
client2
[
0
]=
E
client2
[
mem
]=
256
emulation/lab.dep
View file @
aa6ee266
router2: router1
router2: router1
switch1
router3: router1
client1: router2
client2: switch1 router2 router3
emulation/switch1.startup
0 → 100644
View file @
aa6ee266
ip link set dev eth0 up
ip link set dev eth1 up
ip link set dev eth2 up
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
brctl addif br0 eth2
ip link set dev br0 up
# identify ports with routers (they need to receive all multicast traffic!)
echo "2" > /sys/devices/virtual/net/br0/brif/eth0/multicast_router
echo "2" > /sys/devices/virtual/net/br0/brif/eth1/multicast_router
emulation/switch1/etc/resolv.conf
0 → 100644
View file @
aa6ee266
nameserver
8
.
8
.
8
.
8
nameserver
8
.
8
.
4
.
4
topology.png
View replaced file @
d618be3f
View file @
aa6ee266
27.3 KB
|
W:
|
H:
31.7 KB
|
W:
|
H:
2-up
Swipe
Onion skin
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment