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
f5fb3c58
Commit
f5fb3c58
authored
Feb 17, 2018
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scripts for tests
parent
c04581c3
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
633 additions
and
35 deletions
+633
-35
emulation/client0/root/client.py
emulation/client0/root/client.py
+75
-0
emulation/client0/root/script.sh
emulation/client0/root/script.sh
+2
-6
emulation/client0/root/server.py
emulation/client0/root/server.py
+67
-0
emulation/client1/root/client.py
emulation/client1/root/client.py
+75
-0
emulation/client1/root/script.sh
emulation/client1/root/script.sh
+2
-6
emulation/client1/root/server.py
emulation/client1/root/server.py
+67
-0
emulation/client2/root/client.py
emulation/client2/root/client.py
+75
-0
emulation/client2/root/script.sh
emulation/client2/root/script.sh
+5
-5
emulation/client2/root/server.py
emulation/client2/root/server.py
+67
-0
emulation/router1/root/script.sh
emulation/router1/root/script.sh
+12
-1
emulation/router2/root/script.sh
emulation/router2/root/script.sh
+8
-1
emulation/router3/root/script.sh
emulation/router3/root/script.sh
+9
-1
emulation/router4/root/script.sh
emulation/router4/root/script.sh
+8
-1
emulation/router5/root/script.sh
emulation/router5/root/script.sh
+8
-1
emulation/router6/root/script.sh
emulation/router6/root/script.sh
+8
-1
emulation/source/root/client.py
emulation/source/root/client.py
+75
-0
emulation/source/root/script.sh
emulation/source/root/script.sh
+2
-6
emulation/source/root/server.py
emulation/source/root/server.py
+67
-0
emulation/switch1/root/script.sh
emulation/switch1/root/script.sh
+1
-6
No files found.
emulation/client0/root/client.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
signal
import
sys
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
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
is_running
:
#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/client0/root/script.sh
View file @
f5fb3c58
rm
-rf
test
/
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/ netifaces
cp
-rf
/hosthome/PycharmProjects/RPC/
test
/
python3 client.py
cd test
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Client.py
emulation/client0/root/server.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
traceback
import
signal
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# 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
)
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
is_running
:
input_msg
=
input
(
'msg --> '
)
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
continue
#print >>sys.stderr, 'received "%s" from %s' % (data, server)
finally
:
#print >>sys.stderr, 'closing socket'
sock
.
close
()
emulation/client1/root/client.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
signal
import
sys
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
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
is_running
:
#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/script.sh
View file @
f5fb3c58
rm
-rf
test
/
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/ netifaces
cp
-rf
/hosthome/PycharmProjects/RPC/
test
/
python3 client.py
cd test
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Client.py
emulation/client1/root/server.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
traceback
import
signal
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# 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
)
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
is_running
:
input_msg
=
input
(
'msg --> '
)
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
continue
#print >>sys.stderr, 'received "%s" from %s' % (data, server)
finally
:
#print >>sys.stderr, 'closing socket'
sock
.
close
()
emulation/client2/root/client.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
signal
import
sys
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
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
is_running
:
#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/client2/root/script.sh
View file @
f5fb3c58
rm
-rf
test
/
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/ netifaces
cp
-rf
/hosthome/PycharmProjects/RPC/
test
/
cd test
cp
/hosthome/PycharmProjects/Test/ServerLog.py
.
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
cp
/hosthome/PycharmProjects/Test/TestAssert.py
.
python3 ServerLog.py
python3 Client.py
emulation/client2/root/server.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
traceback
import
signal
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# 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
)
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
is_running
:
input_msg
=
input
(
'msg --> '
)
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
continue
#print >>sys.stderr, 'received "%s" from %s' % (data, server)
finally
:
#print >>sys.stderr, 'closing socket'
sock
.
close
()
emulation/router1/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,15 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,15 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R1 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-aiigmp
eth2
python3 Run.py
-aiigmp
eth3
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-ai
eth2
python3 Run.py
-ai
eth3
python3 Run.py
-v
emulation/router2/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R2 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-v
emulation/router3/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,12 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,12 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R3 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-v
emulation/router4/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R4 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-v
emulation/router5/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R5 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-v
emulation/router6/root/script.sh
View file @
f5fb3c58
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
...
@@ -3,4 +3,11 @@ cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd
MulticastRouting
cd
MulticastRouting
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Server.py
python3 Run.py
-stop
python3 Run.py
-start
python3 Run.py
-t
R6 10.5.5.100
python3 Run.py
-aiigmp
eth0
python3 Run.py
-aiigmp
eth1
python3 Run.py
-ai
eth0
python3 Run.py
-ai
eth1
python3 Run.py
-v
emulation/source/root/client.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
signal
import
sys
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
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
is_running
:
#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/source/root/script.sh
View file @
f5fb3c58
rm
-rf
test
/
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/ netifaces
cp
-rf
/hosthome/PycharmProjects/RPC/
test
/
python3 server.py
cd test
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Client.py
emulation/source/root/server.py
0 → 100644
View file @
f5fb3c58
import
socket
import
struct
import
sys
import
netifaces
import
traceback
import
signal
is_running
=
True
sock
=
None
def
exit
(
signal
,
frame
):
is_running
=
False
sock
.
close
()
sys
.
exit
(
0
)
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
signal
.
signal
(
signal
.
SIGINT
,
exit
)
signal
.
signal
(
signal
.
SIGTERM
,
exit
)
multicast_group
=
(
'224.12.12.12'
,
10000
)
# Create the datagram socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
# 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
)
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
is_running
:
input_msg
=
input
(
'msg --> '
)
try
:
sock
.
sendto
(
input_msg
.
encode
(
"utf-8"
),
multicast_group
)
except
:
traceback
.
print_exc
()
continue
#print >>sys.stderr, 'received "%s" from %s' % (data, server)
finally
:
#print >>sys.stderr, 'closing socket'
sock
.
close
()
emulation/switch1/root/script.sh
View file @
f5fb3c58
rm
-rf
test
/
tcpdump
-i
any
-w
/hosthome/Desktop/assert_capture.pcap
cp
-rf
/hosthome/PycharmProjects/RPC/
test
/
cd test
pip-3.2
install
--index-url
=
https://pypi.python.org/simple/
-r
requirements.txt
python3 Client.py
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