mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-01-30 04:52:03 +01:00
packet lib: add data serialize support to Packet class
This enables you to send data with Packet class. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
4e887d03c8
commit
3fdb2dabec
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from . import packet_base
|
||||
from . import ethernet
|
||||
|
||||
|
||||
@ -37,11 +38,14 @@ class Packet(object):
|
||||
self.data = bytearray()
|
||||
r = self.protocols[::-1]
|
||||
for i, p in enumerate(r):
|
||||
if i == len(r) - 1:
|
||||
prev = None
|
||||
if p.__class__.__bases__[0] == packet_base.PacketBase:
|
||||
if i == len(r) - 1:
|
||||
prev = None
|
||||
else:
|
||||
prev = r[i + 1]
|
||||
data = p.serialize(self.data, prev)
|
||||
else:
|
||||
prev = r[i + 1]
|
||||
data = p.serialize(self.data, prev)
|
||||
data = str(p)
|
||||
self.data = data + self.data
|
||||
|
||||
def add_protocol(self, proto):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user