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
6cbbc7ef
Commit
6cbbc7ef
authored
Jul 27, 2017
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor improvements - len(pkt)
parent
f3d3c0ef
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
49 additions
and
13 deletions
+49
-13
Hello.py
Hello.py
+0
-4
Packet/PacketIpHeader.py
Packet/PacketIpHeader.py
+3
-0
Packet/PacketPimEncodedGroupAddress.py
Packet/PacketPimEncodedGroupAddress.py
+9
-0
Packet/PacketPimEncodedSourceAddress.py
Packet/PacketPimEncodedSourceAddress.py
+9
-0
Packet/PacketPimEncodedUnicastAddress.py
Packet/PacketPimEncodedUnicastAddress.py
+9
-0
Packet/PacketPimHeader.py
Packet/PacketPimHeader.py
+3
-1
Packet/PacketPimHello.py
Packet/PacketPimHello.py
+3
-0
Packet/PacketPimJoinPrune.py
Packet/PacketPimJoinPrune.py
+2
-2
Packet/PacketPimJoinPruneMulticastGroup.py
Packet/PacketPimJoinPruneMulticastGroup.py
+6
-3
Packet/ReceivedPacket.py
Packet/ReceivedPacket.py
+5
-3
No files found.
Hello.py
View file @
6cbbc7ef
...
...
@@ -41,7 +41,6 @@ class Hello:
hello_timer
=
random
.
uniform
(
0
,
Hello
.
TRIGGERED_HELLO_DELAY
)
Timer
(
hello_timer
,
self
.
packet_send_handle
,
args
=
[
interface
]).
start
()
# TODO: ver melhor este metodo
def
force_send_remove
(
self
,
interface
:
Interface
):
pim_payload
=
PacketPimHello
()
pim_payload
.
add_option
(
1
,
HELLO_HOLD_TIME_TIMEOUT
)
...
...
@@ -52,9 +51,6 @@ class Hello:
# receive handler
def
receive_handle
(
self
,
packet
:
ReceivedPacket
):
if
packet
.
ip_header
is
None
:
return
# TODO: MAYBE EXCEPCAO??
ip
=
packet
.
ip_header
.
ip_src
print
(
"ip = "
,
ip
)
options
=
packet
.
pim_header
.
payload
.
get_options
()
...
...
Packet/PacketIpHeader.py
View file @
6cbbc7ef
...
...
@@ -32,6 +32,9 @@ class PacketIpHeader:
self
.
ip_src
=
ip_src
self
.
ip_dst
=
ip_dst
def
__len__
(
self
):
return
self
.
hdr_length
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
(
verhlen
,
tos
,
iplen
,
ipid
,
frag
,
ttl
,
proto
,
cksum
,
src
,
dst
)
=
\
...
...
Packet/PacketPimEncodedGroupAddress.py
View file @
6cbbc7ef
...
...
@@ -57,6 +57,15 @@ class PacketPimEncodedGroupAddress:
else
:
raise
Exception
def
__len__
(
self
):
version
=
ipaddress
.
ip_address
(
self
.
group_address
).
version
if
version
==
4
:
return
self
.
PIM_ENCODED_GROUP_ADDRESS_HDR_LEN
elif
version
==
6
:
return
self
.
PIM_ENCODED_GROUP_ADDRESS_HDR_LEN_IPv6
else
:
raise
Exception
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
data_without_group_addr
=
data
[
0
:
PacketPimEncodedGroupAddress
.
PIM_ENCODED_GROUP_ADDRESS_HDR_WITHOUT_GROUP_ADDRESS_LEN
]
...
...
Packet/PacketPimEncodedSourceAddress.py
View file @
6cbbc7ef
...
...
@@ -59,6 +59,15 @@ class PacketPimEncodedSourceAddress:
else
:
raise
Exception
def
__len__
(
self
):
version
=
ipaddress
.
ip_address
(
self
.
source_address
).
version
if
version
==
4
:
return
self
.
PIM_ENCODED_SOURCE_ADDRESS_HDR_LEN
elif
version
==
6
:
return
self
.
PIM_ENCODED_SOURCE_ADDRESS_HDR_LEN_IPV6
else
:
raise
Exception
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
data_without_source_addr
=
data
[
0
:
PacketPimEncodedSourceAddress
.
PIM_ENCODED_SOURCE_ADDRESS_HDR_WITHOUT_SOURCE_ADDRESS_LEN
]
...
...
Packet/PacketPimEncodedUnicastAddress.py
View file @
6cbbc7ef
...
...
@@ -48,6 +48,15 @@ class PacketPimEncodedUnicastAddress:
else
:
raise
Exception
def
__len__
(
self
):
version
=
ipaddress
.
ip_address
(
self
.
unicast_address
).
version
if
version
==
4
:
return
self
.
PIM_ENCODED_UNICAST_ADDRESS_HDR_LEN
elif
version
==
6
:
return
self
.
PIM_ENCODED_UNICAST_ADDRESS_HDR_LEN_IPV6
else
:
raise
Exception
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
data_without_unicast_addr
=
data
[
0
:
PacketPimEncodedUnicastAddress
.
PIM_ENCODED_UNICAST_ADDRESS_HDR_WITHOUT_UNICAST_ADDRESS_LEN
]
...
...
Packet/PacketPimHeader.py
View file @
6cbbc7ef
...
...
@@ -33,9 +33,11 @@ class PacketPimHeader:
msg
=
msg_without_chcksum
[
0
:
2
]
+
struct
.
pack
(
"! H"
,
pim_checksum
)
+
msg_without_chcksum
[
4
:]
return
msg
def
__len__
(
self
):
return
len
(
self
.
bytes
())
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
# print("parsePimHdr: ", msg.encode("hex"))
print
(
"parsePimHdr: "
,
data
)
pim_hdr
=
data
[
0
:
PacketPimHeader
.
PIM_HDR_LEN
]
...
...
Packet/PacketPimHello.py
View file @
6cbbc7ef
...
...
@@ -48,6 +48,9 @@ class PacketPimHello:
res
+=
type_length_hdr
+
struct
.
pack
(
"! "
+
str
(
option_length
)
+
"s"
,
option_value
.
to_bytes
(
option_length
,
byteorder
=
'big'
))
return
res
def
__len__
(
self
):
return
len
(
self
.
bytes
())
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
pim_payload
=
PacketPimHello
()
...
...
Packet/PacketPimJoinPrune.py
View file @
6cbbc7ef
...
...
@@ -49,7 +49,7 @@ class PacketPimJoinPrune:
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
upstream_neighbor_addr_obj
=
PacketPimEncodedUnicastAddress
.
parse_bytes
(
data
)
upstream_neighbor_addr_len
=
len
(
upstream_neighbor_addr_obj
.
bytes
()
)
upstream_neighbor_addr_len
=
len
(
upstream_neighbor_addr_obj
)
data
=
data
[
upstream_neighbor_addr_len
:]
(
_
,
num_groups
,
hold_time
)
=
struct
.
unpack
(
PacketPimJoinPrune
.
PIM_HDR_JOIN_PRUNE_WITHOUT_ADDRESS
,
data
[:
PacketPimJoinPrune
.
PIM_HDR_JOIN_PRUNE_WITHOUT_ADDRESS_LEN
])
...
...
@@ -58,7 +58,7 @@ class PacketPimJoinPrune:
for
i
in
range
(
0
,
num_groups
):
group
=
PacketPimJoinPruneMulticastGroup
.
parse_bytes
(
data
)
group_len
=
len
(
group
.
bytes
()
)
group_len
=
len
(
group
)
pim_payload
.
add_multicast_group
(
group
)
data
=
data
[
group_len
:]
...
...
Packet/PacketPimJoinPruneMulticastGroup.py
View file @
6cbbc7ef
...
...
@@ -72,10 +72,13 @@ class PacketPimJoinPruneMulticastGroup:
msg
+=
pruned_src_address_bytes
return
msg
def
__len__
(
self
):
return
len
(
self
.
bytes
())
@
staticmethod
def
parse_bytes
(
data
:
bytes
):
multicast_group_addr_obj
=
PacketPimEncodedGroupAddress
.
parse_bytes
(
data
)
multicast_group_addr_len
=
len
(
multicast_group_addr_obj
.
bytes
()
)
multicast_group_addr_len
=
len
(
multicast_group_addr_obj
)
data
=
data
[
multicast_group_addr_len
:]
number_join_prune_data
=
data
[:
PacketPimJoinPruneMulticastGroup
.
PIM_HDR_JOIN_PRUNE_MULTICAST_GROUP_WITHOUT_GROUP_ADDRESS_LEN
]
...
...
@@ -86,13 +89,13 @@ class PacketPimJoinPruneMulticastGroup:
data
=
data
[
PacketPimJoinPruneMulticastGroup
.
PIM_HDR_JOIN_PRUNE_MULTICAST_GROUP_WITHOUT_GROUP_ADDRESS_LEN
:]
for
i
in
range
(
0
,
number_joined_sources
):
joined_obj
=
PacketPimEncodedSourceAddress
.
parse_bytes
(
data
)
joined_obj_len
=
len
(
joined_obj
.
bytes
()
)
joined_obj_len
=
len
(
joined_obj
)
data
=
data
[
joined_obj_len
:]
joined
.
append
(
joined_obj
.
source_address
)
for
i
in
range
(
0
,
number_pruned_sources
):
pruned_obj
=
PacketPimEncodedSourceAddress
.
parse_bytes
(
data
)
pruned_obj_len
=
len
(
pruned_obj
.
bytes
()
)
pruned_obj_len
=
len
(
pruned_obj
)
data
=
data
[
pruned_obj_len
:]
pruned
.
append
(
pruned_obj
.
source_address
)
...
...
Packet/ReceivedPacket.py
View file @
6cbbc7ef
...
...
@@ -15,7 +15,9 @@ class ReceivedPacket(Packet):
# Parse ao packet e preencher objeto Packet
packet_ip_hdr
=
raw_packet
[:
PacketIpHeader
.
IP_HDR_LEN
]
self
.
ip_header
=
PacketIpHeader
.
parse_bytes
(
packet_ip_hdr
)
ip_header
=
PacketIpHeader
.
parse_bytes
(
packet_ip_hdr
)
packet_without_ip_hdr
=
raw_packet
[
self
.
ip_header
.
hdr_length
:]
self
.
pim_header
=
PacketPimHeader
.
parse_bytes
(
packet_without_ip_hdr
)
packet_without_ip_hdr
=
raw_packet
[
ip_header
.
hdr_length
:]
pim_header
=
PacketPimHeader
.
parse_bytes
(
packet_without_ip_hdr
)
super
().
__init__
(
ip_header
=
ip_header
,
pim_header
=
pim_header
)
\ No newline at end of file
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