Remove "nose" library
The library "nose", used for unit testing, is removed. This library is in maintenance mode and is not compatible with Python3.10 [1]. Now all checks are implemented using "unittest". The methods are not loaded in realtime into the test case execution; instead of this, this patch uses "testscenarios.WithScenarios", that allows to execute the same test with different defined scenarios. NOTE: "BgpSpeakerTestBase" tests are disable temporarily. It is needed to configure "docker" in the system in order to execute them. [1]https://nose.readthedocs.io/en/latest/ Story: #2010063 Task: #45519 Change-Id: I92e9547a26e9bec6c2a9a011c49a70b82dbb373e
This commit is contained in:
parent
90328068b8
commit
2495ebdff9
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,7 +24,6 @@ cover/
|
|||||||
.coverage*
|
.coverage*
|
||||||
!.coveragerc
|
!.coveragerc
|
||||||
.tox
|
.tox
|
||||||
nosetests.xml
|
|
||||||
.testrepository
|
.testrepository
|
||||||
.stestr
|
.stestr
|
||||||
.venv
|
.venv
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright 2010-2011 OpenStack Foundation
|
|
||||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
|
|
||||||
class TestCase(base.BaseTestCase):
|
|
||||||
|
|
||||||
"""Test case base class for all unit tests."""
|
|
@ -32,42 +32,45 @@ class BgpSpeakerTestBase(unittest.TestCase):
|
|||||||
bridges = []
|
bridges = []
|
||||||
checktime = 120
|
checktime = 120
|
||||||
|
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(cls):
|
self.skipTest('These tests require to have "docker" configured in the '
|
||||||
cls.brdc1 = ctn_base.Bridge(name='brdc1',
|
'system. Regardless of if we move them to functional or '
|
||||||
|
'fix them, now we need to disable them.')
|
||||||
|
self.brdc1 = ctn_base.Bridge(name='brdc1',
|
||||||
subnet='192.168.10.0/24')
|
subnet='192.168.10.0/24')
|
||||||
cls.bridges.append(cls.brdc1)
|
self.bridges.append(self.brdc1)
|
||||||
|
|
||||||
cls.dockerimg = ctn_base.DockerImage()
|
self.dockerimg = ctn_base.DockerImage()
|
||||||
image = 'python:%d.%d' % (
|
image = 'python:%d.%d' % (
|
||||||
sys.version_info.major, sys.version_info.minor)
|
sys.version_info.major, sys.version_info.minor)
|
||||||
cls.r_img = cls.dockerimg.create_os_ken(image=image, check_exist=True)
|
self.r_img = self.dockerimg.create_os_ken(image=image,
|
||||||
cls.images.append(cls.r_img)
|
check_exist=True)
|
||||||
cls.q_img = 'osrg/quagga'
|
self.images.append(self.r_img)
|
||||||
cls.images.append(cls.q_img)
|
self.q_img = 'osrg/quagga'
|
||||||
|
self.images.append(self.q_img)
|
||||||
|
|
||||||
cls.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
self.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||||
router_id='192.168.0.1',
|
router_id='192.168.0.1',
|
||||||
ctn_image_name=cls.r_img)
|
ctn_image_name=self.r_img)
|
||||||
cls.containers.append(cls.r1)
|
self.containers.append(self.r1)
|
||||||
cls.r1.add_route('10.10.0.0/28')
|
self.r1.add_route('10.10.0.0/28')
|
||||||
cls.r1.run(wait=True)
|
self.r1.run(wait=True)
|
||||||
cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
|
self.r1_ip_cidr = self.brdc1.addif(self.r1)
|
||||||
cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
|
self.r1_ip = self.r1_ip_cidr.split('/')[0]
|
||||||
|
|
||||||
cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
self.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||||
router_id='192.168.0.2',
|
router_id='192.168.0.2',
|
||||||
ctn_image_name=cls.q_img)
|
ctn_image_name=self.q_img)
|
||||||
cls.containers.append(cls.q1)
|
self.containers.append(self.q1)
|
||||||
cls.q1.add_route('192.168.160.0/24')
|
self.q1.add_route('192.168.160.0/24')
|
||||||
cls.q1.run(wait=True)
|
self.q1.run(wait=True)
|
||||||
cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
|
self.q1_ip_cidr = self.brdc1.addif(self.q1)
|
||||||
cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
|
self.q1_ip = self.q1_ip_cidr.split('/')[0]
|
||||||
|
|
||||||
cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name)
|
self.r1.add_peer(self.q1, bridge=self.brdc1.name)
|
||||||
cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name)
|
self.q1.add_peer(self.r1, bridge=self.brdc1.name)
|
||||||
|
|
||||||
super(BgpSpeakerTestBase, cls).setUpClass()
|
super().setUp()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
@ -32,42 +32,44 @@ class BgpSpeakerTestBase(unittest.TestCase):
|
|||||||
bridges = []
|
bridges = []
|
||||||
checktime = 120
|
checktime = 120
|
||||||
|
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(cls):
|
self.skipTest('These tests require to have "docker" configured in the '
|
||||||
cls.brdc1 = ctn_base.Bridge(name='brip6dc1',
|
'system. Regardless of if we move them to functional or '
|
||||||
subnet='2001:10::/32')
|
'fix them, now we need to disable them.')
|
||||||
cls.bridges.append(cls.brdc1)
|
self.brdc1 = ctn_base.Bridge(name='brip6dc1', subnet='2001:10::/32')
|
||||||
|
self.bridges.append(self.brdc1)
|
||||||
|
|
||||||
cls.dockerimg = ctn_base.DockerImage()
|
self.dockerimg = ctn_base.DockerImage()
|
||||||
image = 'python:%d.%d' % (
|
image = 'python:%d.%d' % (
|
||||||
sys.version_info.major, sys.version_info.minor)
|
sys.version_info.major, sys.version_info.minor)
|
||||||
cls.r_img = cls.dockerimg.create_os_ken(image=image, check_exist=True)
|
self.r_img = self.dockerimg.create_os_ken(image=image,
|
||||||
cls.images.append(cls.r_img)
|
check_exist=True)
|
||||||
cls.q_img = 'osrg/quagga'
|
self.images.append(self.r_img)
|
||||||
cls.images.append(cls.q_img)
|
self.q_img = 'osrg/quagga'
|
||||||
|
self.images.append(self.q_img)
|
||||||
|
|
||||||
cls.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
self.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||||
router_id='192.168.0.1',
|
router_id='192.168.0.1',
|
||||||
ctn_image_name=cls.r_img)
|
ctn_image_name=self.r_img)
|
||||||
cls.containers.append(cls.r1)
|
self.containers.append(self.r1)
|
||||||
cls.r1.add_route('fc00:10::/64', route_info={'rf': 'ipv6'})
|
self.r1.add_route('fc00:10::/64', route_info={'rf': 'ipv6'})
|
||||||
cls.r1.run(wait=True)
|
self.r1.run(wait=True)
|
||||||
cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
|
self.r1_ip_cidr = self.brdc1.addif(self.r1)
|
||||||
cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
|
self.r1_ip = self.r1_ip_cidr.split('/')[0]
|
||||||
|
|
||||||
cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
self.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||||
router_id='192.168.0.2',
|
router_id='192.168.0.2',
|
||||||
ctn_image_name=cls.q_img)
|
ctn_image_name=self.q_img)
|
||||||
cls.containers.append(cls.q1)
|
self.containers.append(self.q1)
|
||||||
cls.q1.add_route('fc00:100::/64', route_info={'rf': 'ipv6'})
|
self.q1.add_route('fc00:100::/64', route_info={'rf': 'ipv6'})
|
||||||
cls.q1.run(wait=True)
|
self.q1.run(wait=True)
|
||||||
cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
|
self.q1_ip_cidr = self.brdc1.addif(self.q1)
|
||||||
cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
|
self.q1_ip = self.q1_ip_cidr.split('/')[0]
|
||||||
|
|
||||||
cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name, v6=True)
|
self.r1.add_peer(self.q1, bridge=self.brdc1.name, v6=True)
|
||||||
cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name, v6=True)
|
self.q1.add_peer(self.r1, bridge=self.brdc1.name, v6=True)
|
||||||
|
|
||||||
super(BgpSpeakerTestBase, cls).setUpClass()
|
super().setUp()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
@ -22,7 +22,7 @@ from . import base
|
|||||||
|
|
||||||
class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
|
class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BgpSpeakerBasicTest, self).setUp()
|
super().setUp()
|
||||||
self.r1.stop_os_kenbgp(retry=True)
|
self.r1.stop_os_kenbgp(retry=True)
|
||||||
self.r1.start_os_kenbgp(retry=True)
|
self.r1.start_os_kenbgp(retry=True)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from . import base_ip6 as base
|
|||||||
|
|
||||||
class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
|
class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BgpSpeakerBasicTest, self).setUp()
|
super().setUp()
|
||||||
self.r1.stop_os_kenbgp(retry=True)
|
self.r1.stop_os_kenbgp(retry=True)
|
||||||
self.r1.start_os_kenbgp(retry=True)
|
self.r1.start_os_kenbgp(retry=True)
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import ok_, eq_, timed, nottest
|
|
||||||
|
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
import time
|
import time
|
||||||
@ -59,30 +58,24 @@ class TestWithOVS12(unittest.TestCase):
|
|||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls.mn.stop()
|
cls.mn.stop()
|
||||||
|
|
||||||
@timed(TIMEOUT)
|
|
||||||
def test_add_flow_v10(self):
|
def test_add_flow_v10(self):
|
||||||
app = 'os_ken/tests/integrated/test_add_flow_v10.py'
|
app = 'os_ken/tests/integrated/test_add_flow_v10.py'
|
||||||
self._run_os_ken_manager_and_check_output(app)
|
self._run_os_ken_manager_and_check_output(app)
|
||||||
|
|
||||||
@timed(TIMEOUT)
|
|
||||||
def test_request_reply_v12(self):
|
def test_request_reply_v12(self):
|
||||||
app = 'os_ken/tests/integrated/test_request_reply_v12.py'
|
app = 'os_ken/tests/integrated/test_request_reply_v12.py'
|
||||||
self._run_os_ken_manager_and_check_output(app)
|
self._run_os_ken_manager_and_check_output(app)
|
||||||
|
|
||||||
@timed(TIMEOUT)
|
|
||||||
def test_add_flow_v12_actions(self):
|
def test_add_flow_v12_actions(self):
|
||||||
app = 'os_ken/tests/integrated/test_add_flow_v12_actions.py'
|
app = 'os_ken/tests/integrated/test_add_flow_v12_actions.py'
|
||||||
self._run_os_ken_manager_and_check_output(app)
|
self._run_os_ken_manager_and_check_output(app)
|
||||||
|
|
||||||
@timed(TIMEOUT)
|
|
||||||
def test_add_flow_v12_matches(self):
|
def test_add_flow_v12_matches(self):
|
||||||
app = 'os_ken/tests/integrated/test_add_flow_v12_matches.py'
|
app = 'os_ken/tests/integrated/test_add_flow_v12_matches.py'
|
||||||
self._run_os_ken_manager_and_check_output(app)
|
self._run_os_ken_manager_and_check_output(app)
|
||||||
|
|
||||||
@nottest
|
|
||||||
def test_of_config(self):
|
def test_of_config(self):
|
||||||
# OVS 1.10 does not support of_config
|
self.skipTest('OVS 1.10 does not support of_config')
|
||||||
pass
|
|
||||||
|
|
||||||
def _run_os_ken_manager_and_check_output(self, app):
|
def _run_os_ken_manager_and_check_output(self, app):
|
||||||
cmd = [PYTHON_BIN, OSKEN_MGR, app]
|
cmd = [PYTHON_BIN, OSKEN_MGR, app]
|
||||||
@ -99,11 +92,7 @@ class TestWithOVS12(unittest.TestCase):
|
|||||||
|
|
||||||
print("osken-manager: %s" % line)
|
print("osken-manager: %s" % line)
|
||||||
if line.find('TEST_FINISHED') != -1:
|
if line.find('TEST_FINISHED') != -1:
|
||||||
ok_(line.find('Completed=[True]') != -1)
|
self.assertTrue(line.find('Completed=[True]') != -1)
|
||||||
p.terminate()
|
p.terminate()
|
||||||
p.communicate() # wait for subprocess is terminated
|
p.communicate() # wait for subprocess is terminated
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from nose import config
|
|
||||||
from nose import core
|
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
import os_ken.tests.unit
|
|
||||||
from os_ken.tests.test_lib import run_tests
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
exit_status = False
|
|
||||||
|
|
||||||
# if a single test case was specified,
|
|
||||||
# we should only invoked the tests once
|
|
||||||
invoke_once = len(sys.argv) > 1
|
|
||||||
|
|
||||||
cwd = os.getcwd()
|
|
||||||
c = config.Config(stream=sys.stdout,
|
|
||||||
env=os.environ,
|
|
||||||
verbosity=int(os.environ.get('NOSE_VERBOSE', 3)),
|
|
||||||
includeExe=True,
|
|
||||||
traverseNamespace=True,
|
|
||||||
plugins=core.DefaultPluginManager())
|
|
||||||
c.configureWhere(os_ken.tests.unit.__path__)
|
|
||||||
|
|
||||||
exit_status = run_tests(c)
|
|
||||||
sys.exit(exit_status)
|
|
@ -1,274 +0,0 @@
|
|||||||
# Copyright (C) 2013,2014,2015 Nippon Telegraph and Telephone Corporation.
|
|
||||||
# Copyright (C) 2013,2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
# implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
import gettext
|
|
||||||
import os
|
|
||||||
import unittest
|
|
||||||
import six
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from nose import result
|
|
||||||
from nose import core
|
|
||||||
from nose import config
|
|
||||||
|
|
||||||
|
|
||||||
class _AnsiColorizer(object):
|
|
||||||
"""
|
|
||||||
A colorizer is an object that loosely wraps around a stream, allowing
|
|
||||||
callers to write text to the stream in a particular color.
|
|
||||||
|
|
||||||
Colorizer classes must implement C{supported()} and C{write(text, color)}.
|
|
||||||
"""
|
|
||||||
_colors = dict(black=30, red=31, green=32, yellow=33,
|
|
||||||
blue=34, magenta=35, cyan=36, white=37)
|
|
||||||
|
|
||||||
def __init__(self, stream):
|
|
||||||
self.stream = stream
|
|
||||||
|
|
||||||
def supported(cls, stream=sys.stdout):
|
|
||||||
"""
|
|
||||||
A class method that returns True if the current platform supports
|
|
||||||
coloring terminal output using this method. Returns False otherwise.
|
|
||||||
"""
|
|
||||||
if not stream.isatty():
|
|
||||||
return False # auto color only on TTYs
|
|
||||||
try:
|
|
||||||
import curses
|
|
||||||
except ImportError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
return curses.tigetnum("colors") > 2
|
|
||||||
except curses.error:
|
|
||||||
curses.setupterm()
|
|
||||||
return curses.tigetnum("colors") > 2
|
|
||||||
except:
|
|
||||||
# guess false in case of error
|
|
||||||
return False
|
|
||||||
supported = classmethod(supported)
|
|
||||||
|
|
||||||
def write(self, text, color):
|
|
||||||
"""
|
|
||||||
Write the given text to the stream in the given color.
|
|
||||||
|
|
||||||
@param text: Text to be written to the stream.
|
|
||||||
|
|
||||||
@param color: A string label for a color. e.g. 'red', 'white'.
|
|
||||||
"""
|
|
||||||
color = self._colors[color]
|
|
||||||
self.stream.write('\x1b[%s;1m%s\x1b[0m' % (color, text))
|
|
||||||
|
|
||||||
|
|
||||||
class _Win32Colorizer(object):
|
|
||||||
"""
|
|
||||||
See _AnsiColorizer docstring.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, stream):
|
|
||||||
from win32console import GetStdHandle, STD_OUT_HANDLE
|
|
||||||
from win32console import FOREGROUND_RED, FOREGROUND_BLUE
|
|
||||||
from win32console import FOREGROUND_GREEN, FOREGROUND_INTENSITY
|
|
||||||
red, green, blue, bold = (FOREGROUND_RED, FOREGROUND_GREEN,
|
|
||||||
FOREGROUND_BLUE, FOREGROUND_INTENSITY)
|
|
||||||
self.stream = stream
|
|
||||||
self.screenBuffer = GetStdHandle(STD_OUT_HANDLE)
|
|
||||||
self._colors = {
|
|
||||||
'normal': red | green | blue,
|
|
||||||
'red': red | bold,
|
|
||||||
'green': green | bold,
|
|
||||||
'blue': blue | bold,
|
|
||||||
'yellow': red | green | bold,
|
|
||||||
'magenta': red | blue | bold,
|
|
||||||
'cyan': green | blue | bold,
|
|
||||||
'white': red | green | blue | bold}
|
|
||||||
|
|
||||||
def supported(cls, stream=sys.stdout):
|
|
||||||
try:
|
|
||||||
import win32console
|
|
||||||
screenBuffer = win32console.GetStdHandle(
|
|
||||||
win32console.STD_OUT_HANDLE)
|
|
||||||
except ImportError:
|
|
||||||
return False
|
|
||||||
import pywintypes
|
|
||||||
try:
|
|
||||||
screenBuffer.SetConsoleTextAttribute(
|
|
||||||
win32console.FOREGROUND_RED |
|
|
||||||
win32console.FOREGROUND_GREEN |
|
|
||||||
win32console.FOREGROUND_BLUE)
|
|
||||||
except pywintypes.error:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
supported = classmethod(supported)
|
|
||||||
|
|
||||||
def write(self, text, color):
|
|
||||||
color = self._colors[color]
|
|
||||||
self.screenBuffer.SetConsoleTextAttribute(color)
|
|
||||||
self.stream.write(text)
|
|
||||||
self.screenBuffer.SetConsoleTextAttribute(self._colors['normal'])
|
|
||||||
|
|
||||||
|
|
||||||
class _NullColorizer(object):
|
|
||||||
"""
|
|
||||||
See _AnsiColorizer docstring.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, stream):
|
|
||||||
self.stream = stream
|
|
||||||
|
|
||||||
def supported(cls, stream=sys.stdout):
|
|
||||||
return True
|
|
||||||
supported = classmethod(supported)
|
|
||||||
|
|
||||||
def write(self, text, color):
|
|
||||||
self.stream.write(text)
|
|
||||||
|
|
||||||
|
|
||||||
class OSKenTestResult(result.TextTestResult):
|
|
||||||
def __init__(self, *args, **kw):
|
|
||||||
result.TextTestResult.__init__(self, *args, **kw)
|
|
||||||
self._last_case = None
|
|
||||||
self.colorizer = None
|
|
||||||
# NOTE(vish, tfukushima): reset stdout for the terminal check
|
|
||||||
stdout = sys.__stdout__
|
|
||||||
sys.stdout = sys.__stdout__
|
|
||||||
for colorizer in [_Win32Colorizer, _AnsiColorizer, _NullColorizer]:
|
|
||||||
if colorizer.supported():
|
|
||||||
self.colorizer = colorizer(self.stream)
|
|
||||||
break
|
|
||||||
sys.stdout = stdout
|
|
||||||
|
|
||||||
def getDescription(self, test):
|
|
||||||
return str(test)
|
|
||||||
|
|
||||||
# NOTE(vish, tfukushima): copied from unittest with edit to add color
|
|
||||||
def addSuccess(self, test):
|
|
||||||
unittest.TestResult.addSuccess(self, test)
|
|
||||||
if self.showAll:
|
|
||||||
self.colorizer.write("OK", 'green')
|
|
||||||
self.stream.writeln()
|
|
||||||
elif self.dots:
|
|
||||||
self.stream.write('.')
|
|
||||||
self.stream.flush()
|
|
||||||
|
|
||||||
# NOTE(vish, tfukushima): copied from unittest with edit to add color
|
|
||||||
def addFailure(self, test, err):
|
|
||||||
unittest.TestResult.addFailure(self, test, err)
|
|
||||||
if self.showAll:
|
|
||||||
self.colorizer.write("FAIL", 'red')
|
|
||||||
self.stream.writeln()
|
|
||||||
elif self.dots:
|
|
||||||
self.stream.write('F')
|
|
||||||
self.stream.flush()
|
|
||||||
|
|
||||||
# NOTE(vish, tfukushima): copied from unittest with edit to add color
|
|
||||||
def addError(self, test, err):
|
|
||||||
"""Overrides normal addError to add support for errorClasses.
|
|
||||||
If the exception is a registered class, the error will be added
|
|
||||||
to the list for that class, not errors.
|
|
||||||
"""
|
|
||||||
stream = getattr(self, 'stream', None)
|
|
||||||
ec, ev, tb = err
|
|
||||||
try:
|
|
||||||
exc_info = self._exc_info_to_string(err, test)
|
|
||||||
except TypeError:
|
|
||||||
# This is for compatibility with Python 2.3.
|
|
||||||
exc_info = self._exc_info_to_string(err)
|
|
||||||
for cls, (storage, label, isfail) in self.errorClasses.items():
|
|
||||||
if result.isclass(ec) and issubclass(ec, cls):
|
|
||||||
if isfail:
|
|
||||||
test.passwd = False
|
|
||||||
storage.append((test, exc_info))
|
|
||||||
# Might get patched into a streamless result
|
|
||||||
if stream is not None:
|
|
||||||
if self.showAll:
|
|
||||||
message = [label]
|
|
||||||
detail = result._exception_detail(err[1])
|
|
||||||
if detail:
|
|
||||||
message.append(detail)
|
|
||||||
stream.writeln(": ".join(message))
|
|
||||||
elif self.dots:
|
|
||||||
stream.write(label[:1])
|
|
||||||
return
|
|
||||||
self.errors.append((test, exc_info))
|
|
||||||
test.passed = False
|
|
||||||
if stream is not None:
|
|
||||||
if self.showAll:
|
|
||||||
self.colorizer.write("ERROR", 'red')
|
|
||||||
self.stream.writeln()
|
|
||||||
elif self.dots:
|
|
||||||
stream.write('E')
|
|
||||||
|
|
||||||
def startTest(self, test):
|
|
||||||
unittest.TestResult.startTest(self, test)
|
|
||||||
current_case = test.test.__class__.__name__
|
|
||||||
|
|
||||||
if self.showAll:
|
|
||||||
if current_case != self._last_case:
|
|
||||||
self.stream.writeln(current_case)
|
|
||||||
self._last_case = current_case
|
|
||||||
# NOTE(salvatore-orlando):
|
|
||||||
# slightly changed in order to print test case class
|
|
||||||
# together with unit test name
|
|
||||||
self.stream.write(
|
|
||||||
' %s' % str(test.test).ljust(60))
|
|
||||||
self.stream.flush()
|
|
||||||
|
|
||||||
|
|
||||||
class OSKenTestRunner(core.TextTestRunner):
|
|
||||||
def _makeResult(self):
|
|
||||||
return OSKenTestResult(self.stream,
|
|
||||||
self.descriptions,
|
|
||||||
self.verbosity,
|
|
||||||
self.config)
|
|
||||||
|
|
||||||
|
|
||||||
def run_tests(c=None):
|
|
||||||
logger = logging.getLogger()
|
|
||||||
hdlr = logging.StreamHandler()
|
|
||||||
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
|
||||||
hdlr.setFormatter(formatter)
|
|
||||||
logger.addHandler(hdlr)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
# NOTE(bgh): I'm not entirely sure why but nose gets confused here when
|
|
||||||
# calling run_tests from a plugin directory run_tests.py (instead of the
|
|
||||||
# main run_tests.py). It will call run_tests with no arguments and the
|
|
||||||
# testing of run_tests will fail (though the plugin tests will pass). For
|
|
||||||
# now we just return True to let the run_tests test pass.
|
|
||||||
if not c:
|
|
||||||
return True
|
|
||||||
|
|
||||||
runner = OSKenTestRunner(stream=c.stream,
|
|
||||||
verbosity=c.verbosity,
|
|
||||||
config=c)
|
|
||||||
return not core.run(config=c, testRunner=runner)
|
|
||||||
|
|
||||||
|
|
||||||
def add_method(cls, method_name, method):
|
|
||||||
"""Add the method to the class dynamically, keeping unittest/nose happy."""
|
|
||||||
method.func_name = method_name
|
|
||||||
method.__name__ = method_name
|
|
||||||
if six.PY3:
|
|
||||||
methodtype = types.MethodType(method, cls)
|
|
||||||
if not hasattr(method, "__qualname__"):
|
|
||||||
method.__qualname__ = "%s.%s" % (cls.__qualname__, method_name)
|
|
||||||
else:
|
|
||||||
methodtype = types.MethodType(method, None, cls)
|
|
||||||
setattr(cls, method_name, methodtype)
|
|
@ -1,28 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
"""
|
|
||||||
test_os_ken
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Tests for `os_ken` module.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from os_ken.tests import base
|
|
||||||
|
|
||||||
|
|
||||||
class TestOs_ken(base.TestCase):
|
|
||||||
|
|
||||||
def test_something(self):
|
|
||||||
pass
|
|
@ -14,18 +14,10 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import eq_, raises
|
from imp import reload
|
||||||
|
|
||||||
try:
|
|
||||||
# Python 3
|
|
||||||
from imp import reload
|
|
||||||
except ImportError:
|
|
||||||
# Python 2
|
|
||||||
pass
|
|
||||||
|
|
||||||
from os_ken.cmd.manager import main
|
from os_ken.cmd.manager import main
|
||||||
|
|
||||||
@ -43,15 +35,13 @@ class Test_Manager(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@raises(SystemExit)
|
|
||||||
@mock.patch('sys.argv', new=['osken-manager', '--version'])
|
@mock.patch('sys.argv', new=['osken-manager', '--version'])
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
main()
|
self.assertRaises(SystemExit, main)
|
||||||
|
|
||||||
@raises(SystemExit)
|
|
||||||
@mock.patch('sys.argv', new=['osken-manager', '--help'])
|
@mock.patch('sys.argv', new=['osken-manager', '--help'])
|
||||||
def test_help(self):
|
def test_help(self):
|
||||||
main()
|
self.assertRaises(SystemExit, main)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _reset_globals():
|
def _reset_globals():
|
||||||
|
@ -22,11 +22,10 @@ import sys
|
|||||||
import warnings
|
import warnings
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
import testtools
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import eq_, raises
|
|
||||||
|
|
||||||
from os_ken.base import app_manager # To suppress cyclic import
|
from os_ken.base import app_manager # To suppress cyclic import
|
||||||
from os_ken.controller import controller
|
from os_ken.controller import controller
|
||||||
from os_ken.controller import handler
|
from os_ken.controller import handler
|
||||||
@ -40,36 +39,35 @@ hub.patch()
|
|||||||
LOG = logging.getLogger('test_controller')
|
LOG = logging.getLogger('test_controller')
|
||||||
|
|
||||||
|
|
||||||
class TestUtils(unittest.TestCase):
|
class TestUtils(testtools.TestCase):
|
||||||
"""
|
"""
|
||||||
Test cases for utilities defined in controller module.
|
Test cases for utilities defined in controller module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_split_addr_with_ipv4(self):
|
def test_split_addr_with_ipv4(self):
|
||||||
addr, port = controller._split_addr('127.0.0.1:6653')
|
addr, port = controller._split_addr('127.0.0.1:6653')
|
||||||
eq_('127.0.0.1', addr)
|
self.assertEqual('127.0.0.1', addr)
|
||||||
eq_(6653, port)
|
self.assertEqual(6653, port)
|
||||||
|
|
||||||
def test_split_addr_with_ipv6(self):
|
def test_split_addr_with_ipv6(self):
|
||||||
addr, port = controller._split_addr('[::1]:6653')
|
addr, port = controller._split_addr('[::1]:6653')
|
||||||
eq_('::1', addr)
|
self.assertEqual('::1', addr)
|
||||||
eq_(6653, port)
|
self.assertEqual(6653, port)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_split_addr_with_invalid_addr(self):
|
def test_split_addr_with_invalid_addr(self):
|
||||||
controller._split_addr('127.0.0.1')
|
self.assertRaises(ValueError, controller._split_addr, '127.0.0.1')
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_split_addr_with_invalid_ipv4_addr(self):
|
def test_split_addr_with_invalid_ipv4_addr(self):
|
||||||
controller._split_addr('xxx.xxx.xxx.xxx:6653')
|
self.assertRaises(ValueError, controller._split_addr,
|
||||||
|
'xxx.xxx.xxx.xxx:6653')
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_split_addr_with_invalid_ipv6_addr(self):
|
def test_split_addr_with_invalid_ipv6_addr(self):
|
||||||
controller._split_addr('[::xxxx]:6653')
|
self.assertRaises(ValueError, controller._split_addr,
|
||||||
|
'[::xxxx]:6653')
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_split_addr_with_non_bracketed_ipv6_addr(self):
|
def test_split_addr_with_non_bracketed_ipv6_addr(self):
|
||||||
controller._split_addr('::1:6653')
|
self.assertRaises(ValueError, controller._split_addr,
|
||||||
|
'::1:6653')
|
||||||
|
|
||||||
|
|
||||||
class Test_Datapath(unittest.TestCase):
|
class Test_Datapath(unittest.TestCase):
|
||||||
@ -176,53 +174,3 @@ class Test_Datapath(unittest.TestCase):
|
|||||||
self.assertEqual(state, handler.MAIN_DISPATCHER)
|
self.assertEqual(state, handler.MAIN_DISPATCHER)
|
||||||
self.assertEqual(kwargs, {})
|
self.assertEqual(kwargs, {})
|
||||||
self.assertEqual(expected_json, output_json)
|
self.assertEqual(expected_json, output_json)
|
||||||
|
|
||||||
|
|
||||||
class TestOpenFlowController(unittest.TestCase):
|
|
||||||
"""
|
|
||||||
Test cases for OpenFlowController
|
|
||||||
"""
|
|
||||||
@mock.patch("os_ken.controller.controller.CONF")
|
|
||||||
def _test_ssl(self, this_dir, port, conf_mock):
|
|
||||||
conf_mock.ofp_ssl_listen_port = port
|
|
||||||
conf_mock.ofp_listen_host = "127.0.0.1"
|
|
||||||
conf_mock.ca_certs = None
|
|
||||||
conf_mock.ciphers = None
|
|
||||||
conf_mock.ctl_cert = os.path.join(this_dir, 'cert.crt')
|
|
||||||
conf_mock.ctl_privkey = os.path.join(this_dir, 'cert.key')
|
|
||||||
c = controller.OpenFlowController()
|
|
||||||
c()
|
|
||||||
|
|
||||||
def test_ssl(self):
|
|
||||||
"""Tests SSL server functionality."""
|
|
||||||
# TODO: TLS version enforcement is necessary to avoid
|
|
||||||
# vulnerable versions. Currently, this only tests TLS
|
|
||||||
# connectivity.
|
|
||||||
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
|
||||||
saved_exception = None
|
|
||||||
try:
|
|
||||||
ssl_version = ssl.PROTOCOL_TLS
|
|
||||||
except AttributeError:
|
|
||||||
# For compatibility with older pythons.
|
|
||||||
ssl_version = ssl.PROTOCOL_TLSv1
|
|
||||||
for i in range(3):
|
|
||||||
try:
|
|
||||||
# Try a few times as this can fail with EADDRINUSE
|
|
||||||
port = random.randint(5000, 10000)
|
|
||||||
server = hub.spawn(self._test_ssl, this_dir, port)
|
|
||||||
hub.sleep(1)
|
|
||||||
client = hub.StreamClient(("127.0.0.1", port),
|
|
||||||
timeout=5,
|
|
||||||
ssl_version=ssl_version)
|
|
||||||
if client.connect() is not None:
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
saved_exception = e
|
|
||||||
continue
|
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
hub.kill(server)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("Failed to connect: " + str(saved_exception))
|
|
||||||
|
@ -13,13 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from nose.tools import eq_
|
|
||||||
|
|
||||||
from os_ken.lib import sockaddr
|
from os_ken.lib import sockaddr
|
||||||
|
|
||||||
|
|
||||||
system = platform.system()
|
system = platform.system()
|
||||||
|
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ class Test_sockaddr(unittest.TestCase):
|
|||||||
addr = '127.0.0.1'
|
addr = '127.0.0.1'
|
||||||
expected_result = (b'\x02\x00\x00\x00'
|
expected_result = (b'\x02\x00\x00\x00'
|
||||||
b'\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00')
|
b'\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
eq_(expected_result, sockaddr.sa_in4(addr))
|
self.assertEqual(expected_result, sockaddr.sa_in4(addr))
|
||||||
|
|
||||||
def test_sockaddr_linux_sa_in6(self):
|
def test_sockaddr_linux_sa_in6(self):
|
||||||
if system != 'Linux' or sys.byteorder != 'little':
|
if system != 'Linux' or sys.byteorder != 'little':
|
||||||
@ -47,9 +46,9 @@ class Test_sockaddr(unittest.TestCase):
|
|||||||
addr = 'dead:beef::1'
|
addr = 'dead:beef::1'
|
||||||
expected_result = (b'\n\x00\x00\x00\x00\x00\x00\x00\xde\xad\xbe\xef'
|
expected_result = (b'\n\x00\x00\x00\x00\x00\x00\x00\xde\xad\xbe\xef'
|
||||||
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00')
|
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00')
|
||||||
eq_(expected_result, sockaddr.sa_in6(addr))
|
self.assertEqual(expected_result, sockaddr.sa_in6(addr))
|
||||||
|
|
||||||
def test_sockaddr_sa_to_ss(self):
|
def test_sockaddr_sa_to_ss(self):
|
||||||
addr = b'\x01'
|
addr = b'\x01'
|
||||||
expected_result = b'\x01' + 127 * b'\x00'
|
expected_result = b'\x01' + 127 * b'\x00'
|
||||||
eq_(expected_result, sockaddr.sa_to_ss(addr))
|
self.assertEqual(expected_result, sockaddr.sa_to_ss(addr))
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.ofproto.ether import *
|
from os_ken.ofproto.ether import *
|
||||||
|
|
||||||
|
|
||||||
@ -29,9 +28,9 @@ class TestInet(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test_ether_type(self):
|
def test_ether_type(self):
|
||||||
eq_(ETH_TYPE_IP, 0x0800)
|
self.assertEqual(ETH_TYPE_IP, 0x0800)
|
||||||
eq_(ETH_TYPE_ARP, 0x0806)
|
self.assertEqual(ETH_TYPE_ARP, 0x0806)
|
||||||
eq_(ETH_TYPE_8021Q, 0x8100)
|
self.assertEqual(ETH_TYPE_8021Q, 0x8100)
|
||||||
eq_(ETH_TYPE_IPV6, 0x86dd)
|
self.assertEqual(ETH_TYPE_IPV6, 0x86dd)
|
||||||
eq_(ETH_TYPE_MPLS, 0x8847)
|
self.assertEqual(ETH_TYPE_MPLS, 0x8847)
|
||||||
eq_(ETH_TYPE_SLOW, 0x8809)
|
self.assertEqual(ETH_TYPE_SLOW, 0x8809)
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.ofproto.inet import *
|
from os_ken.ofproto.inet import *
|
||||||
|
|
||||||
|
|
||||||
@ -29,15 +28,15 @@ class TestInet(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test_ip_proto(self):
|
def test_ip_proto(self):
|
||||||
eq_(IPPROTO_IP, 0)
|
self.assertEqual(IPPROTO_IP, 0)
|
||||||
eq_(IPPROTO_HOPOPTS, 0)
|
self.assertEqual(IPPROTO_HOPOPTS, 0)
|
||||||
eq_(IPPROTO_ICMP, 1)
|
self.assertEqual(IPPROTO_ICMP, 1)
|
||||||
eq_(IPPROTO_TCP, 6)
|
self.assertEqual(IPPROTO_TCP, 6)
|
||||||
eq_(IPPROTO_UDP, 17)
|
self.assertEqual(IPPROTO_UDP, 17)
|
||||||
eq_(IPPROTO_ROUTING, 43)
|
self.assertEqual(IPPROTO_ROUTING, 43)
|
||||||
eq_(IPPROTO_FRAGMENT, 44)
|
self.assertEqual(IPPROTO_FRAGMENT, 44)
|
||||||
eq_(IPPROTO_AH, 51)
|
self.assertEqual(IPPROTO_AH, 51)
|
||||||
eq_(IPPROTO_ICMPV6, 58)
|
self.assertEqual(IPPROTO_ICMPV6, 58)
|
||||||
eq_(IPPROTO_NONE, 59)
|
self.assertEqual(IPPROTO_NONE, 59)
|
||||||
eq_(IPPROTO_DSTOPTS, 60)
|
self.assertEqual(IPPROTO_DSTOPTS, 60)
|
||||||
eq_(IPPROTO_SCTP, 132)
|
self.assertEqual(IPPROTO_SCTP, 132)
|
||||||
|
@ -16,16 +16,10 @@
|
|||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
try:
|
from imp import reload
|
||||||
# Python 3
|
|
||||||
from imp import reload
|
|
||||||
except ImportError:
|
|
||||||
# Python 2
|
|
||||||
pass
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
from nose.tools import eq_
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('test_ofproto')
|
LOG = logging.getLogger('test_ofproto')
|
||||||
@ -53,19 +47,22 @@ class TestOfprotCommon(unittest.TestCase):
|
|||||||
import os_ken.ofproto.ofproto_v1_3
|
import os_ken.ofproto.ofproto_v1_3
|
||||||
import os_ken.ofproto.ofproto_v1_4
|
import os_ken.ofproto.ofproto_v1_4
|
||||||
import os_ken.ofproto.ofproto_v1_5
|
import os_ken.ofproto.ofproto_v1_5
|
||||||
eq_(set(ofp_modules.keys()), set([os_ken.ofproto.ofproto_v1_0.OFP_VERSION,
|
self.assertEqual(set(ofp_modules.keys()),
|
||||||
|
set([os_ken.ofproto.ofproto_v1_0.OFP_VERSION,
|
||||||
os_ken.ofproto.ofproto_v1_2.OFP_VERSION,
|
os_ken.ofproto.ofproto_v1_2.OFP_VERSION,
|
||||||
os_ken.ofproto.ofproto_v1_3.OFP_VERSION,
|
os_ken.ofproto.ofproto_v1_3.OFP_VERSION,
|
||||||
os_ken.ofproto.ofproto_v1_4.OFP_VERSION,
|
os_ken.ofproto.ofproto_v1_4.OFP_VERSION,
|
||||||
os_ken.ofproto.ofproto_v1_5.OFP_VERSION,
|
os_ken.ofproto.ofproto_v1_5.OFP_VERSION,
|
||||||
]))
|
]))
|
||||||
consts_mods = set([ofp_mod[0] for ofp_mod in ofp_modules.values()])
|
consts_mods = set([ofp_mod[0] for ofp_mod in ofp_modules.values()])
|
||||||
eq_(consts_mods, set([os_ken.ofproto.ofproto_v1_0,
|
self.assertEqual(consts_mods,
|
||||||
|
set([os_ken.ofproto.ofproto_v1_0,
|
||||||
os_ken.ofproto.ofproto_v1_2,
|
os_ken.ofproto.ofproto_v1_2,
|
||||||
os_ken.ofproto.ofproto_v1_3,
|
os_ken.ofproto.ofproto_v1_3,
|
||||||
os_ken.ofproto.ofproto_v1_4,
|
os_ken.ofproto.ofproto_v1_4,
|
||||||
os_ken.ofproto.ofproto_v1_5,
|
os_ken.ofproto.ofproto_v1_5,
|
||||||
]))
|
])
|
||||||
|
)
|
||||||
|
|
||||||
parser_mods = set([ofp_mod[1] for ofp_mod in ofp_modules.values()])
|
parser_mods = set([ofp_mod[1] for ofp_mod in ofp_modules.values()])
|
||||||
import os_ken.ofproto.ofproto_v1_0_parser
|
import os_ken.ofproto.ofproto_v1_0_parser
|
||||||
@ -73,9 +70,11 @@ class TestOfprotCommon(unittest.TestCase):
|
|||||||
import os_ken.ofproto.ofproto_v1_3_parser
|
import os_ken.ofproto.ofproto_v1_3_parser
|
||||||
import os_ken.ofproto.ofproto_v1_4_parser
|
import os_ken.ofproto.ofproto_v1_4_parser
|
||||||
import os_ken.ofproto.ofproto_v1_5_parser
|
import os_ken.ofproto.ofproto_v1_5_parser
|
||||||
eq_(parser_mods, set([os_ken.ofproto.ofproto_v1_0_parser,
|
self.assertEqual(parser_mods,
|
||||||
|
set([os_ken.ofproto.ofproto_v1_0_parser,
|
||||||
os_ken.ofproto.ofproto_v1_2_parser,
|
os_ken.ofproto.ofproto_v1_2_parser,
|
||||||
os_ken.ofproto.ofproto_v1_3_parser,
|
os_ken.ofproto.ofproto_v1_3_parser,
|
||||||
os_ken.ofproto.ofproto_v1_4_parser,
|
os_ken.ofproto.ofproto_v1_4_parser,
|
||||||
os_ken.ofproto.ofproto_v1_5_parser,
|
os_ken.ofproto.ofproto_v1_5_parser,
|
||||||
]))
|
])
|
||||||
|
)
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.ofproto.ofproto_common import *
|
from os_ken.ofproto.ofproto_common import *
|
||||||
|
|
||||||
|
|
||||||
@ -29,9 +28,9 @@ class TestOfprotCommon(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test_struct_ofp_header(self):
|
def test_struct_ofp_header(self):
|
||||||
eq_(OFP_HEADER_PACK_STR, '!BBHI')
|
self.assertEqual(OFP_HEADER_PACK_STR, '!BBHI')
|
||||||
eq_(OFP_HEADER_SIZE, 8)
|
self.assertEqual(OFP_HEADER_SIZE, 8)
|
||||||
|
|
||||||
def test_define_constants(self):
|
def test_define_constants(self):
|
||||||
eq_(OFP_TCP_PORT, 6653)
|
self.assertEqual(OFP_TCP_PORT, 6653)
|
||||||
eq_(OFP_SSL_PORT, 6653)
|
self.assertEqual(OFP_SSL_PORT, 6653)
|
||||||
|
@ -19,7 +19,6 @@ import six
|
|||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import *
|
|
||||||
import struct
|
import struct
|
||||||
from os_ken import exception
|
from os_ken import exception
|
||||||
|
|
||||||
@ -68,10 +67,10 @@ class TestOfproto_Parser(unittest.TestCase):
|
|||||||
msg_type,
|
msg_type,
|
||||||
msg_len,
|
msg_len,
|
||||||
xid) = ofproto_parser.header(self.bufHello)
|
xid) = ofproto_parser.header(self.bufHello)
|
||||||
eq_(version, 1)
|
self.assertEqual(version, 1)
|
||||||
eq_(msg_type, 0)
|
self.assertEqual(msg_type, 0)
|
||||||
eq_(msg_len, 8)
|
self.assertEqual(msg_len, 8)
|
||||||
eq_(xid, 1)
|
self.assertEqual(xid, 1)
|
||||||
|
|
||||||
def testFeaturesReply(self):
|
def testFeaturesReply(self):
|
||||||
(version,
|
(version,
|
||||||
@ -87,11 +86,11 @@ class TestOfproto_Parser(unittest.TestCase):
|
|||||||
self.bufFeaturesReply)
|
self.bufFeaturesReply)
|
||||||
LOG.debug(msg)
|
LOG.debug(msg)
|
||||||
|
|
||||||
ok_(isinstance(msg, ofproto_v1_0_parser.OFPSwitchFeatures))
|
self.assertTrue(isinstance(msg, ofproto_v1_0_parser.OFPSwitchFeatures))
|
||||||
LOG.debug(msg.ports[65534])
|
LOG.debug(msg.ports[65534])
|
||||||
ok_(isinstance(msg.ports[1], ofproto_v1_0_parser.OFPPhyPort))
|
self.assertTrue(isinstance(msg.ports[1], ofproto_v1_0_parser.OFPPhyPort))
|
||||||
ok_(isinstance(msg.ports[2], ofproto_v1_0_parser.OFPPhyPort))
|
self.assertTrue(isinstance(msg.ports[2], ofproto_v1_0_parser.OFPPhyPort))
|
||||||
ok_(isinstance(msg.ports[65534], ofproto_v1_0_parser.OFPPhyPort))
|
self.assertTrue(isinstance(msg.ports[65534], ofproto_v1_0_parser.OFPPhyPort))
|
||||||
|
|
||||||
def testPacketIn(self):
|
def testPacketIn(self):
|
||||||
(version,
|
(version,
|
||||||
@ -106,9 +105,8 @@ class TestOfproto_Parser(unittest.TestCase):
|
|||||||
xid,
|
xid,
|
||||||
self.bufPacketIn)
|
self.bufPacketIn)
|
||||||
LOG.debug(msg)
|
LOG.debug(msg)
|
||||||
ok_(isinstance(msg, ofproto_v1_0_parser.OFPPacketIn))
|
self.assertTrue(isinstance(msg, ofproto_v1_0_parser.OFPPacketIn))
|
||||||
|
|
||||||
@raises(AssertionError)
|
|
||||||
def test_check_msg_len(self):
|
def test_check_msg_len(self):
|
||||||
(version,
|
(version,
|
||||||
msg_type,
|
msg_type,
|
||||||
@ -116,14 +114,9 @@ class TestOfproto_Parser(unittest.TestCase):
|
|||||||
xid) = ofproto_parser.header(self.bufPacketIn)
|
xid) = ofproto_parser.header(self.bufPacketIn)
|
||||||
|
|
||||||
msg_len = len(self.bufPacketIn) + 1
|
msg_len = len(self.bufPacketIn) + 1
|
||||||
ofproto_parser.msg(self,
|
self.assertRaises(AssertionError, ofproto_parser.msg, self, version,
|
||||||
version,
|
msg_type, msg_len, xid, self.bufPacketIn)
|
||||||
msg_type,
|
|
||||||
msg_len,
|
|
||||||
xid,
|
|
||||||
self.bufPacketIn)
|
|
||||||
|
|
||||||
@raises(exception.OFPUnknownVersion)
|
|
||||||
def test_check_msg_parser(self):
|
def test_check_msg_parser(self):
|
||||||
(version,
|
(version,
|
||||||
msg_type,
|
msg_type,
|
||||||
@ -131,11 +124,8 @@ class TestOfproto_Parser(unittest.TestCase):
|
|||||||
xid) = ofproto_parser.header(self.bufPacketIn)
|
xid) = ofproto_parser.header(self.bufPacketIn)
|
||||||
|
|
||||||
version = 0xff
|
version = 0xff
|
||||||
ofproto_parser.msg(self,
|
self.assertRaises(exception.OFPUnknownVersion, ofproto_parser.msg,
|
||||||
version,
|
self, version, msg_type, msg_len, xid,
|
||||||
msg_type,
|
|
||||||
msg_len,
|
|
||||||
xid,
|
|
||||||
self.bufPacketIn)
|
self.bufPacketIn)
|
||||||
|
|
||||||
|
|
||||||
@ -156,14 +146,13 @@ class TestMsgBase(unittest.TestCase):
|
|||||||
xid = 3841413783
|
xid = 3841413783
|
||||||
c = ofproto_parser.MsgBase(object)
|
c = ofproto_parser.MsgBase(object)
|
||||||
c.set_xid(xid)
|
c.set_xid(xid)
|
||||||
eq_(xid, c.xid)
|
self.assertEqual(xid, c.xid)
|
||||||
|
|
||||||
@raises(AssertionError)
|
|
||||||
def test_set_xid_check_xid(self):
|
def test_set_xid_check_xid(self):
|
||||||
xid = 2160492514
|
xid = 2160492514
|
||||||
c = ofproto_parser.MsgBase(object)
|
c = ofproto_parser.MsgBase(object)
|
||||||
c.xid = xid
|
c.xid = xid
|
||||||
c.set_xid(xid)
|
self.assertRaises(AssertionError, c.set_xid, xid)
|
||||||
|
|
||||||
def _test_parser(self, msg_type=ofproto_v1_0.OFPT_HELLO):
|
def _test_parser(self, msg_type=ofproto_v1_0.OFPT_HELLO):
|
||||||
version = ofproto_v1_0.OFP_VERSION
|
version = ofproto_v1_0.OFP_VERSION
|
||||||
@ -178,11 +167,11 @@ class TestMsgBase(unittest.TestCase):
|
|||||||
res = ofproto_v1_0_parser.OFPHello.parser(
|
res = ofproto_v1_0_parser.OFPHello.parser(
|
||||||
object, version, msg_type, msg_len, xid, bytearray(buf))
|
object, version, msg_type, msg_len, xid, bytearray(buf))
|
||||||
|
|
||||||
eq_(version, res.version)
|
self.assertEqual(version, res.version)
|
||||||
eq_(msg_type, res.msg_type)
|
self.assertEqual(msg_type, res.msg_type)
|
||||||
eq_(msg_len, res.msg_len)
|
self.assertEqual(msg_len, res.msg_len)
|
||||||
eq_(xid, res.xid)
|
self.assertEqual(xid, res.xid)
|
||||||
eq_(buffer(buf), res.buf)
|
self.assertEqual(buffer(buf), res.buf)
|
||||||
|
|
||||||
# test __str__()
|
# test __str__()
|
||||||
list_ = ('version', 'msg_type', 'msg_len', 'xid')
|
list_ = ('version', 'msg_type', 'msg_len', 'xid')
|
||||||
@ -193,19 +182,19 @@ class TestMsgBase(unittest.TestCase):
|
|||||||
if k in list_:
|
if k in list_:
|
||||||
check[k] = v
|
check[k] = v
|
||||||
|
|
||||||
eq_(hex(ofproto_v1_0.OFP_VERSION), check['version'])
|
self.assertEqual(hex(ofproto_v1_0.OFP_VERSION), check['version'])
|
||||||
eq_(hex(ofproto_v1_0.OFPT_HELLO), check['msg_type'])
|
self.assertEqual(hex(ofproto_v1_0.OFPT_HELLO), check['msg_type'])
|
||||||
eq_(hex(msg_len), check['msg_len'])
|
self.assertEqual(hex(msg_len), check['msg_len'])
|
||||||
eq_(hex(xid), check['xid'])
|
self.assertEqual(hex(xid), check['xid'])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
ok_(self._test_parser())
|
self.assertTrue(self._test_parser())
|
||||||
|
|
||||||
@raises(AssertionError)
|
|
||||||
def test_parser_check_msg_type(self):
|
def test_parser_check_msg_type(self):
|
||||||
self._test_parser(ofproto_v1_0.OFPT_ERROR)
|
self.assertRaises(AssertionError, self._test_parser,
|
||||||
|
ofproto_v1_0.OFPT_ERROR)
|
||||||
|
|
||||||
def _test_serialize(self):
|
def _test_serialize(self):
|
||||||
|
|
||||||
@ -216,14 +205,14 @@ class TestMsgBase(unittest.TestCase):
|
|||||||
c = ofproto_v1_0_parser.OFPHello(Datapath)
|
c = ofproto_v1_0_parser.OFPHello(Datapath)
|
||||||
|
|
||||||
c.serialize()
|
c.serialize()
|
||||||
eq_(ofproto_v1_0.OFP_VERSION, c.version)
|
self.assertEqual(ofproto_v1_0.OFP_VERSION, c.version)
|
||||||
eq_(ofproto_v1_0.OFPT_HELLO, c.msg_type)
|
self.assertEqual(ofproto_v1_0.OFPT_HELLO, c.msg_type)
|
||||||
eq_(0, c.xid)
|
self.assertEqual(0, c.xid)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
ok_(self._test_serialize())
|
self.assertTrue(self._test_serialize())
|
||||||
|
|
||||||
|
|
||||||
class TestMsgStrAttr(unittest.TestCase):
|
class TestMsgStrAttr(unittest.TestCase):
|
||||||
@ -240,5 +229,5 @@ class TestMsgStrAttr(unittest.TestCase):
|
|||||||
res = ofproto_parser.msg_str_attr(c, buf, ('check',))
|
res = ofproto_parser.msg_str_attr(c, buf, ('check',))
|
||||||
str_ = str(res)
|
str_ = str(res)
|
||||||
str_ = str_.rsplit()
|
str_ = str_.rsplit()
|
||||||
eq_('check', str_[0])
|
self.assertEqual('check', str_[0])
|
||||||
eq_('msg_str_attr_test', str_[1])
|
self.assertEqual('msg_str_attr_test', str_[1])
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,10 +14,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os.path
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
import testscenarios
|
||||||
|
|
||||||
from os_ken.ofproto import ofproto_parser
|
from os_ken.ofproto import ofproto_parser
|
||||||
from os_ken.ofproto import ofproto_protocol
|
from os_ken.ofproto import ofproto_protocol
|
||||||
@ -26,7 +27,6 @@ from os_ken.ofproto import ofproto_v1_2
|
|||||||
from os_ken.ofproto import ofproto_v1_3
|
from os_ken.ofproto import ofproto_v1_3
|
||||||
from os_ken.ofproto import ofproto_v1_4
|
from os_ken.ofproto import ofproto_v1_4
|
||||||
from os_ken.ofproto import ofproto_v1_5
|
from os_ken.ofproto import ofproto_v1_5
|
||||||
from os_ken.tests import test_lib
|
|
||||||
from os_ken import exception
|
from os_ken import exception
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -153,13 +153,53 @@ implemented = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Test_Parser(unittest.TestCase):
|
def _list_test_cases():
|
||||||
""" Test case for os_ken.ofproto, especially json representation
|
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
||||||
"""
|
packet_data_dir = os.path.join(this_dir, '../../packet_data')
|
||||||
|
json_dir = os.path.join(this_dir, 'json')
|
||||||
|
ofvers = [
|
||||||
|
'of10',
|
||||||
|
'of12',
|
||||||
|
'of13',
|
||||||
|
'of14',
|
||||||
|
'of15',
|
||||||
|
]
|
||||||
|
cases = []
|
||||||
|
for ver in ofvers:
|
||||||
|
pdir = packet_data_dir + '/' + ver
|
||||||
|
jdir = json_dir + '/' + ver
|
||||||
|
for file in os.listdir(pdir):
|
||||||
|
if file.endswith('.packet'):
|
||||||
|
truncated = None
|
||||||
|
elif '.truncated' in file:
|
||||||
|
# contents of .truncated files aren't relevant
|
||||||
|
s1, s2 = file.split('.truncated')
|
||||||
|
try:
|
||||||
|
truncated = int(s2)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
file = s1 + '.packet'
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
wire_msg = open(pdir + '/' + file, 'rb').read()
|
||||||
|
if not truncated:
|
||||||
|
json_str = open(jdir + '/' + file + '.json', 'r').read()
|
||||||
|
else:
|
||||||
|
json_str = open(jdir + '/' + file +
|
||||||
|
'.truncated%d.json' % truncated, 'r').read()
|
||||||
|
wire_msg = wire_msg[:truncated]
|
||||||
|
method_name = ('test_' + file).replace('-', '_').replace('.', '_')
|
||||||
|
if truncated:
|
||||||
|
method_name += '_truncated%d' % truncated
|
||||||
|
cases.append({'name': method_name, 'wire_msg': wire_msg,
|
||||||
|
'json_str': json_str})
|
||||||
|
return cases
|
||||||
|
|
||||||
def __init__(self, methodName):
|
|
||||||
print('init %s' % methodName)
|
class Test_Parser(testscenarios.WithScenarios, unittest.TestCase):
|
||||||
super(Test_Parser, self).__init__(methodName)
|
"""Test case for os_ken.ofproto, especially json representation"""
|
||||||
|
|
||||||
|
scenarios = [(case['name'], case) for case in _list_test_cases()]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
@ -175,6 +215,10 @@ class Test_Parser(unittest.TestCase):
|
|||||||
def _jsondict_to_msg(dp, jsondict):
|
def _jsondict_to_msg(dp, jsondict):
|
||||||
return ofproto_parser.ofp_msg_from_jsondict(dp, jsondict)
|
return ofproto_parser.ofp_msg_from_jsondict(dp, jsondict)
|
||||||
|
|
||||||
|
def test_parser(self):
|
||||||
|
self._test_msg(name=self.name, wire_msg=self.wire_msg,
|
||||||
|
json_str=self.json_str)
|
||||||
|
|
||||||
def _test_msg(self, name, wire_msg, json_str):
|
def _test_msg(self, name, wire_msg, json_str):
|
||||||
def bytes_eq(buf1, buf2):
|
def bytes_eq(buf1, buf2):
|
||||||
if buf1 != buf2:
|
if buf1 != buf2:
|
||||||
@ -206,8 +250,9 @@ class Test_Parser(unittest.TestCase):
|
|||||||
json_dict2 = {'OFPTruncatedMessage':
|
json_dict2 = {'OFPTruncatedMessage':
|
||||||
self._msg_to_jsondict(e.ofpmsg)}
|
self._msg_to_jsondict(e.ofpmsg)}
|
||||||
# XXXdebug code
|
# XXXdebug code
|
||||||
open(('/tmp/%s.json' % name), 'w').write(json.dumps(json_dict2))
|
with open(('/tmp/%s.json' % name), 'w') as _file:
|
||||||
eq_(json_dict, json_dict2)
|
_file.write(json.dumps(json_dict2))
|
||||||
|
self.assertEqual(json_dict, json_dict2)
|
||||||
if 'OFPTruncatedMessage' in json_dict2:
|
if 'OFPTruncatedMessage' in json_dict2:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -217,7 +262,7 @@ class Test_Parser(unittest.TestCase):
|
|||||||
msg2.set_xid(xid)
|
msg2.set_xid(xid)
|
||||||
if has_serializer:
|
if has_serializer:
|
||||||
msg2.serialize()
|
msg2.serialize()
|
||||||
eq_(self._msg_to_jsondict(msg2), json_dict)
|
self.assertEqual(self._msg_to_jsondict(msg2), json_dict)
|
||||||
bytes_eq(wire_msg, msg2.buf)
|
bytes_eq(wire_msg, msg2.buf)
|
||||||
|
|
||||||
# check if "len" "length" fields can be omitted
|
# check if "len" "length" fields can be omitted
|
||||||
@ -243,67 +288,3 @@ class Test_Parser(unittest.TestCase):
|
|||||||
|
|
||||||
msg2.serialize()
|
msg2.serialize()
|
||||||
bytes_eq(wire_msg, msg2.buf)
|
bytes_eq(wire_msg, msg2.buf)
|
||||||
|
|
||||||
|
|
||||||
def _add_tests():
|
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
import functools
|
|
||||||
|
|
||||||
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
|
||||||
packet_data_dir = os.path.join(this_dir, '../../packet_data')
|
|
||||||
json_dir = os.path.join(this_dir, 'json')
|
|
||||||
ofvers = [
|
|
||||||
'of10',
|
|
||||||
'of12',
|
|
||||||
'of13',
|
|
||||||
'of14',
|
|
||||||
'of15',
|
|
||||||
]
|
|
||||||
cases = set()
|
|
||||||
for ver in ofvers:
|
|
||||||
pdir = packet_data_dir + '/' + ver
|
|
||||||
jdir = json_dir + '/' + ver
|
|
||||||
n_added = 0
|
|
||||||
for file in os.listdir(pdir):
|
|
||||||
if file.endswith('.packet'):
|
|
||||||
truncated = None
|
|
||||||
elif '.truncated' in file:
|
|
||||||
# contents of .truncated files aren't relevant
|
|
||||||
s1, s2 = file.split('.truncated')
|
|
||||||
try:
|
|
||||||
truncated = int(s2)
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
file = s1 + '.packet'
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
wire_msg = open(pdir + '/' + file, 'rb').read()
|
|
||||||
if not truncated:
|
|
||||||
json_str = open(jdir + '/' + file + '.json', 'r').read()
|
|
||||||
else:
|
|
||||||
json_str = open(jdir + '/' + file +
|
|
||||||
'.truncated%d.json' % truncated, 'r').read()
|
|
||||||
wire_msg = wire_msg[:truncated]
|
|
||||||
method_name = ('test_' + file).replace('-', '_').replace('.', '_')
|
|
||||||
if truncated:
|
|
||||||
method_name += '_truncated%d' % truncated
|
|
||||||
|
|
||||||
def _run(self, name, wire_msg, json_str):
|
|
||||||
print('processing %s ...' % name)
|
|
||||||
if six.PY3:
|
|
||||||
self._test_msg(self, name, wire_msg, json_str)
|
|
||||||
else:
|
|
||||||
self._test_msg(name, wire_msg, json_str)
|
|
||||||
print('adding %s ...' % method_name)
|
|
||||||
f = functools.partial(_run, name=method_name, wire_msg=wire_msg,
|
|
||||||
json_str=json_str)
|
|
||||||
test_lib.add_method(Test_Parser, method_name, f)
|
|
||||||
cases.add(method_name)
|
|
||||||
n_added += 1
|
|
||||||
assert n_added > 0
|
|
||||||
assert (cases ==
|
|
||||||
set(unittest.defaultTestLoader.getTestCaseNames(Test_Parser)))
|
|
||||||
|
|
||||||
|
|
||||||
_add_tests()
|
|
||||||
|
@ -15,10 +15,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
import testscenarios
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.ofproto import ofproto_v1_2
|
from os_ken.ofproto import ofproto_v1_2
|
||||||
from os_ken.ofproto import ofproto_v1_3
|
from os_ken.ofproto import ofproto_v1_3
|
||||||
@ -26,14 +24,22 @@ from os_ken.ofproto import ofproto_v1_2_parser
|
|||||||
from os_ken.ofproto import ofproto_v1_3_parser
|
from os_ken.ofproto import ofproto_v1_3_parser
|
||||||
|
|
||||||
from os_ken.lib import addrconv
|
from os_ken.lib import addrconv
|
||||||
from os_ken.tests import test_lib
|
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
|
|
||||||
class Test_Parser_Compat(unittest.TestCase):
|
def _list_test_cases():
|
||||||
def __init__(self, methodName):
|
ofpps = [ofproto_v1_2_parser, ofproto_v1_3_parser]
|
||||||
print('init %s' % methodName)
|
cases = []
|
||||||
super(Test_Parser_Compat, self).__init__(methodName)
|
for ofpp in ofpps:
|
||||||
|
mod = ofpp.__name__.split('.')[-1]
|
||||||
|
method_name = 'test_' + mod + '_ofpmatch_compat'
|
||||||
|
cases.append({'name': method_name, 'ofpp': ofpp})
|
||||||
|
return cases
|
||||||
|
|
||||||
|
|
||||||
|
class Test_Parser_Compat(testscenarios.WithScenarios, unittest.TestCase):
|
||||||
|
|
||||||
|
scenarios = [(case['name'], case) for case in _list_test_cases()]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
@ -41,6 +47,9 @@ class Test_Parser_Compat(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_parser(self):
|
||||||
|
self._test(name=self.name, ofpp=self.ofpp)
|
||||||
|
|
||||||
def _test(self, name, ofpp):
|
def _test(self, name, ofpp):
|
||||||
ofp = {
|
ofp = {
|
||||||
ofproto_v1_2_parser: ofproto_v1_2,
|
ofproto_v1_2_parser: ofproto_v1_2,
|
||||||
@ -70,17 +79,17 @@ class Test_Parser_Compat(unittest.TestCase):
|
|||||||
return f
|
return f
|
||||||
get_value = lambda m, t: get_field(m, t).value
|
get_value = lambda m, t: get_field(m, t).value
|
||||||
|
|
||||||
eq_(get_value(o, ofpp.MTInPort), old_in_port)
|
self.assertEqual(get_value(o, ofpp.MTInPort), old_in_port)
|
||||||
eq_(get_value(o, ofpp.MTEthSrc), old_eth_src)
|
self.assertEqual(get_value(o, ofpp.MTEthSrc), old_eth_src)
|
||||||
eq_(get_value(o, ofpp.MTIPV4Src), old_ipv4_src)
|
self.assertEqual(get_value(o, ofpp.MTIPV4Src), old_ipv4_src)
|
||||||
eq_(get_value(o, ofpp.MTIPv6Src), old_ipv6_src)
|
self.assertEqual(get_value(o, ofpp.MTIPv6Src), old_ipv6_src)
|
||||||
|
|
||||||
def check_new(o):
|
def check_new(o):
|
||||||
# new api
|
# new api
|
||||||
eq_(o['in_port'], in_port)
|
self.assertEqual(o['in_port'], in_port)
|
||||||
eq_(o['eth_src'], eth_src)
|
self.assertEqual(o['eth_src'], eth_src)
|
||||||
eq_(o['ipv4_src'], ipv4_src)
|
self.assertEqual(o['ipv4_src'], ipv4_src)
|
||||||
eq_(o['ipv6_src'], ipv6_src)
|
self.assertEqual(o['ipv6_src'], ipv6_src)
|
||||||
|
|
||||||
# ensure that old and new api produces the same thing
|
# ensure that old and new api produces the same thing
|
||||||
|
|
||||||
@ -117,43 +126,19 @@ class Test_Parser_Compat(unittest.TestCase):
|
|||||||
|
|
||||||
new_buf = bytearray()
|
new_buf = bytearray()
|
||||||
new.serialize(new_buf, 0)
|
new.serialize(new_buf, 0)
|
||||||
eq_(new_buf, old_buf)
|
self.assertEqual(new_buf, old_buf)
|
||||||
eq_(new_buf, old2_buf)
|
self.assertEqual(new_buf, old2_buf)
|
||||||
|
|
||||||
old_jsondict = old.to_jsondict()
|
old_jsondict = old.to_jsondict()
|
||||||
old2_jsondict = old2.to_jsondict()
|
old2_jsondict = old2.to_jsondict()
|
||||||
new_jsondict = new.to_jsondict()
|
new_jsondict = new.to_jsondict()
|
||||||
eq_(new_jsondict, old_jsondict)
|
self.assertEqual(new_jsondict, old_jsondict)
|
||||||
eq_(new_jsondict, old2_jsondict)
|
self.assertEqual(new_jsondict, old2_jsondict)
|
||||||
|
|
||||||
eq_(str(new), str(old))
|
self.assertEqual(str(new), str(old))
|
||||||
eq_(str(new), str(old2))
|
self.assertEqual(str(new), str(old2))
|
||||||
|
|
||||||
# a parsed object can be inspected by old and new api
|
# a parsed object can be inspected by old and new api
|
||||||
|
|
||||||
check(ofpp.OFPMatch.parser(six.binary_type(new_buf), 0))
|
check(ofpp.OFPMatch.parser(six.binary_type(new_buf), 0))
|
||||||
check(ofpp.OFPMatch.from_jsondict(list(new_jsondict.values())[0]))
|
check(ofpp.OFPMatch.from_jsondict(list(new_jsondict.values())[0]))
|
||||||
|
|
||||||
|
|
||||||
def _add_tests():
|
|
||||||
import functools
|
|
||||||
import itertools
|
|
||||||
|
|
||||||
ofpps = [ofproto_v1_2_parser, ofproto_v1_3_parser]
|
|
||||||
for ofpp in ofpps:
|
|
||||||
mod = ofpp.__name__.split('.')[-1]
|
|
||||||
method_name = 'test_' + mod + '_ofpmatch_compat'
|
|
||||||
|
|
||||||
def _run(self, name, ofpp):
|
|
||||||
print('processing %s ...' % name)
|
|
||||||
if six.PY3:
|
|
||||||
self._test(self, name, ofpp)
|
|
||||||
else:
|
|
||||||
self._test(name, ofpp)
|
|
||||||
print('adding %s ...' % method_name)
|
|
||||||
f = functools.partial(_run, name=method_name,
|
|
||||||
ofpp=ofpp)
|
|
||||||
test_lib.add_method(Test_Parser_Compat, method_name, f)
|
|
||||||
|
|
||||||
|
|
||||||
_add_tests()
|
|
||||||
|
@ -14,17 +14,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
try:
|
import functools
|
||||||
# Python 3
|
import itertools
|
||||||
from functools import reduce
|
|
||||||
except ImportError:
|
|
||||||
# Python 2
|
|
||||||
pass
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
import testscenarios
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.ofproto import ofproto_v1_2
|
from os_ken.ofproto import ofproto_v1_2
|
||||||
from os_ken.ofproto import ofproto_v1_3
|
from os_ken.ofproto import ofproto_v1_3
|
||||||
@ -34,50 +28,9 @@ from os_ken.ofproto import ofproto_v1_2_parser
|
|||||||
from os_ken.ofproto import ofproto_v1_3_parser
|
from os_ken.ofproto import ofproto_v1_3_parser
|
||||||
from os_ken.ofproto import ofproto_v1_4_parser
|
from os_ken.ofproto import ofproto_v1_4_parser
|
||||||
from os_ken.ofproto import ofproto_v1_5_parser
|
from os_ken.ofproto import ofproto_v1_5_parser
|
||||||
from os_ken.tests import test_lib
|
|
||||||
|
|
||||||
|
|
||||||
class Test_Parser_OFPMatch(unittest.TestCase):
|
def _list_test_cases():
|
||||||
_ofp = {ofproto_v1_2_parser: ofproto_v1_2,
|
|
||||||
ofproto_v1_3_parser: ofproto_v1_3,
|
|
||||||
ofproto_v1_4_parser: ofproto_v1_4,
|
|
||||||
ofproto_v1_5_parser: ofproto_v1_5}
|
|
||||||
|
|
||||||
def __init__(self, methodName):
|
|
||||||
print('init %s' % methodName)
|
|
||||||
super(Test_Parser_OFPMatch, self).__init__(methodName)
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _test(self, name, ofpp, d, domask):
|
|
||||||
if domask:
|
|
||||||
d = dict(self._ofp[ofpp].oxm_normalize_user(k, uv)
|
|
||||||
for (k, uv)
|
|
||||||
in d.items())
|
|
||||||
match = ofpp.OFPMatch(**d)
|
|
||||||
b = bytearray()
|
|
||||||
match.serialize(b, 0)
|
|
||||||
match2 = match.parser(six.binary_type(b), 0)
|
|
||||||
for k, v in d.items():
|
|
||||||
ok_(k in match)
|
|
||||||
ok_(k in match2)
|
|
||||||
eq_(match[k], v)
|
|
||||||
eq_(match2[k], v)
|
|
||||||
for k, v in match.iteritems():
|
|
||||||
ok_(k in d)
|
|
||||||
eq_(d[k], v)
|
|
||||||
for k, v in match2.iteritems():
|
|
||||||
ok_(k in d)
|
|
||||||
eq_(d[k], v)
|
|
||||||
|
|
||||||
|
|
||||||
def _add_tests():
|
|
||||||
import functools
|
|
||||||
import itertools
|
|
||||||
|
|
||||||
class Field(object):
|
class Field(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -238,8 +191,9 @@ def _add_tests():
|
|||||||
return l + flatten(i)
|
return l + flatten(i)
|
||||||
else:
|
else:
|
||||||
return l + [i]
|
return l + [i]
|
||||||
flatten = lambda l: reduce(flatten_one, l, [])
|
flatten = lambda l: functools.reduce(flatten_one, l, [])
|
||||||
|
|
||||||
|
cases = []
|
||||||
for ofpp in ofpps:
|
for ofpp in ofpps:
|
||||||
for n in range(1, 3):
|
for n in range(1, 3):
|
||||||
for C in itertools.combinations(L[ofpp], n):
|
for C in itertools.combinations(L[ofpp], n):
|
||||||
@ -272,18 +226,47 @@ def _add_tests():
|
|||||||
method_name = method_name.replace(',', '_')
|
method_name = method_name.replace(',', '_')
|
||||||
method_name = method_name.replace("'", '_')
|
method_name = method_name.replace("'", '_')
|
||||||
method_name = method_name.replace(' ', '_')
|
method_name = method_name.replace(' ', '_')
|
||||||
|
cases.append({'name': method_name, 'ofpp': ofpp,
|
||||||
def _run(self, name, ofpp, d, domask):
|
'd': d, 'domask': domask})
|
||||||
print('processing %s ...' % name)
|
return cases
|
||||||
if six.PY3:
|
|
||||||
self._test(self, name, ofpp, d, domask)
|
|
||||||
else:
|
|
||||||
self._test(name, ofpp, d, domask)
|
|
||||||
print('adding %s ...' % method_name)
|
|
||||||
f = functools.partial(_run, name=method_name,
|
|
||||||
ofpp=ofpp, d=d, domask=domask)
|
|
||||||
test_lib.add_method(Test_Parser_OFPMatch,
|
|
||||||
method_name, f)
|
|
||||||
|
|
||||||
|
|
||||||
_add_tests()
|
class Test_Parser_OFPMatch(testscenarios.WithScenarios, unittest.TestCase):
|
||||||
|
|
||||||
|
scenarios = [(case['name'], case) for case in _list_test_cases()]
|
||||||
|
|
||||||
|
_ofp = {ofproto_v1_2_parser: ofproto_v1_2,
|
||||||
|
ofproto_v1_3_parser: ofproto_v1_3,
|
||||||
|
ofproto_v1_4_parser: ofproto_v1_4,
|
||||||
|
ofproto_v1_5_parser: ofproto_v1_5}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_parser(self):
|
||||||
|
self._test(name=self.name, ofpp=self.ofpp, d=self.d,
|
||||||
|
domask=self.domask)
|
||||||
|
|
||||||
|
def _test(self, name, ofpp, d, domask):
|
||||||
|
if domask:
|
||||||
|
d = dict(self._ofp[ofpp].oxm_normalize_user(k, uv)
|
||||||
|
for (k, uv)
|
||||||
|
in d.items())
|
||||||
|
match = ofpp.OFPMatch(**d)
|
||||||
|
b = bytearray()
|
||||||
|
match.serialize(b, 0)
|
||||||
|
match2 = match.parser(six.binary_type(b), 0)
|
||||||
|
for k, v in d.items():
|
||||||
|
self.assertTrue(k in match)
|
||||||
|
self.assertTrue(k in match2)
|
||||||
|
self.assertEqual(match[k], v)
|
||||||
|
self.assertEqual(match2[k], v)
|
||||||
|
for k, v in match.iteritems():
|
||||||
|
self.assertTrue(k in d)
|
||||||
|
self.assertEqual(d[k], v)
|
||||||
|
for k, v in match2.iteritems():
|
||||||
|
self.assertTrue(k in d)
|
||||||
|
self.assertEqual(d[k], v)
|
||||||
|
@ -13,56 +13,17 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
try:
|
from functools import reduce
|
||||||
# Python 3
|
|
||||||
from functools import reduce
|
|
||||||
except ImportError:
|
|
||||||
# Python 2
|
|
||||||
pass
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
import testscenarios
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.ofproto import ofproto_v1_5
|
from os_ken.ofproto import ofproto_v1_5
|
||||||
from os_ken.ofproto import ofproto_v1_5_parser
|
from os_ken.ofproto import ofproto_v1_5_parser
|
||||||
from os_ken.tests import test_lib
|
|
||||||
|
|
||||||
|
|
||||||
class Test_Parser_OFPStats(unittest.TestCase):
|
def _list_test_cases():
|
||||||
_ofp = {ofproto_v1_5_parser: ofproto_v1_5}
|
|
||||||
|
|
||||||
def __init__(self, methodName):
|
|
||||||
print('init %s' % methodName)
|
|
||||||
super(Test_Parser_OFPStats, self).__init__(methodName)
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _test(self, name, ofpp, d):
|
|
||||||
stats = ofpp.OFPStats(**d)
|
|
||||||
b = bytearray()
|
|
||||||
stats.serialize(b, 0)
|
|
||||||
stats2 = stats.parser(six.binary_type(b), 0)
|
|
||||||
for k, v in d.items():
|
|
||||||
ok_(k in stats)
|
|
||||||
ok_(k in stats2)
|
|
||||||
eq_(stats[k], v)
|
|
||||||
eq_(stats2[k], v)
|
|
||||||
for k, v in stats.iteritems():
|
|
||||||
ok_(k in d)
|
|
||||||
eq_(d[k], v)
|
|
||||||
for k, v in stats2.iteritems():
|
|
||||||
ok_(k in d)
|
|
||||||
eq_(d[k], v)
|
|
||||||
|
|
||||||
|
|
||||||
def _add_tests():
|
|
||||||
import functools
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
@ -159,6 +120,7 @@ def _add_tests():
|
|||||||
return l + [i]
|
return l + [i]
|
||||||
flatten = lambda l: reduce(flatten_one, l, [])
|
flatten = lambda l: reduce(flatten_one, l, [])
|
||||||
|
|
||||||
|
cases = []
|
||||||
for ofpp in ofpps:
|
for ofpp in ofpps:
|
||||||
for n in range(1, 3):
|
for n in range(1, 3):
|
||||||
for C in itertools.combinations(L[ofpp], n):
|
for C in itertools.combinations(L[ofpp], n):
|
||||||
@ -191,18 +153,37 @@ def _add_tests():
|
|||||||
method_name = method_name.replace(',', '_')
|
method_name = method_name.replace(',', '_')
|
||||||
method_name = method_name.replace("'", '_')
|
method_name = method_name.replace("'", '_')
|
||||||
method_name = method_name.replace(' ', '_')
|
method_name = method_name.replace(' ', '_')
|
||||||
|
cases.append({'name': method_name, 'ofpp': ofpp, 'd': d})
|
||||||
def _run(self, name, ofpp, d):
|
return cases
|
||||||
print('processing %s ...' % name)
|
|
||||||
if six.PY3:
|
|
||||||
self._test(self, name, ofpp, d)
|
|
||||||
else:
|
|
||||||
self._test(name, ofpp, d)
|
|
||||||
print('adding %s ...' % method_name)
|
|
||||||
f = functools.partial(_run, name=method_name,
|
|
||||||
ofpp=ofpp, d=d)
|
|
||||||
test_lib.add_method(Test_Parser_OFPStats,
|
|
||||||
method_name, f)
|
|
||||||
|
|
||||||
|
|
||||||
_add_tests()
|
class Test_Parser_OFPStats(testscenarios.WithScenarios, unittest.TestCase):
|
||||||
|
|
||||||
|
scenarios = [(case['name'], case) for case in _list_test_cases()]
|
||||||
|
_ofp = {ofproto_v1_5_parser: ofproto_v1_5}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_parser(self):
|
||||||
|
self._test(name=self.name, ofpp=self.ofpp, d=self.d)
|
||||||
|
|
||||||
|
def _test(self, name, ofpp, d):
|
||||||
|
stats = ofpp.OFPStats(**d)
|
||||||
|
b = bytearray()
|
||||||
|
stats.serialize(b, 0)
|
||||||
|
stats2 = stats.parser(six.binary_type(b), 0)
|
||||||
|
for k, v in d.items():
|
||||||
|
self.assertTrue(k in stats)
|
||||||
|
self.assertTrue(k in stats2)
|
||||||
|
self.assertEqual(stats[k], v)
|
||||||
|
self.assertEqual(stats2[k], v)
|
||||||
|
for k, v in stats.iteritems():
|
||||||
|
self.assertTrue(k in d)
|
||||||
|
self.assertEqual(d[k], v)
|
||||||
|
for k, v in stats2.iteritems():
|
||||||
|
self.assertTrue(k in d)
|
||||||
|
self.assertEqual(d[k], v)
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -20,15 +20,9 @@ import logging
|
|||||||
import six
|
import six
|
||||||
import socket
|
import socket
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto.ofproto_v1_3_parser import *
|
from os_ken.ofproto.ofproto_v1_3_parser import *
|
||||||
from os_ken.ofproto import ofproto_v1_3_parser
|
|
||||||
from os_ken.ofproto import ofproto_v1_3
|
from os_ken.ofproto import ofproto_v1_3
|
||||||
from os_ken.ofproto import ofproto_protocol
|
from os_ken.ofproto import ofproto_protocol
|
||||||
from os_ken.ofproto import ether
|
|
||||||
from os_ken.ofproto.ofproto_parser import MsgBase
|
|
||||||
from os_ken import utils
|
|
||||||
from os_ken.lib import addrconv
|
|
||||||
|
|
||||||
LOG = logging.getLogger('test_ofproto_v13')
|
LOG = logging.getLogger('test_ofproto_v13')
|
||||||
|
|
||||||
@ -45,10 +39,10 @@ class TestOFPMatch(unittest.TestCase):
|
|||||||
res = OFPMatch()
|
res = OFPMatch()
|
||||||
|
|
||||||
# wc check
|
# wc check
|
||||||
eq_(res._wc.vlan_vid_mask, 0)
|
self.assertEqual(res._wc.vlan_vid_mask, 0)
|
||||||
|
|
||||||
# flow check
|
# flow check
|
||||||
eq_(res._flow.vlan_vid, 0)
|
self.assertEqual(res._flow.vlan_vid, 0)
|
||||||
|
|
||||||
def _test_serialize_and_parser(self, match, header, value, mask=None):
|
def _test_serialize_and_parser(self, match, header, value, mask=None):
|
||||||
cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
|
cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
|
||||||
@ -58,34 +52,34 @@ class TestOFPMatch(unittest.TestCase):
|
|||||||
# serialize
|
# serialize
|
||||||
buf = bytearray()
|
buf = bytearray()
|
||||||
length = match.serialize(buf, 0)
|
length = match.serialize(buf, 0)
|
||||||
eq_(length, len(buf))
|
self.assertEqual(length, len(buf))
|
||||||
if mask and len(buf) > calcsize(fmt):
|
if mask and len(buf) > calcsize(fmt):
|
||||||
fmt += pack_str
|
fmt += pack_str
|
||||||
|
|
||||||
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
|
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
|
||||||
if type(value) is list:
|
if type(value) is list:
|
||||||
res_value = res[:calcsize(pack_str) // 2]
|
res_value = res[:calcsize(pack_str) // 2]
|
||||||
eq_(res_value, value)
|
self.assertEqual(res_value, value)
|
||||||
if mask:
|
if mask:
|
||||||
res_mask = res[calcsize(pack_str) // 2:]
|
res_mask = res[calcsize(pack_str) // 2:]
|
||||||
eq_(res_mask, mask)
|
self.assertEqual(res_mask, mask)
|
||||||
else:
|
else:
|
||||||
res_value = res.pop(0)
|
res_value = res.pop(0)
|
||||||
if cls_.__name__ == 'MTVlanVid':
|
if cls_.__name__ == 'MTVlanVid':
|
||||||
eq_(res_value, value | ofproto.OFPVID_PRESENT)
|
self.assertEqual(res_value, value | ofproto.OFPVID_PRESENT)
|
||||||
else:
|
else:
|
||||||
eq_(res_value, value)
|
self.assertEqual(res_value, value)
|
||||||
if mask and res and res[0]:
|
if mask and res and res[0]:
|
||||||
res_mask = res[0]
|
res_mask = res[0]
|
||||||
eq_(res_mask, mask)
|
self.assertEqual(res_mask, mask)
|
||||||
|
|
||||||
# parser
|
# parser
|
||||||
res = match.parser(six.binary_type(buf), 0)
|
res = match.parser(six.binary_type(buf), 0)
|
||||||
eq_(res.type, ofproto.OFPMT_OXM)
|
self.assertEqual(res.type, ofproto.OFPMT_OXM)
|
||||||
eq_(res.fields[0].header, header)
|
self.assertEqual(res.fields[0].header, header)
|
||||||
eq_(res.fields[0].value, value)
|
self.assertEqual(res.fields[0].value, value)
|
||||||
if mask and res.fields[0].mask is not None:
|
if mask and res.fields[0].mask is not None:
|
||||||
eq_(res.fields[0].mask, mask)
|
self.assertEqual(res.fields[0].mask, mask)
|
||||||
|
|
||||||
# to_jsondict
|
# to_jsondict
|
||||||
jsondict = match.to_jsondict()
|
jsondict = match.to_jsondict()
|
||||||
@ -94,8 +88,8 @@ class TestOFPMatch(unittest.TestCase):
|
|||||||
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
||||||
buf2 = bytearray()
|
buf2 = bytearray()
|
||||||
match2.serialize(buf2, 0)
|
match2.serialize(buf2, 0)
|
||||||
eq_(str(match), str(match2))
|
self.assertEqual(str(match), str(match2))
|
||||||
eq_(buf, buf2)
|
self.assertEqual(buf, buf2)
|
||||||
|
|
||||||
# set_vlan_vid
|
# set_vlan_vid
|
||||||
def _test_set_vlan_vid(self, vid, mask=None):
|
def _test_set_vlan_vid(self, vid, mask=None):
|
||||||
@ -120,17 +114,17 @@ class TestOFPMatch(unittest.TestCase):
|
|||||||
# serialize
|
# serialize
|
||||||
buf = bytearray()
|
buf = bytearray()
|
||||||
length = match.serialize(buf, 0)
|
length = match.serialize(buf, 0)
|
||||||
eq_(length, len(buf))
|
self.assertEqual(length, len(buf))
|
||||||
|
|
||||||
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
|
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
|
||||||
res_value = res.pop(0)
|
res_value = res.pop(0)
|
||||||
eq_(res_value, value)
|
self.assertEqual(res_value, value)
|
||||||
|
|
||||||
# parser
|
# parser
|
||||||
res = match.parser(six.binary_type(buf), 0)
|
res = match.parser(six.binary_type(buf), 0)
|
||||||
eq_(res.type, ofproto.OFPMT_OXM)
|
self.assertEqual(res.type, ofproto.OFPMT_OXM)
|
||||||
eq_(res.fields[0].header, header)
|
self.assertEqual(res.fields[0].header, header)
|
||||||
eq_(res.fields[0].value, value)
|
self.assertEqual(res.fields[0].value, value)
|
||||||
|
|
||||||
# to_jsondict
|
# to_jsondict
|
||||||
jsondict = match.to_jsondict()
|
jsondict = match.to_jsondict()
|
||||||
@ -139,8 +133,8 @@ class TestOFPMatch(unittest.TestCase):
|
|||||||
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
||||||
buf2 = bytearray()
|
buf2 = bytearray()
|
||||||
match2.serialize(buf2, 0)
|
match2.serialize(buf2, 0)
|
||||||
eq_(str(match), str(match2))
|
self.assertEqual(str(match), str(match2))
|
||||||
eq_(buf, buf2)
|
self.assertEqual(buf, buf2)
|
||||||
|
|
||||||
def test_set_vlan_vid_mid(self):
|
def test_set_vlan_vid_mid(self):
|
||||||
self._test_set_vlan_vid(2047)
|
self._test_set_vlan_vid(2047)
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
from os_ken.lib.packet.packet import Packet
|
from os_ken.lib.packet.packet import Packet
|
||||||
@ -67,15 +66,15 @@ class Test_arp(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.hwtype, self.a.hwtype)
|
self.assertEqual(self.hwtype, self.a.hwtype)
|
||||||
eq_(self.proto, self.a.proto)
|
self.assertEqual(self.proto, self.a.proto)
|
||||||
eq_(self.hlen, self.a.hlen)
|
self.assertEqual(self.hlen, self.a.hlen)
|
||||||
eq_(self.plen, self.a.plen)
|
self.assertEqual(self.plen, self.a.plen)
|
||||||
eq_(self.opcode, self.a.opcode)
|
self.assertEqual(self.opcode, self.a.opcode)
|
||||||
eq_(self.src_mac, self.a.src_mac)
|
self.assertEqual(self.src_mac, self.a.src_mac)
|
||||||
eq_(self.src_ip, self.a.src_ip)
|
self.assertEqual(self.src_ip, self.a.src_ip)
|
||||||
eq_(self.dst_mac, self.a.dst_mac)
|
self.assertEqual(self.dst_mac, self.a.dst_mac)
|
||||||
eq_(self.dst_ip, self.a.dst_ip)
|
self.assertEqual(self.dst_ip, self.a.dst_ip)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = self.a.parser(self.buf)
|
_res = self.a.parser(self.buf)
|
||||||
@ -84,15 +83,15 @@ class Test_arp(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res.hwtype, self.hwtype)
|
self.assertEqual(res.hwtype, self.hwtype)
|
||||||
eq_(res.proto, self.proto)
|
self.assertEqual(res.proto, self.proto)
|
||||||
eq_(res.hlen, self.hlen)
|
self.assertEqual(res.hlen, self.hlen)
|
||||||
eq_(res.plen, self.plen)
|
self.assertEqual(res.plen, self.plen)
|
||||||
eq_(res.opcode, self.opcode)
|
self.assertEqual(res.opcode, self.opcode)
|
||||||
eq_(res.src_mac, self.src_mac)
|
self.assertEqual(res.src_mac, self.src_mac)
|
||||||
eq_(res.src_ip, self.src_ip)
|
self.assertEqual(res.src_ip, self.src_ip)
|
||||||
eq_(res.dst_mac, self.dst_mac)
|
self.assertEqual(res.dst_mac, self.dst_mac)
|
||||||
eq_(res.dst_ip, self.dst_ip)
|
self.assertEqual(res.dst_ip, self.dst_ip)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -102,15 +101,15 @@ class Test_arp(unittest.TestCase):
|
|||||||
fmt = arp._PACK_STR
|
fmt = arp._PACK_STR
|
||||||
res = struct.unpack(fmt, buf)
|
res = struct.unpack(fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.hwtype)
|
self.assertEqual(res[0], self.hwtype)
|
||||||
eq_(res[1], self.proto)
|
self.assertEqual(res[1], self.proto)
|
||||||
eq_(res[2], self.hlen)
|
self.assertEqual(res[2], self.hlen)
|
||||||
eq_(res[3], self.plen)
|
self.assertEqual(res[3], self.plen)
|
||||||
eq_(res[4], self.opcode)
|
self.assertEqual(res[4], self.opcode)
|
||||||
eq_(res[5], addrconv.mac.text_to_bin(self.src_mac))
|
self.assertEqual(res[5], addrconv.mac.text_to_bin(self.src_mac))
|
||||||
eq_(res[6], addrconv.ipv4.text_to_bin(self.src_ip))
|
self.assertEqual(res[6], addrconv.ipv4.text_to_bin(self.src_ip))
|
||||||
eq_(res[7], addrconv.mac.text_to_bin(self.dst_mac))
|
self.assertEqual(res[7], addrconv.mac.text_to_bin(self.dst_mac))
|
||||||
eq_(res[8], addrconv.ipv4.text_to_bin(self.dst_ip))
|
self.assertEqual(res[8], addrconv.ipv4.text_to_bin(self.dst_ip))
|
||||||
|
|
||||||
def _build_arp(self, vlan_enabled):
|
def _build_arp(self, vlan_enabled):
|
||||||
if vlan_enabled is True:
|
if vlan_enabled is True:
|
||||||
@ -132,52 +131,51 @@ class Test_arp(unittest.TestCase):
|
|||||||
p = self._build_arp(True)
|
p = self._build_arp(True)
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_8021Q)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||||
|
|
||||||
v = self.find_protocol(p, "vlan")
|
v = self.find_protocol(p, "vlan")
|
||||||
ok_(v)
|
self.assertTrue(v)
|
||||||
eq_(v.ethertype, ether.ETH_TYPE_ARP)
|
self.assertEqual(v.ethertype, ether.ETH_TYPE_ARP)
|
||||||
|
|
||||||
a = self.find_protocol(p, "arp")
|
a = self.find_protocol(p, "arp")
|
||||||
ok_(a)
|
self.assertTrue(a)
|
||||||
|
|
||||||
eq_(a.hwtype, self.hwtype)
|
self.assertEqual(a.hwtype, self.hwtype)
|
||||||
eq_(a.proto, self.proto)
|
self.assertEqual(a.proto, self.proto)
|
||||||
eq_(a.hlen, self.hlen)
|
self.assertEqual(a.hlen, self.hlen)
|
||||||
eq_(a.plen, self.plen)
|
self.assertEqual(a.plen, self.plen)
|
||||||
eq_(a.opcode, self.opcode)
|
self.assertEqual(a.opcode, self.opcode)
|
||||||
eq_(a.src_mac, self.src_mac)
|
self.assertEqual(a.src_mac, self.src_mac)
|
||||||
eq_(a.src_ip, self.src_ip)
|
self.assertEqual(a.src_ip, self.src_ip)
|
||||||
eq_(a.dst_mac, self.dst_mac)
|
self.assertEqual(a.dst_mac, self.dst_mac)
|
||||||
eq_(a.dst_ip, self.dst_ip)
|
self.assertEqual(a.dst_ip, self.dst_ip)
|
||||||
|
|
||||||
def test_build_arp_novlan(self):
|
def test_build_arp_novlan(self):
|
||||||
p = self._build_arp(False)
|
p = self._build_arp(False)
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_ARP)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_ARP)
|
||||||
|
|
||||||
a = self.find_protocol(p, "arp")
|
a = self.find_protocol(p, "arp")
|
||||||
ok_(a)
|
self.assertTrue(a)
|
||||||
|
|
||||||
eq_(a.hwtype, self.hwtype)
|
self.assertEqual(a.hwtype, self.hwtype)
|
||||||
eq_(a.proto, self.proto)
|
self.assertEqual(a.proto, self.proto)
|
||||||
eq_(a.hlen, self.hlen)
|
self.assertEqual(a.hlen, self.hlen)
|
||||||
eq_(a.plen, self.plen)
|
self.assertEqual(a.plen, self.plen)
|
||||||
eq_(a.opcode, self.opcode)
|
self.assertEqual(a.opcode, self.opcode)
|
||||||
eq_(a.src_mac, self.src_mac)
|
self.assertEqual(a.src_mac, self.src_mac)
|
||||||
eq_(a.src_ip, self.src_ip)
|
self.assertEqual(a.src_ip, self.src_ip)
|
||||||
eq_(a.dst_mac, self.dst_mac)
|
self.assertEqual(a.dst_mac, self.dst_mac)
|
||||||
eq_(a.dst_ip, self.dst_ip)
|
self.assertEqual(a.dst_ip, self.dst_ip)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_arp(self):
|
def test_malformed_arp(self):
|
||||||
m_short_buf = self.buf[1:arp._MIN_LEN]
|
m_short_buf = self.buf[1:arp._MIN_LEN]
|
||||||
arp.parser(m_short_buf)
|
self.assertRaises(Exception, arp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.a.to_jsondict()
|
jsondict = self.a.to_jsondict()
|
||||||
a = arp.from_jsondict(jsondict['arp'])
|
a = arp.from_jsondict(jsondict['arp'])
|
||||||
eq_(str(self.a), str(a))
|
self.assertEqual(str(self.a), str(a))
|
||||||
|
@ -17,7 +17,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
import inspect
|
import inspect
|
||||||
from nose.tools import ok_, eq_, nottest
|
|
||||||
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.ofproto import inet
|
from os_ken.ofproto import inet
|
||||||
@ -95,52 +94,52 @@ class TestBFD(unittest.TestCase):
|
|||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
eq_(type(next(i)), ipv4.ipv4)
|
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||||
eq_(type(next(i)), udp.udp)
|
self.assertEqual(type(next(i)), udp.udp)
|
||||||
eq_(type(bfd.bfd.parser(next(i))[0]), bfd.bfd)
|
self.assertEqual(type(bfd.bfd.parser(next(i))[0]), bfd.bfd)
|
||||||
|
|
||||||
def test_parse_with_auth_simple(self):
|
def test_parse_with_auth_simple(self):
|
||||||
buf = self.data_auth_simple
|
buf = self.data_auth_simple
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
eq_(type(next(i)), ipv4.ipv4)
|
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||||
eq_(type(next(i)), udp.udp)
|
self.assertEqual(type(next(i)), udp.udp)
|
||||||
|
|
||||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||||
eq_(type(bfd_obj), bfd.bfd)
|
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||||
eq_(type(bfd_obj.auth_cls), bfd.SimplePassword)
|
self.assertEqual(type(bfd_obj.auth_cls), bfd.SimplePassword)
|
||||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||||
|
|
||||||
def test_parse_with_auth_md5(self):
|
def test_parse_with_auth_md5(self):
|
||||||
buf = self.data_auth_md5
|
buf = self.data_auth_md5
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
eq_(type(next(i)), ipv4.ipv4)
|
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||||
eq_(type(next(i)), udp.udp)
|
self.assertEqual(type(next(i)), udp.udp)
|
||||||
|
|
||||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||||
eq_(type(bfd_obj), bfd.bfd)
|
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||||
eq_(type(bfd_obj.auth_cls), bfd.KeyedMD5)
|
self.assertEqual(type(bfd_obj.auth_cls), bfd.KeyedMD5)
|
||||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||||
|
|
||||||
def test_parse_with_auth_sha1(self):
|
def test_parse_with_auth_sha1(self):
|
||||||
buf = self.data_auth_sha1
|
buf = self.data_auth_sha1
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
eq_(type(next(i)), ipv4.ipv4)
|
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||||
eq_(type(next(i)), udp.udp)
|
self.assertEqual(type(next(i)), udp.udp)
|
||||||
|
|
||||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||||
eq_(type(bfd_obj), bfd.bfd)
|
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||||
eq_(type(bfd_obj.auth_cls), bfd.KeyedSHA1)
|
self.assertEqual(type(bfd_obj.auth_cls), bfd.KeyedSHA1)
|
||||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
pkt = packet.Packet()
|
pkt = packet.Packet()
|
||||||
@ -162,10 +161,10 @@ class TestBFD(unittest.TestCase):
|
|||||||
required_min_echo_rx_interval=0)
|
required_min_echo_rx_interval=0)
|
||||||
pkt.add_protocol(bfd_pkt)
|
pkt.add_protocol(bfd_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 4)
|
self.assertEqual(len(pkt.protocols), 4)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(pkt.data, self.data)
|
self.assertEqual(pkt.data, self.data)
|
||||||
|
|
||||||
def test_serialize_with_auth_simple(self):
|
def test_serialize_with_auth_simple(self):
|
||||||
pkt = packet.Packet()
|
pkt = packet.Packet()
|
||||||
@ -193,10 +192,10 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
pkt.add_protocol(bfd_pkt)
|
pkt.add_protocol(bfd_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 4)
|
self.assertEqual(len(pkt.protocols), 4)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(pkt.data, self.data_auth_simple)
|
self.assertEqual(pkt.data, self.data_auth_simple)
|
||||||
|
|
||||||
def test_serialize_with_auth_md5(self):
|
def test_serialize_with_auth_md5(self):
|
||||||
pkt = packet.Packet()
|
pkt = packet.Packet()
|
||||||
@ -224,10 +223,10 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
pkt.add_protocol(bfd_pkt)
|
pkt.add_protocol(bfd_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 4)
|
self.assertEqual(len(pkt.protocols), 4)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(pkt.data, self.data_auth_md5)
|
self.assertEqual(pkt.data, self.data_auth_md5)
|
||||||
|
|
||||||
def test_serialize_with_auth_sha1(self):
|
def test_serialize_with_auth_sha1(self):
|
||||||
pkt = packet.Packet()
|
pkt = packet.Packet()
|
||||||
@ -255,10 +254,10 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
pkt.add_protocol(bfd_pkt)
|
pkt.add_protocol(bfd_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 4)
|
self.assertEqual(len(pkt.protocols), 4)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(pkt.data, self.data_auth_sha1)
|
self.assertEqual(pkt.data, self.data_auth_sha1)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
|
bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
|
||||||
@ -269,7 +268,7 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
jsondict = bfd1.to_jsondict()
|
jsondict = bfd1.to_jsondict()
|
||||||
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
||||||
eq_(str(bfd1), str(bfd2))
|
self.assertEqual(str(bfd1), str(bfd2))
|
||||||
|
|
||||||
def test_json_with_auth_simple(self):
|
def test_json_with_auth_simple(self):
|
||||||
auth_cls = bfd.SimplePassword(auth_key_id=2,
|
auth_cls = bfd.SimplePassword(auth_key_id=2,
|
||||||
@ -285,7 +284,7 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
jsondict = bfd1.to_jsondict()
|
jsondict = bfd1.to_jsondict()
|
||||||
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
||||||
eq_(str(bfd1), str(bfd2))
|
self.assertEqual(str(bfd1), str(bfd2))
|
||||||
|
|
||||||
def test_json_with_auth_md5(self):
|
def test_json_with_auth_md5(self):
|
||||||
auth_cls = bfd.KeyedMD5(auth_key_id=2, seq=16859,
|
auth_cls = bfd.KeyedMD5(auth_key_id=2, seq=16859,
|
||||||
@ -301,7 +300,7 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
jsondict = bfd1.to_jsondict()
|
jsondict = bfd1.to_jsondict()
|
||||||
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
||||||
eq_(str(bfd1), str(bfd2))
|
self.assertEqual(str(bfd1), str(bfd2))
|
||||||
|
|
||||||
def test_json_with_auth_sha1(self):
|
def test_json_with_auth_sha1(self):
|
||||||
auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16859,
|
auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16859,
|
||||||
@ -317,4 +316,4 @@ class TestBFD(unittest.TestCase):
|
|||||||
|
|
||||||
jsondict = bfd1.to_jsondict()
|
jsondict = bfd1.to_jsondict()
|
||||||
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
|
||||||
eq_(str(bfd1), str(bfd2))
|
self.assertEqual(str(bfd1), str(bfd2))
|
||||||
|
@ -19,8 +19,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.utils import binary_str
|
from os_ken.utils import binary_str
|
||||||
from os_ken.lib import pcaplib
|
from os_ken.lib import pcaplib
|
||||||
@ -150,9 +148,9 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.1')
|
msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.1')
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(len(msg), 29)
|
self.assertEqual(len(msg), 29)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_open2(self):
|
def test_open2(self):
|
||||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||||
@ -172,17 +170,17 @@ class Test_bgp(unittest.TestCase):
|
|||||||
opt_param=opt_param)
|
opt_param=opt_param)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
ok_(len(msg) > 29)
|
self.assertTrue(len(msg) > 29)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_update1(self):
|
def test_update1(self):
|
||||||
msg = bgp.BGPUpdate()
|
msg = bgp.BGPUpdate()
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(len(msg), 23)
|
self.assertEqual(len(msg), 23)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_update2(self):
|
def test_update2(self):
|
||||||
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
||||||
@ -313,34 +311,34 @@ class Test_bgp(unittest.TestCase):
|
|||||||
nlri=nlri)
|
nlri=nlri)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
ok_(len(msg) > 23)
|
self.assertTrue(len(msg) > 23)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_keepalive(self):
|
def test_keepalive(self):
|
||||||
msg = bgp.BGPKeepAlive()
|
msg = bgp.BGPKeepAlive()
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(len(msg), 19)
|
self.assertEqual(len(msg), 19)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_notification(self):
|
def test_notification(self):
|
||||||
data = b'hoge'
|
data = b'hoge'
|
||||||
msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
|
msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(len(msg), 21 + len(data))
|
self.assertEqual(len(msg), 21 + len(data))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_route_refresh(self):
|
def test_route_refresh(self):
|
||||||
msg = bgp.BGPRouteRefresh(afi=afi.IP, safi=safi.MPLS_VPN)
|
msg = bgp.BGPRouteRefresh(afi=afi.IP, safi=safi.MPLS_VPN)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(len(msg), 23)
|
self.assertEqual(len(msg), 23)
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_stream_parser(self):
|
def test_stream_parser(self):
|
||||||
msgs = [
|
msgs = [
|
||||||
@ -354,7 +352,7 @@ class Test_bgp(unittest.TestCase):
|
|||||||
for b in binmsgs:
|
for b in binmsgs:
|
||||||
for m in sp.parse(b):
|
for m in sp.parse(b):
|
||||||
results.append(m)
|
results.append(m)
|
||||||
eq_(str(results), str(msgs))
|
self.assertEqual(str(results), str(msgs))
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
files = [
|
files = [
|
||||||
@ -391,12 +389,12 @@ class Test_bgp(unittest.TestCase):
|
|||||||
open(BGP4_PACKET_DATA_DIR + f + '.pcap', 'rb')):
|
open(BGP4_PACKET_DATA_DIR + f + '.pcap', 'rb')):
|
||||||
# Checks if BGP message can be parsed as expected.
|
# Checks if BGP message can be parsed as expected.
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
ok_(isinstance(pkt.protocols[-1], bgp.BGPMessage),
|
self.assertTrue(isinstance(pkt.protocols[-1], bgp.BGPMessage),
|
||||||
'Failed to parse BGP message: %s' % pkt)
|
'Failed to parse BGP message: %s' % pkt)
|
||||||
|
|
||||||
# Checks if BGP message can be serialized as expected.
|
# Checks if BGP message can be serialized as expected.
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(buf, pkt.data,
|
self.assertEqual(buf, pkt.data,
|
||||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||||
|
|
||||||
def test_vlan_action_parser(self):
|
def test_vlan_action_parser(self):
|
||||||
@ -411,8 +409,8 @@ class Test_bgp(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
binmsg = action.serialize()
|
binmsg = action.serialize()
|
||||||
msg, rest = bgp.BGPFlowSpecVlanActionCommunity.parse(binmsg)
|
msg, rest = bgp.BGPFlowSpecVlanActionCommunity.parse(binmsg)
|
||||||
eq_(str(action), str(msg))
|
self.assertEqual(str(action), str(msg))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_tpid_action_parser(self):
|
def test_tpid_action_parser(self):
|
||||||
action = bgp.BGPFlowSpecTPIDActionCommunity(
|
action = bgp.BGPFlowSpecTPIDActionCommunity(
|
||||||
@ -423,8 +421,8 @@ class Test_bgp(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
binmsg = action.serialize()
|
binmsg = action.serialize()
|
||||||
msg, rest = bgp.BGPFlowSpecTPIDActionCommunity.parse(binmsg)
|
msg, rest = bgp.BGPFlowSpecTPIDActionCommunity.parse(binmsg)
|
||||||
eq_(str(action), str(msg))
|
self.assertEqual(str(action), str(msg))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_json1(self):
|
def test_json1(self):
|
||||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||||
@ -439,7 +437,7 @@ class Test_bgp(unittest.TestCase):
|
|||||||
opt_param=opt_param)
|
opt_param=opt_param)
|
||||||
jsondict = msg1.to_jsondict()
|
jsondict = msg1.to_jsondict()
|
||||||
msg2 = bgp.BGPOpen.from_jsondict(jsondict['BGPOpen'])
|
msg2 = bgp.BGPOpen.from_jsondict(jsondict['BGPOpen'])
|
||||||
eq_(str(msg1), str(msg2))
|
self.assertEqual(str(msg1), str(msg2))
|
||||||
|
|
||||||
def test_json2(self):
|
def test_json2(self):
|
||||||
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
||||||
@ -568,7 +566,7 @@ class Test_bgp(unittest.TestCase):
|
|||||||
nlri=nlri)
|
nlri=nlri)
|
||||||
jsondict = msg1.to_jsondict()
|
jsondict = msg1.to_jsondict()
|
||||||
msg2 = bgp.BGPUpdate.from_jsondict(jsondict['BGPUpdate'])
|
msg2 = bgp.BGPUpdate.from_jsondict(jsondict['BGPUpdate'])
|
||||||
eq_(str(msg1), str(msg2))
|
self.assertEqual(str(msg1), str(msg2))
|
||||||
|
|
||||||
def test_flowspec_user_interface_ipv4(self):
|
def test_flowspec_user_interface_ipv4(self):
|
||||||
rules = RULES_BASE + [
|
rules = RULES_BASE + [
|
||||||
@ -614,11 +612,11 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg2 = bgp.FlowSpecIPv4NLRI(rules=rules)
|
msg2 = bgp.FlowSpecIPv4NLRI(rules=rules)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
binmsg2 = msg2.serialize()
|
binmsg2 = msg2.serialize()
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||||
msg3, rest = bgp.FlowSpecIPv4NLRI.parser(binmsg)
|
msg3, rest = bgp.FlowSpecIPv4NLRI.parser(binmsg)
|
||||||
eq_(str(msg), str(msg3))
|
self.assertEqual(str(msg), str(msg3))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_flowspec_user_interface_vpv4(self):
|
def test_flowspec_user_interface_vpv4(self):
|
||||||
rules = RULES_BASE + [
|
rules = RULES_BASE + [
|
||||||
@ -664,11 +662,11 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg2 = bgp.FlowSpecVPNv4NLRI(route_dist='65001:250', rules=rules)
|
msg2 = bgp.FlowSpecVPNv4NLRI(route_dist='65001:250', rules=rules)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
binmsg2 = msg2.serialize()
|
binmsg2 = msg2.serialize()
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||||
msg3, rest = bgp.FlowSpecVPNv4NLRI.parser(binmsg)
|
msg3, rest = bgp.FlowSpecVPNv4NLRI.parser(binmsg)
|
||||||
eq_(str(msg), str(msg3))
|
self.assertEqual(str(msg), str(msg3))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_flowspec_user_interface_ipv6(self):
|
def test_flowspec_user_interface_ipv6(self):
|
||||||
rules = RULES_BASE + [
|
rules = RULES_BASE + [
|
||||||
@ -721,11 +719,11 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg2 = bgp.FlowSpecIPv6NLRI(rules=rules)
|
msg2 = bgp.FlowSpecIPv6NLRI(rules=rules)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
binmsg2 = msg2.serialize()
|
binmsg2 = msg2.serialize()
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||||
msg3, rest = bgp.FlowSpecIPv6NLRI.parser(binmsg)
|
msg3, rest = bgp.FlowSpecIPv6NLRI.parser(binmsg)
|
||||||
eq_(str(msg), str(msg3))
|
self.assertEqual(str(msg), str(msg3))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_flowspec_user_interface_vpnv6(self):
|
def test_flowspec_user_interface_vpnv6(self):
|
||||||
rules = RULES_BASE + [
|
rules = RULES_BASE + [
|
||||||
@ -779,11 +777,11 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg2 = bgp.FlowSpecVPNv6NLRI(route_dist='65001:250', rules=rules)
|
msg2 = bgp.FlowSpecVPNv6NLRI(route_dist='65001:250', rules=rules)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
binmsg2 = msg2.serialize()
|
binmsg2 = msg2.serialize()
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||||
msg3, rest = bgp.FlowSpecVPNv6NLRI.parser(binmsg)
|
msg3, rest = bgp.FlowSpecVPNv6NLRI.parser(binmsg)
|
||||||
eq_(str(msg), str(msg3))
|
self.assertEqual(str(msg), str(msg3))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_flowspec_user_interface_l2vpn(self):
|
def test_flowspec_user_interface_l2vpn(self):
|
||||||
rules = RULES_L2VPN_BASE
|
rules = RULES_L2VPN_BASE
|
||||||
@ -804,8 +802,8 @@ class Test_bgp(unittest.TestCase):
|
|||||||
msg2 = bgp.FlowSpecL2VPNNLRI(route_dist='65001:250', rules=rules)
|
msg2 = bgp.FlowSpecL2VPNNLRI(route_dist='65001:250', rules=rules)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
binmsg2 = msg2.serialize()
|
binmsg2 = msg2.serialize()
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||||
msg3, rest = bgp.FlowSpecL2VPNNLRI.parser(binmsg)
|
msg3, rest = bgp.FlowSpecL2VPNNLRI.parser(binmsg)
|
||||||
eq_(str(msg), str(msg3))
|
self.assertEqual(str(msg), str(msg3))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from os_ken.lib.packet import bmp
|
from os_ken.lib.packet import bmp
|
||||||
@ -51,8 +49,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
timestamp=self._time())
|
timestamp=self._time())
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_route_monitoring_adj_rib_out(self):
|
def test_route_monitoring_adj_rib_out(self):
|
||||||
update = bgp.BGPUpdate()
|
update = bgp.BGPUpdate()
|
||||||
@ -67,8 +65,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
timestamp=self._time())
|
timestamp=self._time())
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_statistics_report(self):
|
def test_statistics_report(self):
|
||||||
stats = [{'type': bmp.BMP_STAT_TYPE_REJECTED, 'value': 100},
|
stats = [{'type': bmp.BMP_STAT_TYPE_REJECTED, 'value': 100},
|
||||||
@ -89,8 +87,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
timestamp=self._time())
|
timestamp=self._time())
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_peer_down_notification(self):
|
def test_peer_down_notification(self):
|
||||||
reason = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
|
reason = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
|
||||||
@ -106,8 +104,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
timestamp=self._time())
|
timestamp=self._time())
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_peer_up_notification(self):
|
def test_peer_up_notification(self):
|
||||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||||
@ -131,8 +129,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
timestamp=self._time())
|
timestamp=self._time())
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_initiation(self):
|
def test_initiation(self):
|
||||||
initiation_info = [{'type': bmp.BMP_INIT_TYPE_STRING,
|
initiation_info = [{'type': bmp.BMP_INIT_TYPE_STRING,
|
||||||
@ -140,8 +138,8 @@ class Test_bmp(unittest.TestCase):
|
|||||||
msg = bmp.BMPInitiation(info=initiation_info)
|
msg = bmp.BMPInitiation(info=initiation_info)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
self.assertEqual(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_termination(self):
|
def test_termination(self):
|
||||||
termination_info = [{'type': bmp.BMP_TERM_TYPE_STRING,
|
termination_info = [{'type': bmp.BMP_TERM_TYPE_STRING,
|
||||||
@ -151,5 +149,5 @@ class Test_bmp(unittest.TestCase):
|
|||||||
msg = bmp.BMPTermination(info=termination_info)
|
msg = bmp.BMPTermination(info=termination_info)
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||||
eq_(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
self.assertEqual(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.lib.packet import bpdu
|
from os_ken.lib.packet import bpdu
|
||||||
|
|
||||||
|
|
||||||
@ -92,48 +91,48 @@ class Test_ConfigurationBPDUs(unittest.TestCase):
|
|||||||
self.forward_delay))
|
self.forward_delay))
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.protocol_id, self.msg._protocol_id)
|
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||||
eq_(self.version_id, self.msg._version_id)
|
self.assertEqual(self.version_id, self.msg._version_id)
|
||||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||||
eq_(self.flags, self.msg.flags)
|
self.assertEqual(self.flags, self.msg.flags)
|
||||||
eq_(self.root_priority, self.msg.root_priority)
|
self.assertEqual(self.root_priority, self.msg.root_priority)
|
||||||
eq_(self.root_system_id_extension,
|
self.assertEqual(self.root_system_id_extension,
|
||||||
self.msg.root_system_id_extension)
|
self.msg.root_system_id_extension)
|
||||||
eq_(self.root_mac_address, self.msg.root_mac_address)
|
self.assertEqual(self.root_mac_address, self.msg.root_mac_address)
|
||||||
eq_(self.root_path_cost, self.msg.root_path_cost)
|
self.assertEqual(self.root_path_cost, self.msg.root_path_cost)
|
||||||
eq_(self.bridge_priority, self.msg.bridge_priority)
|
self.assertEqual(self.bridge_priority, self.msg.bridge_priority)
|
||||||
eq_(self.bridge_system_id_extension,
|
self.assertEqual(self.bridge_system_id_extension,
|
||||||
self.msg.bridge_system_id_extension)
|
self.msg.bridge_system_id_extension)
|
||||||
eq_(self.bridge_mac_address, self.msg.bridge_mac_address)
|
self.assertEqual(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||||
eq_(self.port_priority, self.msg.port_priority)
|
self.assertEqual(self.port_priority, self.msg.port_priority)
|
||||||
eq_(self.port_number, self.msg.port_number)
|
self.assertEqual(self.port_number, self.msg.port_number)
|
||||||
eq_(self.message_age, self.msg.message_age)
|
self.assertEqual(self.message_age, self.msg.message_age)
|
||||||
eq_(self.max_age, self.msg.max_age)
|
self.assertEqual(self.max_age, self.msg.max_age)
|
||||||
eq_(self.hello_time, self.msg.hello_time)
|
self.assertEqual(self.hello_time, self.msg.hello_time)
|
||||||
eq_(self.forward_delay, self.msg.forward_delay)
|
self.assertEqual(self.forward_delay, self.msg.forward_delay)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||||
|
|
||||||
eq_(type(r1), type(self.msg))
|
self.assertEqual(type(r1), type(self.msg))
|
||||||
eq_(r1._protocol_id, self.protocol_id)
|
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||||
eq_(r1._version_id, self.version_id)
|
self.assertEqual(r1._version_id, self.version_id)
|
||||||
eq_(r1._bpdu_type, self.bpdu_type)
|
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||||
eq_(r1.flags, self.flags)
|
self.assertEqual(r1.flags, self.flags)
|
||||||
eq_(r1.root_priority, self.root_priority)
|
self.assertEqual(r1.root_priority, self.root_priority)
|
||||||
eq_(r1.root_system_id_extension, self.root_system_id_extension)
|
self.assertEqual(r1.root_system_id_extension, self.root_system_id_extension)
|
||||||
eq_(r1.root_mac_address, self.root_mac_address)
|
self.assertEqual(r1.root_mac_address, self.root_mac_address)
|
||||||
eq_(r1.root_path_cost, self.root_path_cost)
|
self.assertEqual(r1.root_path_cost, self.root_path_cost)
|
||||||
eq_(r1.bridge_priority, self.bridge_priority)
|
self.assertEqual(r1.bridge_priority, self.bridge_priority)
|
||||||
eq_(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
self.assertEqual(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||||
eq_(r1.bridge_mac_address, self.bridge_mac_address)
|
self.assertEqual(r1.bridge_mac_address, self.bridge_mac_address)
|
||||||
eq_(r1.port_priority, self.port_priority)
|
self.assertEqual(r1.port_priority, self.port_priority)
|
||||||
eq_(r1.port_number, self.port_number)
|
self.assertEqual(r1.port_number, self.port_number)
|
||||||
eq_(r1.message_age, self.message_age)
|
self.assertEqual(r1.message_age, self.message_age)
|
||||||
eq_(r1.max_age, self.max_age)
|
self.assertEqual(r1.max_age, self.max_age)
|
||||||
eq_(r1.hello_time, self.hello_time)
|
self.assertEqual(r1.hello_time, self.hello_time)
|
||||||
eq_(r1.forward_delay, self.forward_delay)
|
self.assertEqual(r1.forward_delay, self.forward_delay)
|
||||||
eq_(r2, None)
|
self.assertEqual(r2, None)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -141,32 +140,32 @@ class Test_ConfigurationBPDUs(unittest.TestCase):
|
|||||||
buf = self.msg.serialize(data, prev)
|
buf = self.msg.serialize(data, prev)
|
||||||
res = struct.unpack(self.fmt, buf)
|
res = struct.unpack(self.fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.protocol_id)
|
self.assertEqual(res[0], self.protocol_id)
|
||||||
eq_(res[1], self.version_id)
|
self.assertEqual(res[1], self.version_id)
|
||||||
eq_(res[2], self.bpdu_type)
|
self.assertEqual(res[2], self.bpdu_type)
|
||||||
eq_(res[3], self.flags)
|
self.assertEqual(res[3], self.flags)
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_bridge_id(res[4]),
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_bridge_id(res[4]),
|
||||||
(self.root_priority,
|
(self.root_priority,
|
||||||
self.root_system_id_extension,
|
self.root_system_id_extension,
|
||||||
self.root_mac_address))
|
self.root_mac_address))
|
||||||
eq_(res[5], self.root_path_cost)
|
self.assertEqual(res[5], self.root_path_cost)
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_bridge_id(res[6]),
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_bridge_id(res[6]),
|
||||||
(self.bridge_priority,
|
(self.bridge_priority,
|
||||||
self.bridge_system_id_extension,
|
self.bridge_system_id_extension,
|
||||||
self.bridge_mac_address))
|
self.bridge_mac_address))
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_port_id(res[7]),
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_port_id(res[7]),
|
||||||
(self.port_priority,
|
(self.port_priority,
|
||||||
self.port_number))
|
self.port_number))
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[8]), self.message_age)
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[8]), self.message_age)
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[9]), self.max_age)
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[9]), self.max_age)
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[10]), self.hello_time)
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[10]), self.hello_time)
|
||||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[11]), self.forward_delay)
|
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[11]), self.forward_delay)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.msg.to_jsondict()
|
jsondict = self.msg.to_jsondict()
|
||||||
msg = bpdu.ConfigurationBPDUs.from_jsondict(
|
msg = bpdu.ConfigurationBPDUs.from_jsondict(
|
||||||
jsondict['ConfigurationBPDUs'])
|
jsondict['ConfigurationBPDUs'])
|
||||||
eq_(str(self.msg), str(msg))
|
self.assertEqual(str(self.msg), str(msg))
|
||||||
|
|
||||||
|
|
||||||
class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
||||||
@ -187,18 +186,18 @@ class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
|||||||
self.bpdu_type)
|
self.bpdu_type)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.protocol_id, self.msg._protocol_id)
|
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||||
eq_(self.version_id, self.msg._version_id)
|
self.assertEqual(self.version_id, self.msg._version_id)
|
||||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||||
|
|
||||||
eq_(type(r1), type(self.msg))
|
self.assertEqual(type(r1), type(self.msg))
|
||||||
eq_(r1._protocol_id, self.protocol_id)
|
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||||
eq_(r1._version_id, self.version_id)
|
self.assertEqual(r1._version_id, self.version_id)
|
||||||
eq_(r1._bpdu_type, self.bpdu_type)
|
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||||
eq_(r2, None)
|
self.assertEqual(r2, None)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -206,15 +205,15 @@ class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
|||||||
buf = self.msg.serialize(data, prev)
|
buf = self.msg.serialize(data, prev)
|
||||||
res = struct.unpack(self.fmt, buf)
|
res = struct.unpack(self.fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.protocol_id)
|
self.assertEqual(res[0], self.protocol_id)
|
||||||
eq_(res[1], self.version_id)
|
self.assertEqual(res[1], self.version_id)
|
||||||
eq_(res[2], self.bpdu_type)
|
self.assertEqual(res[2], self.bpdu_type)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.msg.to_jsondict()
|
jsondict = self.msg.to_jsondict()
|
||||||
msg = bpdu.TopologyChangeNotificationBPDUs.from_jsondict(
|
msg = bpdu.TopologyChangeNotificationBPDUs.from_jsondict(
|
||||||
jsondict['TopologyChangeNotificationBPDUs'])
|
jsondict['TopologyChangeNotificationBPDUs'])
|
||||||
eq_(str(self.msg), str(msg))
|
self.assertEqual(str(self.msg), str(msg))
|
||||||
|
|
||||||
|
|
||||||
class Test_RstBPDUs(unittest.TestCase):
|
class Test_RstBPDUs(unittest.TestCase):
|
||||||
@ -282,50 +281,50 @@ class Test_RstBPDUs(unittest.TestCase):
|
|||||||
self.version_1_length)
|
self.version_1_length)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.protocol_id, self.msg._protocol_id)
|
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||||
eq_(self.version_id, self.msg._version_id)
|
self.assertEqual(self.version_id, self.msg._version_id)
|
||||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||||
eq_(self.flags, self.msg.flags)
|
self.assertEqual(self.flags, self.msg.flags)
|
||||||
eq_(self.root_priority, self.msg.root_priority)
|
self.assertEqual(self.root_priority, self.msg.root_priority)
|
||||||
eq_(self.root_system_id_extension,
|
self.assertEqual(self.root_system_id_extension,
|
||||||
self.msg.root_system_id_extension)
|
self.msg.root_system_id_extension)
|
||||||
eq_(self.root_mac_address, self.msg.root_mac_address)
|
self.assertEqual(self.root_mac_address, self.msg.root_mac_address)
|
||||||
eq_(self.root_path_cost, self.msg.root_path_cost)
|
self.assertEqual(self.root_path_cost, self.msg.root_path_cost)
|
||||||
eq_(self.bridge_priority, self.msg.bridge_priority)
|
self.assertEqual(self.bridge_priority, self.msg.bridge_priority)
|
||||||
eq_(self.bridge_system_id_extension,
|
self.assertEqual(self.bridge_system_id_extension,
|
||||||
self.msg.bridge_system_id_extension)
|
self.msg.bridge_system_id_extension)
|
||||||
eq_(self.bridge_mac_address, self.msg.bridge_mac_address)
|
self.assertEqual(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||||
eq_(self.port_priority, self.msg.port_priority)
|
self.assertEqual(self.port_priority, self.msg.port_priority)
|
||||||
eq_(self.port_number, self.msg.port_number)
|
self.assertEqual(self.port_number, self.msg.port_number)
|
||||||
eq_(self.message_age, self.msg.message_age)
|
self.assertEqual(self.message_age, self.msg.message_age)
|
||||||
eq_(self.max_age, self.msg.max_age)
|
self.assertEqual(self.max_age, self.msg.max_age)
|
||||||
eq_(self.hello_time, self.msg.hello_time)
|
self.assertEqual(self.hello_time, self.msg.hello_time)
|
||||||
eq_(self.forward_delay, self.msg.forward_delay)
|
self.assertEqual(self.forward_delay, self.msg.forward_delay)
|
||||||
eq_(self.version_1_length, self.msg._version_1_length)
|
self.assertEqual(self.version_1_length, self.msg._version_1_length)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||||
|
|
||||||
eq_(type(r1), type(self.msg))
|
self.assertEqual(type(r1), type(self.msg))
|
||||||
eq_(r1._protocol_id, self.protocol_id)
|
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||||
eq_(r1._version_id, self.version_id)
|
self.assertEqual(r1._version_id, self.version_id)
|
||||||
eq_(r1._bpdu_type, self.bpdu_type)
|
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||||
eq_(r1.flags, self.flags)
|
self.assertEqual(r1.flags, self.flags)
|
||||||
eq_(r1.root_priority, self.root_priority)
|
self.assertEqual(r1.root_priority, self.root_priority)
|
||||||
eq_(r1.root_system_id_extension, self.root_system_id_extension)
|
self.assertEqual(r1.root_system_id_extension, self.root_system_id_extension)
|
||||||
eq_(r1.root_mac_address, self.root_mac_address)
|
self.assertEqual(r1.root_mac_address, self.root_mac_address)
|
||||||
eq_(r1.root_path_cost, self.root_path_cost)
|
self.assertEqual(r1.root_path_cost, self.root_path_cost)
|
||||||
eq_(r1.bridge_priority, self.bridge_priority)
|
self.assertEqual(r1.bridge_priority, self.bridge_priority)
|
||||||
eq_(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
self.assertEqual(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||||
eq_(r1.bridge_mac_address, self.bridge_mac_address)
|
self.assertEqual(r1.bridge_mac_address, self.bridge_mac_address)
|
||||||
eq_(r1.port_priority, self.port_priority)
|
self.assertEqual(r1.port_priority, self.port_priority)
|
||||||
eq_(r1.port_number, self.port_number)
|
self.assertEqual(r1.port_number, self.port_number)
|
||||||
eq_(r1.message_age, self.message_age)
|
self.assertEqual(r1.message_age, self.message_age)
|
||||||
eq_(r1.max_age, self.max_age)
|
self.assertEqual(r1.max_age, self.max_age)
|
||||||
eq_(r1.hello_time, self.hello_time)
|
self.assertEqual(r1.hello_time, self.hello_time)
|
||||||
eq_(r1.forward_delay, self.forward_delay)
|
self.assertEqual(r1.forward_delay, self.forward_delay)
|
||||||
eq_(r1._version_1_length, self.version_1_length)
|
self.assertEqual(r1._version_1_length, self.version_1_length)
|
||||||
eq_(r2, None)
|
self.assertEqual(r2, None)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -333,32 +332,32 @@ class Test_RstBPDUs(unittest.TestCase):
|
|||||||
buf = self.msg.serialize(data, prev)
|
buf = self.msg.serialize(data, prev)
|
||||||
res = struct.unpack(self.fmt, buf)
|
res = struct.unpack(self.fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.protocol_id)
|
self.assertEqual(res[0], self.protocol_id)
|
||||||
eq_(res[1], self.version_id)
|
self.assertEqual(res[1], self.version_id)
|
||||||
eq_(res[2], self.bpdu_type)
|
self.assertEqual(res[2], self.bpdu_type)
|
||||||
eq_(res[3], self.flags)
|
self.assertEqual(res[3], self.flags)
|
||||||
eq_(bpdu.RstBPDUs._decode_bridge_id(res[4]),
|
self.assertEqual(bpdu.RstBPDUs._decode_bridge_id(res[4]),
|
||||||
(self.root_priority,
|
(self.root_priority,
|
||||||
self.root_system_id_extension,
|
self.root_system_id_extension,
|
||||||
self.root_mac_address))
|
self.root_mac_address))
|
||||||
eq_(res[5], self.root_path_cost)
|
self.assertEqual(res[5], self.root_path_cost)
|
||||||
eq_(bpdu.RstBPDUs._decode_bridge_id(res[6]),
|
self.assertEqual(bpdu.RstBPDUs._decode_bridge_id(res[6]),
|
||||||
(self.bridge_priority,
|
(self.bridge_priority,
|
||||||
self.bridge_system_id_extension,
|
self.bridge_system_id_extension,
|
||||||
self.bridge_mac_address))
|
self.bridge_mac_address))
|
||||||
eq_(bpdu.RstBPDUs._decode_port_id(res[7]),
|
self.assertEqual(bpdu.RstBPDUs._decode_port_id(res[7]),
|
||||||
(self.port_priority,
|
(self.port_priority,
|
||||||
self.port_number))
|
self.port_number))
|
||||||
eq_(bpdu.RstBPDUs._decode_timer(res[8]), self.message_age)
|
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[8]), self.message_age)
|
||||||
eq_(bpdu.RstBPDUs._decode_timer(res[9]), self.max_age)
|
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[9]), self.max_age)
|
||||||
eq_(bpdu.RstBPDUs._decode_timer(res[10]), self.hello_time)
|
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[10]), self.hello_time)
|
||||||
eq_(bpdu.RstBPDUs._decode_timer(res[11]), self.forward_delay)
|
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[11]), self.forward_delay)
|
||||||
eq_(res[12], self.version_1_length)
|
self.assertEqual(res[12], self.version_1_length)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.msg.to_jsondict()
|
jsondict = self.msg.to_jsondict()
|
||||||
msg = bpdu.RstBPDUs.from_jsondict(jsondict['RstBPDUs'])
|
msg = bpdu.RstBPDUs.from_jsondict(jsondict['RstBPDUs'])
|
||||||
eq_(str(self.msg), str(msg))
|
self.assertEqual(str(self.msg), str(msg))
|
||||||
|
|
||||||
|
|
||||||
class Test_UnknownVersion(unittest.TestCase):
|
class Test_UnknownVersion(unittest.TestCase):
|
||||||
@ -411,8 +410,8 @@ class Test_UnknownVersion(unittest.TestCase):
|
|||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||||
eq_(r1, self.buf)
|
self.assertEqual(r1, self.buf)
|
||||||
eq_(r2, None)
|
self.assertEqual(r2, None)
|
||||||
|
|
||||||
|
|
||||||
class Test_UnknownType(unittest.TestCase):
|
class Test_UnknownType(unittest.TestCase):
|
||||||
@ -465,5 +464,5 @@ class Test_UnknownType(unittest.TestCase):
|
|||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||||
eq_(r1, self.buf)
|
self.assertEqual(r1, self.buf)
|
||||||
eq_(r2, None)
|
self.assertEqual(r2, None)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,6 @@ import struct
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.lib import addrconv
|
from os_ken.lib import addrconv
|
||||||
from os_ken.lib.packet import dhcp
|
from os_ken.lib.packet import dhcp
|
||||||
@ -92,57 +90,57 @@ class Test_dhcp_offer(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.op, self.dh.op)
|
self.assertEqual(self.op, self.dh.op)
|
||||||
eq_(self.htype, self.dh.htype)
|
self.assertEqual(self.htype, self.dh.htype)
|
||||||
eq_(self.hlen, self.dh.hlen)
|
self.assertEqual(self.hlen, self.dh.hlen)
|
||||||
eq_(self.hops, self.dh.hops)
|
self.assertEqual(self.hops, self.dh.hops)
|
||||||
eq_(self.xid, self.dh.xid)
|
self.assertEqual(self.xid, self.dh.xid)
|
||||||
eq_(self.secs, self.dh.secs)
|
self.assertEqual(self.secs, self.dh.secs)
|
||||||
eq_(self.flags, self.dh.flags)
|
self.assertEqual(self.flags, self.dh.flags)
|
||||||
eq_(self.ciaddr, self.dh.ciaddr)
|
self.assertEqual(self.ciaddr, self.dh.ciaddr)
|
||||||
eq_(self.yiaddr, self.dh.yiaddr)
|
self.assertEqual(self.yiaddr, self.dh.yiaddr)
|
||||||
eq_(self.siaddr, self.dh.siaddr)
|
self.assertEqual(self.siaddr, self.dh.siaddr)
|
||||||
eq_(self.giaddr, self.dh.giaddr)
|
self.assertEqual(self.giaddr, self.dh.giaddr)
|
||||||
eq_(self.chaddr, self.dh.chaddr)
|
self.assertEqual(self.chaddr, self.dh.chaddr)
|
||||||
eq_(self.sname, self.dh.sname)
|
self.assertEqual(self.sname, self.dh.sname)
|
||||||
eq_(self.boot_file, self.dh.boot_file)
|
self.assertEqual(self.boot_file, self.dh.boot_file)
|
||||||
eq_(str(self.options), str(self.dh.options))
|
self.assertEqual(str(self.options), str(self.dh.options))
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
res, _, rest = dhcp.dhcp.parser(self.buf)
|
res, _, rest = dhcp.dhcp.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.op, res.op)
|
self.assertEqual(self.op, res.op)
|
||||||
eq_(self.htype, res.htype)
|
self.assertEqual(self.htype, res.htype)
|
||||||
eq_(self.hlen, res.hlen)
|
self.assertEqual(self.hlen, res.hlen)
|
||||||
eq_(self.hops, res.hops)
|
self.assertEqual(self.hops, res.hops)
|
||||||
eq_(self.xid, res.xid)
|
self.assertEqual(self.xid, res.xid)
|
||||||
eq_(self.secs, res.secs)
|
self.assertEqual(self.secs, res.secs)
|
||||||
eq_(self.flags, res.flags)
|
self.assertEqual(self.flags, res.flags)
|
||||||
eq_(self.ciaddr, res.ciaddr)
|
self.assertEqual(self.ciaddr, res.ciaddr)
|
||||||
eq_(self.yiaddr, res.yiaddr)
|
self.assertEqual(self.yiaddr, res.yiaddr)
|
||||||
eq_(self.siaddr, res.siaddr)
|
self.assertEqual(self.siaddr, res.siaddr)
|
||||||
eq_(self.giaddr, res.giaddr)
|
self.assertEqual(self.giaddr, res.giaddr)
|
||||||
eq_(self.chaddr, res.chaddr)
|
self.assertEqual(self.chaddr, res.chaddr)
|
||||||
# sname is 64 byte length. rest of data is filled by '\x00'.
|
# sname is 64 byte length. rest of data is filled by '\x00'.
|
||||||
eq_(self.sname.ljust(64, '\x00'), res.sname)
|
self.assertEqual(self.sname.ljust(64, '\x00'), res.sname)
|
||||||
# boof_file is 128 byte length. rest of data is filled by '\x00'.
|
# boof_file is 128 byte length. rest of data is filled by '\x00'.
|
||||||
eq_(self.boot_file.ljust(128, '\x00'), res.boot_file)
|
self.assertEqual(self.boot_file.ljust(128, '\x00'), res.boot_file)
|
||||||
eq_(str(self.options), str(res.options))
|
self.assertEqual(str(self.options), str(res.options))
|
||||||
eq_(b'', rest)
|
self.assertEqual(b'', rest)
|
||||||
|
|
||||||
def test_parser_corrupted(self):
|
def test_parser_corrupted(self):
|
||||||
corrupt_buf = self.buf[:-4]
|
corrupt_buf = self.buf[:-4]
|
||||||
pkt, _, rest = dhcp.dhcp.parser(corrupt_buf)
|
pkt, _, rest = dhcp.dhcp.parser(corrupt_buf)
|
||||||
|
|
||||||
ok_(isinstance(pkt, dhcp.dhcp))
|
self.assertTrue(isinstance(pkt, dhcp.dhcp))
|
||||||
ok_(isinstance(pkt.options, dhcp.options))
|
self.assertTrue(isinstance(pkt.options, dhcp.options))
|
||||||
for opt in pkt.options.option_list[:-1]:
|
for opt in pkt.options.option_list[:-1]:
|
||||||
ok_(isinstance(opt, dhcp.option))
|
self.assertTrue(isinstance(opt, dhcp.option))
|
||||||
ok_(isinstance(pkt.options.option_list[-1], six.binary_type))
|
self.assertTrue(isinstance(pkt.options.option_list[-1], six.binary_type))
|
||||||
|
|
||||||
buf = pkt.serialize()
|
buf = pkt.serialize()
|
||||||
eq_(str(buf), str(corrupt_buf))
|
self.assertEqual(str(buf), str(corrupt_buf))
|
||||||
eq_(b'', rest)
|
self.assertEqual(b'', rest)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.dh.serialize()
|
buf = self.dh.serialize()
|
||||||
@ -150,25 +148,25 @@ class Test_dhcp_offer(unittest.TestCase):
|
|||||||
res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR,
|
res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR,
|
||||||
six.binary_type(buf))
|
six.binary_type(buf))
|
||||||
|
|
||||||
eq_(self.op, res[0])
|
self.assertEqual(self.op, res[0])
|
||||||
eq_(self.htype, res[1])
|
self.assertEqual(self.htype, res[1])
|
||||||
eq_(self.hlen, res[2])
|
self.assertEqual(self.hlen, res[2])
|
||||||
eq_(self.hops, res[3])
|
self.assertEqual(self.hops, res[3])
|
||||||
eq_(self.xid, res[4])
|
self.assertEqual(self.xid, res[4])
|
||||||
eq_(self.secs, res[5])
|
self.assertEqual(self.secs, res[5])
|
||||||
eq_(self.flags, res[6])
|
self.assertEqual(self.flags, res[6])
|
||||||
eq_(self.ciaddr, addrconv.ipv4.bin_to_text(res[7]))
|
self.assertEqual(self.ciaddr, addrconv.ipv4.bin_to_text(res[7]))
|
||||||
eq_(self.yiaddr, addrconv.ipv4.bin_to_text(res[8]))
|
self.assertEqual(self.yiaddr, addrconv.ipv4.bin_to_text(res[8]))
|
||||||
eq_(self.siaddr, addrconv.ipv4.bin_to_text(res[9]))
|
self.assertEqual(self.siaddr, addrconv.ipv4.bin_to_text(res[9]))
|
||||||
eq_(self.giaddr, addrconv.ipv4.bin_to_text(res[10]))
|
self.assertEqual(self.giaddr, addrconv.ipv4.bin_to_text(res[10]))
|
||||||
eq_(self.chaddr, addrconv.mac.bin_to_text(res[11][:6]))
|
self.assertEqual(self.chaddr, addrconv.mac.bin_to_text(res[11][:6]))
|
||||||
# sname is 64 byte length. rest of data is filled by '\x00'.
|
# sname is 64 byte length. rest of data is filled by '\x00'.
|
||||||
eq_(self.sname.ljust(64, '\x00'), res[12].decode('ascii'))
|
self.assertEqual(self.sname.ljust(64, '\x00'), res[12].decode('ascii'))
|
||||||
# boof_file is 128 byte length. rest of data is filled by '\x00'.
|
# boof_file is 128 byte length. rest of data is filled by '\x00'.
|
||||||
eq_(self.boot_file.ljust(128, '\x00'), res[13].decode('ascii'))
|
self.assertEqual(self.boot_file.ljust(128, '\x00'), res[13].decode('ascii'))
|
||||||
options = dhcp.options.parser(
|
options = dhcp.options.parser(
|
||||||
buf[struct.calcsize(dhcp.dhcp._DHCP_PACK_STR):])
|
buf[struct.calcsize(dhcp.dhcp._DHCP_PACK_STR):])
|
||||||
eq_(str(self.options), str(options))
|
self.assertEqual(str(self.options), str(options))
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
option_values = ['tag', 'length', 'value']
|
option_values = ['tag', 'length', 'value']
|
||||||
@ -209,10 +207,10 @@ class Test_dhcp_offer(unittest.TestCase):
|
|||||||
if k in dhcp_values])
|
if k in dhcp_values])
|
||||||
dh_str = '%s(%s)' % (dhcp.dhcp.__name__, _dh_str)
|
dh_str = '%s(%s)' % (dhcp.dhcp.__name__, _dh_str)
|
||||||
|
|
||||||
eq_(str(self.dh), dh_str)
|
self.assertEqual(str(self.dh), dh_str)
|
||||||
eq_(repr(self.dh), dh_str)
|
self.assertEqual(repr(self.dh), dh_str)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.dh.to_jsondict()
|
jsondict = self.dh.to_jsondict()
|
||||||
dh = dhcp.dhcp.from_jsondict(jsondict['dhcp'])
|
dh = dhcp.dhcp.from_jsondict(jsondict['dhcp'])
|
||||||
eq_(str(self.dh), str(dh))
|
self.assertEqual(str(self.dh), str(dh))
|
||||||
|
@ -21,7 +21,6 @@ import six
|
|||||||
import struct
|
import struct
|
||||||
import netaddr
|
import netaddr
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import ether, inet
|
from os_ken.ofproto import ether, inet
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
from os_ken.lib.packet.packet import Packet
|
from os_ken.lib.packet.packet import Packet
|
||||||
@ -58,18 +57,18 @@ class Test_ethernet(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.dst, self.e.dst)
|
self.assertEqual(self.dst, self.e.dst)
|
||||||
eq_(self.src, self.e.src)
|
self.assertEqual(self.src, self.e.src)
|
||||||
eq_(self.ethertype, self.e.ethertype)
|
self.assertEqual(self.ethertype, self.e.ethertype)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
res, ptype, _ = self.e.parser(self.buf)
|
res, ptype, _ = self.e.parser(self.buf)
|
||||||
LOG.debug((res, ptype))
|
LOG.debug((res, ptype))
|
||||||
|
|
||||||
eq_(res.dst, self.dst)
|
self.assertEqual(res.dst, self.dst)
|
||||||
eq_(res.src, self.src)
|
self.assertEqual(res.src, self.src)
|
||||||
eq_(res.ethertype, self.ethertype)
|
self.assertEqual(res.ethertype, self.ethertype)
|
||||||
eq_(ptype, arp)
|
self.assertEqual(ptype, arp)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -79,25 +78,24 @@ class Test_ethernet(unittest.TestCase):
|
|||||||
fmt = ethernet._PACK_STR
|
fmt = ethernet._PACK_STR
|
||||||
res = struct.unpack(fmt, buf)
|
res = struct.unpack(fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], addrconv.mac.text_to_bin(self.dst))
|
self.assertEqual(res[0], addrconv.mac.text_to_bin(self.dst))
|
||||||
eq_(res[1], addrconv.mac.text_to_bin(self.src))
|
self.assertEqual(res[1], addrconv.mac.text_to_bin(self.src))
|
||||||
eq_(res[2], self.ethertype)
|
self.assertEqual(res[2], self.ethertype)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_ethernet(self):
|
def test_malformed_ethernet(self):
|
||||||
m_short_buf = self.buf[1:ethernet._MIN_LEN]
|
m_short_buf = self.buf[1:ethernet._MIN_LEN]
|
||||||
ethernet.parser(m_short_buf)
|
self.assertRaises(Exception, ethernet.parser, m_short_buf)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
e = ethernet()
|
e = ethernet()
|
||||||
buf = e.serialize(bytearray(), None)
|
buf = e.serialize(bytearray(), None)
|
||||||
res = struct.unpack(e._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(e._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], addrconv.mac.text_to_bin('ff:ff:ff:ff:ff:ff'))
|
self.assertEqual(res[0], addrconv.mac.text_to_bin('ff:ff:ff:ff:ff:ff'))
|
||||||
eq_(res[1], addrconv.mac.text_to_bin('00:00:00:00:00:00'))
|
self.assertEqual(res[1], addrconv.mac.text_to_bin('00:00:00:00:00:00'))
|
||||||
eq_(res[2], ether.ETH_TYPE_IP)
|
self.assertEqual(res[2], ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.e.to_jsondict()
|
jsondict = self.e.to_jsondict()
|
||||||
e = ethernet.from_jsondict(jsondict['ethernet'])
|
e = ethernet.from_jsondict(jsondict['ethernet'])
|
||||||
eq_(str(self.e), str(e))
|
self.assertEqual(str(self.e), str(e))
|
||||||
|
@ -18,8 +18,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.lib import pcaplib
|
from os_ken.lib import pcaplib
|
||||||
from os_ken.lib.packet import geneve
|
from os_ken.lib.packet import geneve
|
||||||
@ -51,10 +49,10 @@ class Test_geneve(unittest.TestCase):
|
|||||||
# Checks if message can be parsed as expected.
|
# Checks if message can be parsed as expected.
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
geneve_pkt = pkt.get_protocol(geneve.geneve)
|
geneve_pkt = pkt.get_protocol(geneve.geneve)
|
||||||
ok_(isinstance(geneve_pkt, geneve.geneve),
|
self.assertTrue(isinstance(geneve_pkt, geneve.geneve),
|
||||||
'Failed to parse Geneve message: %s' % pkt)
|
'Failed to parse Geneve message: %s' % pkt)
|
||||||
|
|
||||||
# Checks if message can be serialized as expected.
|
# Checks if message can be serialized as expected.
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(buf, pkt.data,
|
self.assertEqual(buf, pkt.data,
|
||||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||||
|
@ -18,8 +18,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.lib import pcaplib
|
from os_ken.lib import pcaplib
|
||||||
from os_ken.lib.packet import gre
|
from os_ken.lib.packet import gre
|
||||||
@ -53,41 +51,41 @@ class Test_gre(unittest.TestCase):
|
|||||||
|
|
||||||
def test_key_setter(self):
|
def test_key_setter(self):
|
||||||
self.gre.key = self.key
|
self.gre.key = self.key
|
||||||
eq_(self.gre._key, self.key)
|
self.assertEqual(self.gre._key, self.key)
|
||||||
eq_(self.gre._vsid, self.vsid)
|
self.assertEqual(self.gre._vsid, self.vsid)
|
||||||
eq_(self.gre._flow_id, self.flow_id)
|
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||||
|
|
||||||
def test_key_setter_none(self):
|
def test_key_setter_none(self):
|
||||||
self.gre.key = None
|
self.gre.key = None
|
||||||
eq_(self.gre._key, None)
|
self.assertEqual(self.gre._key, None)
|
||||||
eq_(self.gre._vsid, None)
|
self.assertEqual(self.gre._vsid, None)
|
||||||
eq_(self.gre._flow_id, None)
|
self.assertEqual(self.gre._flow_id, None)
|
||||||
|
|
||||||
self.gre.key = self.key
|
self.gre.key = self.key
|
||||||
|
|
||||||
def test_vsid_setter(self):
|
def test_vsid_setter(self):
|
||||||
self.gre.vsid = self.vsid
|
self.gre.vsid = self.vsid
|
||||||
eq_(self.gre._key, self.key)
|
self.assertEqual(self.gre._key, self.key)
|
||||||
eq_(self.gre._vsid, self.vsid)
|
self.assertEqual(self.gre._vsid, self.vsid)
|
||||||
eq_(self.gre._flow_id, self.flow_id)
|
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||||
|
|
||||||
def test_flowid_setter(self):
|
def test_flowid_setter(self):
|
||||||
self.gre.flow_id = self.flow_id
|
self.gre.flow_id = self.flow_id
|
||||||
eq_(self.gre._key, self.key)
|
self.assertEqual(self.gre._key, self.key)
|
||||||
eq_(self.gre._vsid, self.vsid)
|
self.assertEqual(self.gre._vsid, self.vsid)
|
||||||
eq_(self.gre._flow_id, self.flow_id)
|
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||||
|
|
||||||
def test_nvgre_init(self):
|
def test_nvgre_init(self):
|
||||||
nvgre = gre.nvgre(version=self.version, vsid=self.vsid,
|
nvgre = gre.nvgre(version=self.version, vsid=self.vsid,
|
||||||
flow_id=self.flow_id)
|
flow_id=self.flow_id)
|
||||||
|
|
||||||
eq_(nvgre.version, self.version)
|
self.assertEqual(nvgre.version, self.version)
|
||||||
eq_(nvgre.protocol, self.nvgre_proto)
|
self.assertEqual(nvgre.protocol, self.nvgre_proto)
|
||||||
eq_(nvgre.checksum, None)
|
self.assertEqual(nvgre.checksum, None)
|
||||||
eq_(nvgre.seq_number, None)
|
self.assertEqual(nvgre.seq_number, None)
|
||||||
eq_(nvgre._key, self.key)
|
self.assertEqual(nvgre._key, self.key)
|
||||||
eq_(nvgre._vsid, self.vsid)
|
self.assertEqual(nvgre._vsid, self.vsid)
|
||||||
eq_(nvgre._flow_id, self.flow_id)
|
self.assertEqual(nvgre._flow_id, self.flow_id)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
files = [
|
files = [
|
||||||
@ -103,11 +101,11 @@ class Test_gre(unittest.TestCase):
|
|||||||
# Checks if message can be parsed as expected.
|
# Checks if message can be parsed as expected.
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
gre_pkt = pkt.get_protocol(gre.gre)
|
gre_pkt = pkt.get_protocol(gre.gre)
|
||||||
ok_(isinstance(gre_pkt, gre.gre),
|
self.assertTrue(isinstance(gre_pkt, gre.gre),
|
||||||
'Failed to parse Gre message: %s' % pkt)
|
'Failed to parse Gre message: %s' % pkt)
|
||||||
|
|
||||||
# Checks if message can be serialized as expected.
|
# Checks if message can be serialized as expected.
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
|
|
||||||
eq_(buf, pkt.data,
|
self.assertEqual(buf, pkt.data,
|
||||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||||
|
@ -20,7 +20,6 @@ import six
|
|||||||
import struct
|
import struct
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.lib.packet import icmp
|
from os_ken.lib.packet import icmp
|
||||||
from os_ken.lib.packet import packet_utils
|
from os_ken.lib.packet import packet_utils
|
||||||
|
|
||||||
@ -111,10 +110,10 @@ class Test_icmp(unittest.TestCase):
|
|||||||
struct.pack_into('!H', self.buf, 2, self.csum_calc)
|
struct.pack_into('!H', self.buf, 2, self.csum_calc)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.ic.type)
|
self.assertEqual(self.type_, self.ic.type)
|
||||||
eq_(self.code, self.ic.code)
|
self.assertEqual(self.code, self.ic.code)
|
||||||
eq_(self.csum, self.ic.csum)
|
self.assertEqual(self.csum, self.ic.csum)
|
||||||
eq_(str(self.data), str(self.ic.data))
|
self.assertEqual(str(self.data), str(self.ic.data))
|
||||||
|
|
||||||
def test_init_with_echo(self):
|
def test_init_with_echo(self):
|
||||||
self.setUp_with_echo()
|
self.setUp_with_echo()
|
||||||
@ -135,10 +134,10 @@ class Test_icmp(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(self.type_, res.type)
|
self.assertEqual(self.type_, res.type)
|
||||||
eq_(self.code, res.code)
|
self.assertEqual(self.code, res.code)
|
||||||
eq_(self.csum_calc, res.csum)
|
self.assertEqual(self.csum_calc, res.csum)
|
||||||
eq_(str(self.data), str(res.data))
|
self.assertEqual(str(self.data), str(res.data))
|
||||||
|
|
||||||
def test_parser_with_echo(self):
|
def test_parser_with_echo(self):
|
||||||
self.setUp_with_echo()
|
self.setUp_with_echo()
|
||||||
@ -159,9 +158,9 @@ class Test_icmp(unittest.TestCase):
|
|||||||
|
|
||||||
res = struct.unpack_from(icmp.icmp._PACK_STR, six.binary_type(buf))
|
res = struct.unpack_from(icmp.icmp._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(self.type_, res[0])
|
self.assertEqual(self.type_, res[0])
|
||||||
eq_(self.code, res[1])
|
self.assertEqual(self.code, res[1])
|
||||||
eq_(self.csum_calc, res[2])
|
self.assertEqual(self.csum_calc, res[2])
|
||||||
|
|
||||||
def test_serialize_with_echo(self):
|
def test_serialize_with_echo(self):
|
||||||
self.setUp_with_echo()
|
self.setUp_with_echo()
|
||||||
@ -171,7 +170,7 @@ class Test_icmp(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ic.serialize(data, prev)
|
buf = self.ic.serialize(data, prev)
|
||||||
echo = icmp.echo.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
echo = icmp.echo.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
||||||
eq_(repr(self.data), repr(echo))
|
self.assertEqual(repr(self.data), repr(echo))
|
||||||
|
|
||||||
def test_serialize_with_dest_unreach(self):
|
def test_serialize_with_dest_unreach(self):
|
||||||
self.setUp_with_dest_unreach()
|
self.setUp_with_dest_unreach()
|
||||||
@ -181,7 +180,7 @@ class Test_icmp(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ic.serialize(data, prev)
|
buf = self.ic.serialize(data, prev)
|
||||||
unreach = icmp.dest_unreach.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
unreach = icmp.dest_unreach.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
||||||
eq_(repr(self.data), repr(unreach))
|
self.assertEqual(repr(self.data), repr(unreach))
|
||||||
|
|
||||||
def test_serialize_with_TimeExceeded(self):
|
def test_serialize_with_TimeExceeded(self):
|
||||||
self.setUp_with_TimeExceeded()
|
self.setUp_with_TimeExceeded()
|
||||||
@ -191,7 +190,7 @@ class Test_icmp(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ic.serialize(data, prev)
|
buf = self.ic.serialize(data, prev)
|
||||||
te = icmp.TimeExceeded.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
te = icmp.TimeExceeded.parser(six.binary_type(buf), icmp.icmp._MIN_LEN)
|
||||||
eq_(repr(self.data), repr(te))
|
self.assertEqual(repr(self.data), repr(te))
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
icmp_values = {'type': repr(self.type_),
|
icmp_values = {'type': repr(self.type_),
|
||||||
@ -203,8 +202,8 @@ class Test_icmp(unittest.TestCase):
|
|||||||
if k in icmp_values])
|
if k in icmp_values])
|
||||||
ic_str = '%s(%s)' % (icmp.icmp.__name__, _ic_str)
|
ic_str = '%s(%s)' % (icmp.icmp.__name__, _ic_str)
|
||||||
|
|
||||||
eq_(str(self.ic), ic_str)
|
self.assertEqual(str(self.ic), ic_str)
|
||||||
eq_(repr(self.ic), ic_str)
|
self.assertEqual(repr(self.ic), ic_str)
|
||||||
|
|
||||||
def test_to_string_with_echo(self):
|
def test_to_string_with_echo(self):
|
||||||
self.setUp_with_echo()
|
self.setUp_with_echo()
|
||||||
@ -223,23 +222,23 @@ class Test_icmp(unittest.TestCase):
|
|||||||
buf = ic.serialize(bytearray(), None)
|
buf = ic.serialize(bytearray(), None)
|
||||||
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
||||||
|
|
||||||
eq_(res[0], 8)
|
self.assertEqual(res[0], 8)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(buf[4:], b'\x00\x00\x00\x00')
|
self.assertEqual(buf[4:], b'\x00\x00\x00\x00')
|
||||||
|
|
||||||
# with data
|
# with data
|
||||||
ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
|
ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
|
||||||
buf = ic.serialize(bytearray(), None)
|
buf = ic.serialize(bytearray(), None)
|
||||||
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
||||||
|
|
||||||
eq_(res[0], 3)
|
self.assertEqual(res[0], 3)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(buf[4:], b'\x00\x00\x00\x00')
|
self.assertEqual(buf[4:], b'\x00\x00\x00\x00')
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.ic.to_jsondict()
|
jsondict = self.ic.to_jsondict()
|
||||||
ic = icmp.icmp.from_jsondict(jsondict['icmp'])
|
ic = icmp.icmp.from_jsondict(jsondict['icmp'])
|
||||||
eq_(str(self.ic), str(ic))
|
self.assertEqual(str(self.ic), str(ic))
|
||||||
|
|
||||||
def test_json_with_echo(self):
|
def test_json_with_echo(self):
|
||||||
self.setUp_with_echo()
|
self.setUp_with_echo()
|
||||||
@ -271,9 +270,9 @@ class Test_echo(unittest.TestCase):
|
|||||||
self.buf += self.data
|
self.buf += self.data
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.id_, self.echo.id)
|
self.assertEqual(self.id_, self.echo.id)
|
||||||
eq_(self.seq, self.echo.seq)
|
self.assertEqual(self.seq, self.echo.seq)
|
||||||
eq_(self.data, self.echo.data)
|
self.assertEqual(self.data, self.echo.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = icmp.echo.parser(self.buf, 0)
|
_res = icmp.echo.parser(self.buf, 0)
|
||||||
@ -281,24 +280,24 @@ class Test_echo(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.id_, res.id)
|
self.assertEqual(self.id_, res.id)
|
||||||
eq_(self.seq, res.seq)
|
self.assertEqual(self.seq, res.seq)
|
||||||
eq_(self.data, res.data)
|
self.assertEqual(self.data, res.data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.echo.serialize()
|
buf = self.echo.serialize()
|
||||||
res = struct.unpack_from('!HH', six.binary_type(buf))
|
res = struct.unpack_from('!HH', six.binary_type(buf))
|
||||||
eq_(self.id_, res[0])
|
self.assertEqual(self.id_, res[0])
|
||||||
eq_(self.seq, res[1])
|
self.assertEqual(self.seq, res[1])
|
||||||
eq_(self.data, buf[struct.calcsize('!HH'):])
|
self.assertEqual(self.data, buf[struct.calcsize('!HH'):])
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
ec = icmp.echo()
|
ec = icmp.echo()
|
||||||
buf = ec.serialize()
|
buf = ec.serialize()
|
||||||
res = struct.unpack(icmp.echo._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(icmp.echo._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
|
|
||||||
|
|
||||||
class Test_dest_unreach(unittest.TestCase):
|
class Test_dest_unreach(unittest.TestCase):
|
||||||
@ -313,9 +312,9 @@ class Test_dest_unreach(unittest.TestCase):
|
|||||||
self.buf += self.data
|
self.buf += self.data
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.data_len, self.dest_unreach.data_len)
|
self.assertEqual(self.data_len, self.dest_unreach.data_len)
|
||||||
eq_(self.mtu, self.dest_unreach.mtu)
|
self.assertEqual(self.mtu, self.dest_unreach.mtu)
|
||||||
eq_(self.data, self.dest_unreach.data)
|
self.assertEqual(self.data, self.dest_unreach.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = icmp.dest_unreach.parser(self.buf, 0)
|
_res = icmp.dest_unreach.parser(self.buf, 0)
|
||||||
@ -323,24 +322,24 @@ class Test_dest_unreach(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.data_len, res.data_len)
|
self.assertEqual(self.data_len, res.data_len)
|
||||||
eq_(self.mtu, res.mtu)
|
self.assertEqual(self.mtu, res.mtu)
|
||||||
eq_(self.data, res.data)
|
self.assertEqual(self.data, res.data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.dest_unreach.serialize()
|
buf = self.dest_unreach.serialize()
|
||||||
res = struct.unpack_from('!xBH', six.binary_type(buf))
|
res = struct.unpack_from('!xBH', six.binary_type(buf))
|
||||||
eq_(self.data_len, res[0])
|
self.assertEqual(self.data_len, res[0])
|
||||||
eq_(self.mtu, res[1])
|
self.assertEqual(self.mtu, res[1])
|
||||||
eq_(self.data, buf[struct.calcsize('!xBH'):])
|
self.assertEqual(self.data, buf[struct.calcsize('!xBH'):])
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
du = icmp.dest_unreach()
|
du = icmp.dest_unreach()
|
||||||
buf = du.serialize()
|
buf = du.serialize()
|
||||||
res = struct.unpack(icmp.dest_unreach._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(icmp.dest_unreach._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
|
|
||||||
|
|
||||||
class Test_TimeExceeded(unittest.TestCase):
|
class Test_TimeExceeded(unittest.TestCase):
|
||||||
@ -354,8 +353,8 @@ class Test_TimeExceeded(unittest.TestCase):
|
|||||||
self.buf += self.data
|
self.buf += self.data
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.data_len, self.te.data_len)
|
self.assertEqual(self.data_len, self.te.data_len)
|
||||||
eq_(self.data, self.te.data)
|
self.assertEqual(self.data, self.te.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = icmp.TimeExceeded.parser(self.buf, 0)
|
_res = icmp.TimeExceeded.parser(self.buf, 0)
|
||||||
@ -363,18 +362,18 @@ class Test_TimeExceeded(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.data_len, res.data_len)
|
self.assertEqual(self.data_len, res.data_len)
|
||||||
eq_(self.data, res.data)
|
self.assertEqual(self.data, res.data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.te.serialize()
|
buf = self.te.serialize()
|
||||||
res = struct.unpack_from('!xBxx', six.binary_type(buf))
|
res = struct.unpack_from('!xBxx', six.binary_type(buf))
|
||||||
eq_(self.data_len, res[0])
|
self.assertEqual(self.data_len, res[0])
|
||||||
eq_(self.data, buf[struct.calcsize('!xBxx'):])
|
self.assertEqual(self.data, buf[struct.calcsize('!xBxx'):])
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
te = icmp.TimeExceeded()
|
te = icmp.TimeExceeded()
|
||||||
buf = te.serialize()
|
buf = te.serialize()
|
||||||
res = struct.unpack(icmp.TimeExceeded._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(icmp.TimeExceeded._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,6 @@ import logging
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from struct import pack, unpack_from, pack_into
|
from struct import pack, unpack_from, pack_into
|
||||||
from nose.tools import ok_, eq_, raises
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.ofproto import inet
|
from os_ken.ofproto import inet
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
@ -66,10 +65,10 @@ class Test_igmp(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.msgtype, self.g.msgtype)
|
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||||
eq_(self.maxresp, self.g.maxresp)
|
self.assertEqual(self.maxresp, self.g.maxresp)
|
||||||
eq_(self.csum, self.g.csum)
|
self.assertEqual(self.csum, self.g.csum)
|
||||||
eq_(self.address, self.g.address)
|
self.assertEqual(self.address, self.g.address)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = self.g.parser(self.buf)
|
_res = self.g.parser(self.buf)
|
||||||
@ -78,10 +77,10 @@ class Test_igmp(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res.msgtype, self.msgtype)
|
self.assertEqual(res.msgtype, self.msgtype)
|
||||||
eq_(res.maxresp, self.maxresp)
|
self.assertEqual(res.maxresp, self.maxresp)
|
||||||
eq_(res.csum, self.csum)
|
self.assertEqual(res.csum, self.csum)
|
||||||
eq_(res.address, self.address)
|
self.assertEqual(res.address, self.address)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -90,10 +89,10 @@ class Test_igmp(unittest.TestCase):
|
|||||||
|
|
||||||
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], self.msgtype)
|
self.assertEqual(res[0], self.msgtype)
|
||||||
eq_(res[1], self.maxresp)
|
self.assertEqual(res[1], self.maxresp)
|
||||||
eq_(res[2], checksum(self.buf))
|
self.assertEqual(res[2], checksum(self.buf))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
|
|
||||||
def _build_igmp(self):
|
def _build_igmp(self):
|
||||||
dl_dst = '11:22:33:44:55:66'
|
dl_dst = '11:22:33:44:55:66'
|
||||||
@ -120,20 +119,20 @@ class Test_igmp(unittest.TestCase):
|
|||||||
p = self._build_igmp()
|
p = self._build_igmp()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertIsNotNone(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
i = self.find_protocol(p, "ipv4")
|
i = self.find_protocol(p, "ipv4")
|
||||||
ok_(i)
|
self.assertTrue(i)
|
||||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||||
|
|
||||||
g = self.find_protocol(p, "igmp")
|
g = self.find_protocol(p, "igmp")
|
||||||
ok_(g)
|
self.assertTrue(g)
|
||||||
|
|
||||||
eq_(g.msgtype, self.msgtype)
|
self.assertEqual(g.msgtype, self.msgtype)
|
||||||
eq_(g.maxresp, self.maxresp)
|
self.assertEqual(g.maxresp, self.maxresp)
|
||||||
eq_(g.csum, checksum(self.buf))
|
self.assertEqual(g.csum, checksum(self.buf))
|
||||||
eq_(g.address, self.address)
|
self.assertEqual(g.address, self.address)
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
igmp_values = {'msgtype': repr(self.msgtype),
|
igmp_values = {'msgtype': repr(self.msgtype),
|
||||||
@ -145,27 +144,26 @@ class Test_igmp(unittest.TestCase):
|
|||||||
if k in igmp_values])
|
if k in igmp_values])
|
||||||
g_str = '%s(%s)' % (igmp.__name__, _g_str)
|
g_str = '%s(%s)' % (igmp.__name__, _g_str)
|
||||||
|
|
||||||
eq_(str(self.g), g_str)
|
self.assertEqual(str(self.g), g_str)
|
||||||
eq_(repr(self.g), g_str)
|
self.assertEqual(repr(self.g), g_str)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_igmp(self):
|
def test_malformed_igmp(self):
|
||||||
m_short_buf = self.buf[1:igmp._MIN_LEN]
|
m_short_buf = self.buf[1:igmp._MIN_LEN]
|
||||||
igmp.parser(m_short_buf)
|
self.assertRaises(Exception, igmp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
ig = igmp()
|
ig = igmp()
|
||||||
buf = ig.serialize(bytearray(), None)
|
buf = ig.serialize(bytearray(), None)
|
||||||
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0x11)
|
self.assertEqual(res[0], 0x11)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.g.to_jsondict()
|
jsondict = self.g.to_jsondict()
|
||||||
g = igmp.from_jsondict(jsondict['igmp'])
|
g = igmp.from_jsondict(jsondict['igmp'])
|
||||||
eq_(str(self.g), str(g))
|
self.assertEqual(str(self.g), str(g))
|
||||||
|
|
||||||
|
|
||||||
class Test_igmpv3_query(unittest.TestCase):
|
class Test_igmpv3_query(unittest.TestCase):
|
||||||
@ -216,15 +214,15 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.msgtype, self.g.msgtype)
|
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||||
eq_(self.maxresp, self.g.maxresp)
|
self.assertEqual(self.maxresp, self.g.maxresp)
|
||||||
eq_(self.csum, self.g.csum)
|
self.assertEqual(self.csum, self.g.csum)
|
||||||
eq_(self.address, self.g.address)
|
self.assertEqual(self.address, self.g.address)
|
||||||
eq_(self.s_flg, self.g.s_flg)
|
self.assertEqual(self.s_flg, self.g.s_flg)
|
||||||
eq_(self.qrv, self.g.qrv)
|
self.assertEqual(self.qrv, self.g.qrv)
|
||||||
eq_(self.qqic, self.g.qqic)
|
self.assertEqual(self.qqic, self.g.qqic)
|
||||||
eq_(self.num, self.g.num)
|
self.assertEqual(self.num, self.g.num)
|
||||||
eq_(self.srcs, self.g.srcs)
|
self.assertEqual(self.srcs, self.g.srcs)
|
||||||
|
|
||||||
def test_init_with_srcs(self):
|
def test_init_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -237,15 +235,15 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res.msgtype, self.msgtype)
|
self.assertEqual(res.msgtype, self.msgtype)
|
||||||
eq_(res.maxresp, self.maxresp)
|
self.assertEqual(res.maxresp, self.maxresp)
|
||||||
eq_(res.csum, self.csum)
|
self.assertEqual(res.csum, self.csum)
|
||||||
eq_(res.address, self.address)
|
self.assertEqual(res.address, self.address)
|
||||||
eq_(res.s_flg, self.s_flg)
|
self.assertEqual(res.s_flg, self.s_flg)
|
||||||
eq_(res.qrv, self.qrv)
|
self.assertEqual(res.qrv, self.qrv)
|
||||||
eq_(res.qqic, self.qqic)
|
self.assertEqual(res.qqic, self.qqic)
|
||||||
eq_(res.num, self.num)
|
self.assertEqual(res.num, self.num)
|
||||||
eq_(res.srcs, self.srcs)
|
self.assertEqual(res.srcs, self.srcs)
|
||||||
|
|
||||||
def test_parser_with_srcs(self):
|
def test_parser_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -258,13 +256,13 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
|
|
||||||
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], self.msgtype)
|
self.assertEqual(res[0], self.msgtype)
|
||||||
eq_(res[1], self.maxresp)
|
self.assertEqual(res[1], self.maxresp)
|
||||||
eq_(res[2], checksum(self.buf))
|
self.assertEqual(res[2], checksum(self.buf))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
eq_(res[4], self.s_qrv)
|
self.assertEqual(res[4], self.s_qrv)
|
||||||
eq_(res[5], self.qqic)
|
self.assertEqual(res[5], self.qqic)
|
||||||
eq_(res[6], self.num)
|
self.assertEqual(res[6], self.num)
|
||||||
|
|
||||||
def test_serialize_with_srcs(self):
|
def test_serialize_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -276,16 +274,16 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
||||||
igmpv3_query._MIN_LEN)
|
igmpv3_query._MIN_LEN)
|
||||||
|
|
||||||
eq_(res[0], self.msgtype)
|
self.assertEqual(res[0], self.msgtype)
|
||||||
eq_(res[1], self.maxresp)
|
self.assertEqual(res[1], self.maxresp)
|
||||||
eq_(res[2], checksum(self.buf))
|
self.assertEqual(res[2], checksum(self.buf))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
eq_(res[4], self.s_qrv)
|
self.assertEqual(res[4], self.s_qrv)
|
||||||
eq_(res[5], self.qqic)
|
self.assertEqual(res[5], self.qqic)
|
||||||
eq_(res[6], self.num)
|
self.assertEqual(res[6], self.num)
|
||||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||||
|
|
||||||
def _build_igmp(self):
|
def _build_igmp(self):
|
||||||
dl_dst = '11:22:33:44:55:66'
|
dl_dst = '11:22:33:44:55:66'
|
||||||
@ -312,25 +310,25 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
p = self._build_igmp()
|
p = self._build_igmp()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
i = self.find_protocol(p, "ipv4")
|
i = self.find_protocol(p, "ipv4")
|
||||||
ok_(i)
|
self.assertTrue(i)
|
||||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||||
|
|
||||||
g = self.find_protocol(p, "igmpv3_query")
|
g = self.find_protocol(p, "igmpv3_query")
|
||||||
ok_(g)
|
self.assertTrue(g)
|
||||||
|
|
||||||
eq_(g.msgtype, self.msgtype)
|
self.assertEqual(g.msgtype, self.msgtype)
|
||||||
eq_(g.maxresp, self.maxresp)
|
self.assertEqual(g.maxresp, self.maxresp)
|
||||||
eq_(g.csum, checksum(self.buf))
|
self.assertEqual(g.csum, checksum(self.buf))
|
||||||
eq_(g.address, self.address)
|
self.assertEqual(g.address, self.address)
|
||||||
eq_(g.s_flg, self.s_flg)
|
self.assertEqual(g.s_flg, self.s_flg)
|
||||||
eq_(g.qrv, self.qrv)
|
self.assertEqual(g.qrv, self.qrv)
|
||||||
eq_(g.qqic, self.qqic)
|
self.assertEqual(g.qqic, self.qqic)
|
||||||
eq_(g.num, self.num)
|
self.assertEqual(g.num, self.num)
|
||||||
eq_(g.srcs, self.srcs)
|
self.assertEqual(g.srcs, self.srcs)
|
||||||
|
|
||||||
def test_build_igmp_with_srcs(self):
|
def test_build_igmp_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -351,14 +349,13 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
if k in igmp_values])
|
if k in igmp_values])
|
||||||
g_str = '%s(%s)' % (igmpv3_query.__name__, _g_str)
|
g_str = '%s(%s)' % (igmpv3_query.__name__, _g_str)
|
||||||
|
|
||||||
eq_(str(self.g), g_str)
|
self.assertEqual(str(self.g), g_str)
|
||||||
eq_(repr(self.g), g_str)
|
self.assertEqual(repr(self.g), g_str)
|
||||||
|
|
||||||
def test_to_string_with_srcs(self):
|
def test_to_string_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
self.test_to_string()
|
self.test_to_string()
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_num_larger_than_srcs(self):
|
def test_num_larger_than_srcs(self):
|
||||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||||
self.num = len(self.srcs) + 1
|
self.num = len(self.srcs) + 1
|
||||||
@ -371,9 +368,8 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
self.g = igmpv3_query(
|
self.g = igmpv3_query(
|
||||||
self.msgtype, self.maxresp, self.csum, self.address,
|
self.msgtype, self.maxresp, self.csum, self.address,
|
||||||
self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
|
self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
|
||||||
self.test_parser()
|
self.assertRaises(Exception, self.test_parser)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_num_smaller_than_srcs(self):
|
def test_num_smaller_than_srcs(self):
|
||||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||||
self.num = len(self.srcs) - 1
|
self.num = len(self.srcs) - 1
|
||||||
@ -386,7 +382,7 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
self.g = igmpv3_query(
|
self.g = igmpv3_query(
|
||||||
self.msgtype, self.maxresp, self.csum, self.address,
|
self.msgtype, self.maxresp, self.csum, self.address,
|
||||||
self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
|
self.s_flg, self.qrv, self.qqic, self.num, self.srcs)
|
||||||
self.test_parser()
|
self.assertRaises(Exception, self.test_parser)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||||
@ -397,13 +393,13 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
buf = bytearray(buf)
|
buf = bytearray(buf)
|
||||||
pack_into('!H', buf, 2, 0)
|
pack_into('!H', buf, 2, 0)
|
||||||
|
|
||||||
eq_(res[0], IGMP_TYPE_QUERY)
|
self.assertEqual(res[0], IGMP_TYPE_QUERY)
|
||||||
eq_(res[1], 100)
|
self.assertEqual(res[1], 100)
|
||||||
eq_(res[2], checksum(buf))
|
self.assertEqual(res[2], checksum(buf))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
eq_(res[4], 2)
|
self.assertEqual(res[4], 2)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
eq_(res[6], 0)
|
self.assertEqual(res[6], 0)
|
||||||
|
|
||||||
# srcs without num
|
# srcs without num
|
||||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||||
@ -415,24 +411,24 @@ class Test_igmpv3_query(unittest.TestCase):
|
|||||||
buf = bytearray(buf)
|
buf = bytearray(buf)
|
||||||
pack_into('!H', buf, 2, 0)
|
pack_into('!H', buf, 2, 0)
|
||||||
|
|
||||||
eq_(res[0], IGMP_TYPE_QUERY)
|
self.assertEqual(res[0], IGMP_TYPE_QUERY)
|
||||||
eq_(res[1], 100)
|
self.assertEqual(res[1], 100)
|
||||||
eq_(res[2], checksum(buf))
|
self.assertEqual(res[2], checksum(buf))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
eq_(res[4], 2)
|
self.assertEqual(res[4], 2)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
eq_(res[6], len(srcs))
|
self.assertEqual(res[6], len(srcs))
|
||||||
|
|
||||||
res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN)
|
res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN)
|
||||||
|
|
||||||
eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||||
eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
self.assertEqual(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||||
eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
self.assertEqual(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.g.to_jsondict()
|
jsondict = self.g.to_jsondict()
|
||||||
g = igmpv3_query.from_jsondict(jsondict['igmpv3_query'])
|
g = igmpv3_query.from_jsondict(jsondict['igmpv3_query'])
|
||||||
eq_(str(self.g), str(g))
|
self.assertEqual(str(self.g), str(g))
|
||||||
|
|
||||||
def test_json_with_srcs(self):
|
def test_json_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -487,10 +483,10 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.msgtype, self.g.msgtype)
|
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||||
eq_(self.csum, self.g.csum)
|
self.assertEqual(self.csum, self.g.csum)
|
||||||
eq_(self.record_num, self.g.record_num)
|
self.assertEqual(self.record_num, self.g.record_num)
|
||||||
eq_(self.records, self.g.records)
|
self.assertEqual(self.records, self.g.records)
|
||||||
|
|
||||||
def test_init_with_records(self):
|
def test_init_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
@ -503,10 +499,10 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res.msgtype, self.msgtype)
|
self.assertEqual(res.msgtype, self.msgtype)
|
||||||
eq_(res.csum, self.csum)
|
self.assertEqual(res.csum, self.csum)
|
||||||
eq_(res.record_num, self.record_num)
|
self.assertEqual(res.record_num, self.record_num)
|
||||||
eq_(repr(res.records), repr(self.records))
|
self.assertEqual(repr(res.records), repr(self.records))
|
||||||
|
|
||||||
def test_parser_with_records(self):
|
def test_parser_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
@ -519,9 +515,9 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
|
|
||||||
res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], self.msgtype)
|
self.assertEqual(res[0], self.msgtype)
|
||||||
eq_(res[1], checksum(self.buf))
|
self.assertEqual(res[1], checksum(self.buf))
|
||||||
eq_(res[2], self.record_num)
|
self.assertEqual(res[2], self.record_num)
|
||||||
|
|
||||||
def test_serialize_with_records(self):
|
def test_serialize_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
@ -539,13 +535,13 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
offset += len(rec3)
|
offset += len(rec3)
|
||||||
rec4 = igmpv3_report_group.parser(buf[offset:])
|
rec4 = igmpv3_report_group.parser(buf[offset:])
|
||||||
|
|
||||||
eq_(res[0], self.msgtype)
|
self.assertEqual(res[0], self.msgtype)
|
||||||
eq_(res[1], checksum(self.buf))
|
self.assertEqual(res[1], checksum(self.buf))
|
||||||
eq_(res[2], self.record_num)
|
self.assertEqual(res[2], self.record_num)
|
||||||
eq_(repr(rec1), repr(self.record1))
|
self.assertEqual(repr(rec1), repr(self.record1))
|
||||||
eq_(repr(rec2), repr(self.record2))
|
self.assertEqual(repr(rec2), repr(self.record2))
|
||||||
eq_(repr(rec3), repr(self.record3))
|
self.assertEqual(repr(rec3), repr(self.record3))
|
||||||
eq_(repr(rec4), repr(self.record4))
|
self.assertEqual(repr(rec4), repr(self.record4))
|
||||||
|
|
||||||
def _build_igmp(self):
|
def _build_igmp(self):
|
||||||
dl_dst = '11:22:33:44:55:66'
|
dl_dst = '11:22:33:44:55:66'
|
||||||
@ -572,20 +568,20 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
p = self._build_igmp()
|
p = self._build_igmp()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
i = self.find_protocol(p, "ipv4")
|
i = self.find_protocol(p, "ipv4")
|
||||||
ok_(i)
|
self.assertTrue(i)
|
||||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||||
|
|
||||||
g = self.find_protocol(p, "igmpv3_report")
|
g = self.find_protocol(p, "igmpv3_report")
|
||||||
ok_(g)
|
self.assertTrue(g)
|
||||||
|
|
||||||
eq_(g.msgtype, self.msgtype)
|
self.assertEqual(g.msgtype, self.msgtype)
|
||||||
eq_(g.csum, checksum(self.buf))
|
self.assertEqual(g.csum, checksum(self.buf))
|
||||||
eq_(g.record_num, self.record_num)
|
self.assertEqual(g.record_num, self.record_num)
|
||||||
eq_(g.records, self.records)
|
self.assertEqual(g.records, self.records)
|
||||||
|
|
||||||
def test_build_igmp_with_records(self):
|
def test_build_igmp_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
@ -601,14 +597,13 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
if k in igmp_values])
|
if k in igmp_values])
|
||||||
g_str = '%s(%s)' % (igmpv3_report.__name__, _g_str)
|
g_str = '%s(%s)' % (igmpv3_report.__name__, _g_str)
|
||||||
|
|
||||||
eq_(str(self.g), g_str)
|
self.assertEqual(str(self.g), g_str)
|
||||||
eq_(repr(self.g), g_str)
|
self.assertEqual(repr(self.g), g_str)
|
||||||
|
|
||||||
def test_to_string_with_records(self):
|
def test_to_string_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
self.test_to_string()
|
self.test_to_string()
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_record_num_larger_than_records(self):
|
def test_record_num_larger_than_records(self):
|
||||||
self.record1 = igmpv3_report_group(
|
self.record1 = igmpv3_report_group(
|
||||||
MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
|
MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
|
||||||
@ -631,9 +626,8 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
self.buf += self.record4.serialize()
|
self.buf += self.record4.serialize()
|
||||||
self.g = igmpv3_report(
|
self.g = igmpv3_report(
|
||||||
self.msgtype, self.csum, self.record_num, self.records)
|
self.msgtype, self.csum, self.record_num, self.records)
|
||||||
self.test_parser()
|
self.assertRaises(Exception, self.test_parser)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_record_num_smaller_than_records(self):
|
def test_record_num_smaller_than_records(self):
|
||||||
self.record1 = igmpv3_report_group(
|
self.record1 = igmpv3_report_group(
|
||||||
MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
|
MODE_IS_INCLUDE, 0, 0, '225.0.0.1')
|
||||||
@ -656,7 +650,7 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
self.buf += self.record4.serialize()
|
self.buf += self.record4.serialize()
|
||||||
self.g = igmpv3_report(
|
self.g = igmpv3_report(
|
||||||
self.msgtype, self.csum, self.record_num, self.records)
|
self.msgtype, self.csum, self.record_num, self.records)
|
||||||
self.test_parser()
|
self.assertRaises(Exception, self.test_parser)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||||
@ -667,9 +661,9 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
buf = bytearray(buf)
|
buf = bytearray(buf)
|
||||||
pack_into('!H', buf, 2, 0)
|
pack_into('!H', buf, 2, 0)
|
||||||
|
|
||||||
eq_(res[0], IGMP_TYPE_REPORT_V3)
|
self.assertEqual(res[0], IGMP_TYPE_REPORT_V3)
|
||||||
eq_(res[1], checksum(buf))
|
self.assertEqual(res[1], checksum(buf))
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
|
|
||||||
# records without record_num
|
# records without record_num
|
||||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||||
@ -691,14 +685,14 @@ class Test_igmpv3_report(unittest.TestCase):
|
|||||||
buf = bytearray(buf)
|
buf = bytearray(buf)
|
||||||
pack_into('!H', buf, 2, 0)
|
pack_into('!H', buf, 2, 0)
|
||||||
|
|
||||||
eq_(res[0], IGMP_TYPE_REPORT_V3)
|
self.assertEqual(res[0], IGMP_TYPE_REPORT_V3)
|
||||||
eq_(res[1], checksum(buf))
|
self.assertEqual(res[1], checksum(buf))
|
||||||
eq_(res[2], len(records))
|
self.assertEqual(res[2], len(records))
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.g.to_jsondict()
|
jsondict = self.g.to_jsondict()
|
||||||
g = igmpv3_report.from_jsondict(jsondict['igmpv3_report'])
|
g = igmpv3_report.from_jsondict(jsondict['igmpv3_report'])
|
||||||
eq_(str(self.g), str(g))
|
self.assertEqual(str(self.g), str(g))
|
||||||
|
|
||||||
def test_json_with_records(self):
|
def test_json_with_records(self):
|
||||||
self.setUp_with_records()
|
self.setUp_with_records()
|
||||||
@ -767,12 +761,12 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.g.type_)
|
self.assertEqual(self.type_, self.g.type_)
|
||||||
eq_(self.aux_len, self.g.aux_len)
|
self.assertEqual(self.aux_len, self.g.aux_len)
|
||||||
eq_(self.num, self.g.num)
|
self.assertEqual(self.num, self.g.num)
|
||||||
eq_(self.address, self.g.address)
|
self.assertEqual(self.address, self.g.address)
|
||||||
eq_(self.srcs, self.g.srcs)
|
self.assertEqual(self.srcs, self.g.srcs)
|
||||||
eq_(self.aux, self.g.aux)
|
self.assertEqual(self.aux, self.g.aux)
|
||||||
|
|
||||||
def test_init_with_srcs(self):
|
def test_init_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -793,12 +787,12 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res.type_, self.type_)
|
self.assertEqual(res.type_, self.type_)
|
||||||
eq_(res.aux_len, self.aux_len)
|
self.assertEqual(res.aux_len, self.aux_len)
|
||||||
eq_(res.num, self.num)
|
self.assertEqual(res.num, self.num)
|
||||||
eq_(res.address, self.address)
|
self.assertEqual(res.address, self.address)
|
||||||
eq_(res.srcs, self.srcs)
|
self.assertEqual(res.srcs, self.srcs)
|
||||||
eq_(res.aux, self.aux)
|
self.assertEqual(res.aux, self.aux)
|
||||||
|
|
||||||
def test_parser_with_srcs(self):
|
def test_parser_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -816,10 +810,10 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
buf = self.g.serialize()
|
buf = self.g.serialize()
|
||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], self.type_)
|
self.assertEqual(res[0], self.type_)
|
||||||
eq_(res[1], self.aux_len)
|
self.assertEqual(res[1], self.aux_len)
|
||||||
eq_(res[2], self.num)
|
self.assertEqual(res[2], self.num)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
|
|
||||||
def test_serialize_with_srcs(self):
|
def test_serialize_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -827,13 +821,13 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
||||||
igmpv3_report_group._MIN_LEN)
|
igmpv3_report_group._MIN_LEN)
|
||||||
eq_(res[0], self.type_)
|
self.assertEqual(res[0], self.type_)
|
||||||
eq_(res[1], self.aux_len)
|
self.assertEqual(res[1], self.aux_len)
|
||||||
eq_(res[2], self.num)
|
self.assertEqual(res[2], self.num)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||||
|
|
||||||
def test_serialize_with_aux(self):
|
def test_serialize_with_aux(self):
|
||||||
self.setUp_with_aux()
|
self.setUp_with_aux()
|
||||||
@ -841,11 +835,11 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
||||||
igmpv3_report_group._MIN_LEN)
|
igmpv3_report_group._MIN_LEN)
|
||||||
eq_(res[0], self.type_)
|
self.assertEqual(res[0], self.type_)
|
||||||
eq_(res[1], self.aux_len)
|
self.assertEqual(res[1], self.aux_len)
|
||||||
eq_(res[2], self.num)
|
self.assertEqual(res[2], self.num)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
eq_(aux, self.aux)
|
self.assertEqual(aux, self.aux)
|
||||||
|
|
||||||
def test_serialize_with_srcs_and_aux(self):
|
def test_serialize_with_srcs_and_aux(self):
|
||||||
self.setUp_with_srcs_and_aux()
|
self.setUp_with_srcs_and_aux()
|
||||||
@ -855,14 +849,14 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
igmpv3_report_group._MIN_LEN)
|
igmpv3_report_group._MIN_LEN)
|
||||||
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
||||||
igmpv3_report_group._MIN_LEN + 12)
|
igmpv3_report_group._MIN_LEN + 12)
|
||||||
eq_(res[0], self.type_)
|
self.assertEqual(res[0], self.type_)
|
||||||
eq_(res[1], self.aux_len)
|
self.assertEqual(res[1], self.aux_len)
|
||||||
eq_(res[2], self.num)
|
self.assertEqual(res[2], self.num)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||||
eq_(aux, self.aux)
|
self.assertEqual(aux, self.aux)
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
igmp_values = {'type_': repr(self.type_),
|
igmp_values = {'type_': repr(self.type_),
|
||||||
@ -876,8 +870,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
if k in igmp_values])
|
if k in igmp_values])
|
||||||
g_str = '%s(%s)' % (igmpv3_report_group.__name__, _g_str)
|
g_str = '%s(%s)' % (igmpv3_report_group.__name__, _g_str)
|
||||||
|
|
||||||
eq_(str(self.g), g_str)
|
self.assertEqual(str(self.g), g_str)
|
||||||
eq_(repr(self.g), g_str)
|
self.assertEqual(repr(self.g), g_str)
|
||||||
|
|
||||||
def test_to_string_with_srcs(self):
|
def test_to_string_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
@ -892,21 +886,20 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
self.test_to_string()
|
self.test_to_string()
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(len(self.g), 8)
|
self.assertEqual(len(self.g), 8)
|
||||||
|
|
||||||
def test_len_with_srcs(self):
|
def test_len_with_srcs(self):
|
||||||
self.setUp_with_srcs()
|
self.setUp_with_srcs()
|
||||||
eq_(len(self.g), 20)
|
self.assertEqual(len(self.g), 20)
|
||||||
|
|
||||||
def test_len_with_aux(self):
|
def test_len_with_aux(self):
|
||||||
self.setUp_with_aux()
|
self.setUp_with_aux()
|
||||||
eq_(len(self.g), 16)
|
self.assertEqual(len(self.g), 16)
|
||||||
|
|
||||||
def test_len_with_srcs_and_aux(self):
|
def test_len_with_srcs_and_aux(self):
|
||||||
self.setUp_with_srcs_and_aux()
|
self.setUp_with_srcs_and_aux()
|
||||||
eq_(len(self.g), 28)
|
self.assertEqual(len(self.g), 28)
|
||||||
|
|
||||||
@raises
|
|
||||||
def test_num_larger_than_srcs(self):
|
def test_num_larger_than_srcs(self):
|
||||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||||
self.num = len(self.srcs) + 1
|
self.num = len(self.srcs) + 1
|
||||||
@ -918,9 +911,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
self.g = igmpv3_report_group(
|
self.g = igmpv3_report_group(
|
||||||
self.type_, self.aux_len, self.num, self.address,
|
self.type_, self.aux_len, self.num, self.address,
|
||||||
self.srcs, self.aux)
|
self.srcs, self.aux)
|
||||||
self.test_parser()
|
self.assertRaises(AssertionError, self.test_parser)
|
||||||
|
|
||||||
@raises
|
|
||||||
def test_num_smaller_than_srcs(self):
|
def test_num_smaller_than_srcs(self):
|
||||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||||
self.num = len(self.srcs) - 1
|
self.num = len(self.srcs) - 1
|
||||||
@ -932,9 +924,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
self.g = igmpv3_report_group(
|
self.g = igmpv3_report_group(
|
||||||
self.type_, self.aux_len, self.num, self.address,
|
self.type_, self.aux_len, self.num, self.address,
|
||||||
self.srcs, self.aux)
|
self.srcs, self.aux)
|
||||||
self.test_parser()
|
self.assertRaises(AssertionError, self.test_parser)
|
||||||
|
|
||||||
@raises
|
|
||||||
def test_aux_len_larger_than_aux(self):
|
def test_aux_len_larger_than_aux(self):
|
||||||
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||||
self.aux_len = len(self.aux) // 4 + 1
|
self.aux_len = len(self.aux) // 4 + 1
|
||||||
@ -945,9 +936,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
self.g = igmpv3_report_group(
|
self.g = igmpv3_report_group(
|
||||||
self.type_, self.aux_len, self.num, self.address,
|
self.type_, self.aux_len, self.num, self.address,
|
||||||
self.srcs, self.aux)
|
self.srcs, self.aux)
|
||||||
self.test_parser()
|
self.assertRaises(Exception, self.test_parser)
|
||||||
|
|
||||||
@raises
|
|
||||||
def test_aux_len_smaller_than_aux(self):
|
def test_aux_len_smaller_than_aux(self):
|
||||||
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||||
self.aux_len = len(self.aux) // 4 - 1
|
self.aux_len = len(self.aux) // 4 - 1
|
||||||
@ -958,17 +948,17 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
self.g = igmpv3_report_group(
|
self.g = igmpv3_report_group(
|
||||||
self.type_, self.aux_len, self.num, self.address,
|
self.type_, self.aux_len, self.num, self.address,
|
||||||
self.srcs, self.aux)
|
self.srcs, self.aux)
|
||||||
self.test_parser()
|
self.assertRaises(AssertionError, self.test_parser)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
rep = igmpv3_report_group()
|
rep = igmpv3_report_group()
|
||||||
buf = rep.serialize()
|
buf = rep.serialize()
|
||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
|
|
||||||
# srcs without num
|
# srcs without num
|
||||||
srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||||
@ -976,17 +966,17 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
buf = rep.serialize()
|
buf = rep.serialize()
|
||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[2], len(srcs))
|
self.assertEqual(res[2], len(srcs))
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
|
|
||||||
res = unpack_from('4s4s4s', six.binary_type(buf),
|
res = unpack_from('4s4s4s', six.binary_type(buf),
|
||||||
igmpv3_report_group._MIN_LEN)
|
igmpv3_report_group._MIN_LEN)
|
||||||
|
|
||||||
eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||||
eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
self.assertEqual(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||||
eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
self.assertEqual(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||||
|
|
||||||
# aux without aux_len
|
# aux without aux_len
|
||||||
aux = b'abcde'
|
aux = b'abcde'
|
||||||
@ -994,8 +984,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
|||||||
buf = rep.serialize()
|
buf = rep.serialize()
|
||||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
eq_(res[1], 2)
|
self.assertEqual(res[1], 2)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||||
eq_(buf[igmpv3_report_group._MIN_LEN:], b'abcde\x00\x00\x00')
|
self.assertEqual(buf[igmpv3_report_group._MIN_LEN:], b'abcde\x00\x00\x00')
|
||||||
|
@ -20,7 +20,6 @@ import logging
|
|||||||
import six
|
import six
|
||||||
import struct
|
import struct
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import ether, inet
|
from os_ken.ofproto import ether, inet
|
||||||
from os_ken.lib.packet import packet_utils
|
from os_ken.lib.packet import packet_utils
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
@ -74,64 +73,63 @@ class Test_ipv4(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.version, self.ip.version)
|
self.assertEqual(self.version, self.ip.version)
|
||||||
eq_(self.header_length, self.ip.header_length)
|
self.assertEqual(self.header_length, self.ip.header_length)
|
||||||
eq_(self.tos, self.ip.tos)
|
self.assertEqual(self.tos, self.ip.tos)
|
||||||
eq_(self.total_length, self.ip.total_length)
|
self.assertEqual(self.total_length, self.ip.total_length)
|
||||||
eq_(self.identification, self.ip.identification)
|
self.assertEqual(self.identification, self.ip.identification)
|
||||||
eq_(self.flags, self.ip.flags)
|
self.assertEqual(self.flags, self.ip.flags)
|
||||||
eq_(self.offset, self.ip.offset)
|
self.assertEqual(self.offset, self.ip.offset)
|
||||||
eq_(self.ttl, self.ip.ttl)
|
self.assertEqual(self.ttl, self.ip.ttl)
|
||||||
eq_(self.proto, self.ip.proto)
|
self.assertEqual(self.proto, self.ip.proto)
|
||||||
eq_(self.csum, self.ip.csum)
|
self.assertEqual(self.csum, self.ip.csum)
|
||||||
eq_(self.src, self.ip.src)
|
self.assertEqual(self.src, self.ip.src)
|
||||||
eq_(self.dst, self.ip.dst)
|
self.assertEqual(self.dst, self.ip.dst)
|
||||||
eq_(self.length, len(self.ip))
|
self.assertEqual(self.length, len(self.ip))
|
||||||
eq_(self.option, self.ip.option)
|
self.assertEqual(self.option, self.ip.option)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
res, ptype, _ = self.ip.parser(self.buf)
|
res, ptype, _ = self.ip.parser(self.buf)
|
||||||
|
|
||||||
eq_(res.version, self.version)
|
self.assertEqual(res.version, self.version)
|
||||||
eq_(res.header_length, self.header_length)
|
self.assertEqual(res.header_length, self.header_length)
|
||||||
eq_(res.tos, self.tos)
|
self.assertEqual(res.tos, self.tos)
|
||||||
eq_(res.total_length, self.total_length)
|
self.assertEqual(res.total_length, self.total_length)
|
||||||
eq_(res.identification, self.identification)
|
self.assertEqual(res.identification, self.identification)
|
||||||
eq_(res.flags, self.flags)
|
self.assertEqual(res.flags, self.flags)
|
||||||
eq_(res.offset, self.offset)
|
self.assertEqual(res.offset, self.offset)
|
||||||
eq_(res.ttl, self.ttl)
|
self.assertEqual(res.ttl, self.ttl)
|
||||||
eq_(res.proto, self.proto)
|
self.assertEqual(res.proto, self.proto)
|
||||||
eq_(res.csum, self.csum)
|
self.assertEqual(res.csum, self.csum)
|
||||||
eq_(res.src, self.src)
|
self.assertEqual(res.src, self.src)
|
||||||
eq_(res.dst, self.dst)
|
self.assertEqual(res.dst, self.dst)
|
||||||
eq_(ptype, tcp)
|
self.assertEqual(ptype, tcp)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.ip.serialize(bytearray(), None)
|
buf = self.ip.serialize(bytearray(), None)
|
||||||
res = struct.unpack_from(ipv4._PACK_STR, six.binary_type(buf))
|
res = struct.unpack_from(ipv4._PACK_STR, six.binary_type(buf))
|
||||||
option = buf[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)]
|
option = buf[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)]
|
||||||
|
|
||||||
eq_(res[0], self.ver_hlen)
|
self.assertEqual(res[0], self.ver_hlen)
|
||||||
eq_(res[1], self.tos)
|
self.assertEqual(res[1], self.tos)
|
||||||
eq_(res[2], self.total_length)
|
self.assertEqual(res[2], self.total_length)
|
||||||
eq_(res[3], self.identification)
|
self.assertEqual(res[3], self.identification)
|
||||||
eq_(res[4], self.flg_off)
|
self.assertEqual(res[4], self.flg_off)
|
||||||
eq_(res[5], self.ttl)
|
self.assertEqual(res[5], self.ttl)
|
||||||
eq_(res[6], self.proto)
|
self.assertEqual(res[6], self.proto)
|
||||||
eq_(res[8], addrconv.ipv4.text_to_bin(self.src))
|
self.assertEqual(res[8], addrconv.ipv4.text_to_bin(self.src))
|
||||||
eq_(res[9], addrconv.ipv4.text_to_bin(self.dst))
|
self.assertEqual(res[9], addrconv.ipv4.text_to_bin(self.dst))
|
||||||
eq_(option, self.option)
|
self.assertEqual(option, self.option)
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
csum = packet_utils.checksum(buf)
|
csum = packet_utils.checksum(buf)
|
||||||
eq_(csum, 0)
|
self.assertEqual(csum, 0)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_ipv4(self):
|
def test_malformed_ipv4(self):
|
||||||
m_short_buf = self.buf[1:ipv4._MIN_LEN]
|
m_short_buf = self.buf[1:ipv4._MIN_LEN]
|
||||||
ipv4.parser(m_short_buf)
|
self.assertRaises(Exception, ipv4.parser, m_short_buf)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.ip.to_jsondict()
|
jsondict = self.ip.to_jsondict()
|
||||||
ip = ipv4.from_jsondict(jsondict['ipv4'])
|
ip = ipv4.from_jsondict(jsondict['ipv4'])
|
||||||
eq_(str(self.ip), str(ip))
|
self.assertEqual(str(self.ip), str(ip))
|
||||||
|
@ -20,7 +20,6 @@ import inspect
|
|||||||
import six
|
import six
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.lib import addrconv
|
from os_ken.lib import addrconv
|
||||||
from os_ken.lib import ip
|
from os_ken.lib import ip
|
||||||
from os_ken.lib.packet import ipv6
|
from os_ken.lib.packet import ipv6
|
||||||
@ -228,15 +227,15 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.version, self.ip.version)
|
self.assertEqual(self.version, self.ip.version)
|
||||||
eq_(self.traffic_class, self.ip.traffic_class)
|
self.assertEqual(self.traffic_class, self.ip.traffic_class)
|
||||||
eq_(self.flow_label, self.ip.flow_label)
|
self.assertEqual(self.flow_label, self.ip.flow_label)
|
||||||
eq_(self.payload_length, self.ip.payload_length)
|
self.assertEqual(self.payload_length, self.ip.payload_length)
|
||||||
eq_(self.nxt, self.ip.nxt)
|
self.assertEqual(self.nxt, self.ip.nxt)
|
||||||
eq_(self.hop_limit, self.ip.hop_limit)
|
self.assertEqual(self.hop_limit, self.ip.hop_limit)
|
||||||
eq_(self.src, self.ip.src)
|
self.assertEqual(self.src, self.ip.src)
|
||||||
eq_(self.dst, self.ip.dst)
|
self.assertEqual(self.dst, self.ip.dst)
|
||||||
eq_(str(self.ext_hdrs), str(self.ip.ext_hdrs))
|
self.assertEqual(str(self.ext_hdrs), str(self.ip.ext_hdrs))
|
||||||
|
|
||||||
def test_init_with_hop_opts(self):
|
def test_init_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
@ -269,15 +268,15 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(self.version, res.version)
|
self.assertEqual(self.version, res.version)
|
||||||
eq_(self.traffic_class, res.traffic_class)
|
self.assertEqual(self.traffic_class, res.traffic_class)
|
||||||
eq_(self.flow_label, res.flow_label)
|
self.assertEqual(self.flow_label, res.flow_label)
|
||||||
eq_(self.payload_length, res.payload_length)
|
self.assertEqual(self.payload_length, res.payload_length)
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.hop_limit, res.hop_limit)
|
self.assertEqual(self.hop_limit, res.hop_limit)
|
||||||
eq_(self.src, res.src)
|
self.assertEqual(self.src, res.src)
|
||||||
eq_(self.dst, res.dst)
|
self.assertEqual(self.dst, res.dst)
|
||||||
eq_(str(self.ext_hdrs), str(res.ext_hdrs))
|
self.assertEqual(str(self.ext_hdrs), str(res.ext_hdrs))
|
||||||
|
|
||||||
def test_parser_with_hop_opts(self):
|
def test_parser_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
@ -310,12 +309,12 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
|
|
||||||
res = struct.unpack_from(ipv6.ipv6._PACK_STR, six.binary_type(buf))
|
res = struct.unpack_from(ipv6.ipv6._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(self.v_tc_flow, res[0])
|
self.assertEqual(self.v_tc_flow, res[0])
|
||||||
eq_(self.payload_length, res[1])
|
self.assertEqual(self.payload_length, res[1])
|
||||||
eq_(self.nxt, res[2])
|
self.assertEqual(self.nxt, res[2])
|
||||||
eq_(self.hop_limit, res[3])
|
self.assertEqual(self.hop_limit, res[3])
|
||||||
eq_(self.src, addrconv.ipv6.bin_to_text(res[4]))
|
self.assertEqual(self.src, addrconv.ipv6.bin_to_text(res[4]))
|
||||||
eq_(self.dst, addrconv.ipv6.bin_to_text(res[5]))
|
self.assertEqual(self.dst, addrconv.ipv6.bin_to_text(res[5]))
|
||||||
|
|
||||||
def test_serialize_with_hop_opts(self):
|
def test_serialize_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
@ -325,7 +324,7 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ip.serialize(data, prev)
|
buf = self.ip.serialize(data, prev)
|
||||||
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
||||||
eq_(repr(self.hop_opts), repr(hop_opts))
|
self.assertEqual(repr(self.hop_opts), repr(hop_opts))
|
||||||
|
|
||||||
def test_serialize_with_dst_opts(self):
|
def test_serialize_with_dst_opts(self):
|
||||||
self.setUp_with_dst_opts()
|
self.setUp_with_dst_opts()
|
||||||
@ -335,7 +334,7 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ip.serialize(data, prev)
|
buf = self.ip.serialize(data, prev)
|
||||||
dst_opts = ipv6.dst_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
dst_opts = ipv6.dst_opts.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
||||||
eq_(repr(self.dst_opts), repr(dst_opts))
|
self.assertEqual(repr(self.dst_opts), repr(dst_opts))
|
||||||
|
|
||||||
def test_serialize_with_routing_type3(self):
|
def test_serialize_with_routing_type3(self):
|
||||||
self.setUp_with_routing_type3()
|
self.setUp_with_routing_type3()
|
||||||
@ -345,7 +344,7 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ip.serialize(data, prev)
|
buf = self.ip.serialize(data, prev)
|
||||||
routing = ipv6.routing.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
routing = ipv6.routing.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
||||||
eq_(repr(self.routing), repr(routing))
|
self.assertEqual(repr(self.routing), repr(routing))
|
||||||
|
|
||||||
def test_serialize_with_fragment(self):
|
def test_serialize_with_fragment(self):
|
||||||
self.setUp_with_fragment()
|
self.setUp_with_fragment()
|
||||||
@ -355,7 +354,7 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ip.serialize(data, prev)
|
buf = self.ip.serialize(data, prev)
|
||||||
fragment = ipv6.fragment.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
fragment = ipv6.fragment.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
||||||
eq_(repr(self.fragment), repr(fragment))
|
self.assertEqual(repr(self.fragment), repr(fragment))
|
||||||
|
|
||||||
def test_serialize_with_auth(self):
|
def test_serialize_with_auth(self):
|
||||||
self.setUp_with_auth()
|
self.setUp_with_auth()
|
||||||
@ -365,7 +364,7 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
prev = None
|
prev = None
|
||||||
buf = self.ip.serialize(data, prev)
|
buf = self.ip.serialize(data, prev)
|
||||||
auth = ipv6.auth.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
auth = ipv6.auth.parser(six.binary_type(buf[ipv6.ipv6._MIN_LEN:]))
|
||||||
eq_(repr(self.auth), repr(auth))
|
self.assertEqual(repr(self.auth), repr(auth))
|
||||||
|
|
||||||
def test_serialize_with_multi_headers(self):
|
def test_serialize_with_multi_headers(self):
|
||||||
self.setUp_with_multi_headers()
|
self.setUp_with_multi_headers()
|
||||||
@ -378,8 +377,8 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[offset:]))
|
hop_opts = ipv6.hop_opts.parser(six.binary_type(buf[offset:]))
|
||||||
offset += len(hop_opts)
|
offset += len(hop_opts)
|
||||||
auth = ipv6.auth.parser(six.binary_type(buf[offset:]))
|
auth = ipv6.auth.parser(six.binary_type(buf[offset:]))
|
||||||
eq_(repr(self.hop_opts), repr(hop_opts))
|
self.assertEqual(repr(self.hop_opts), repr(hop_opts))
|
||||||
eq_(repr(self.auth), repr(auth))
|
self.assertEqual(repr(self.auth), repr(auth))
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
ipv6_values = {'version': self.version,
|
ipv6_values = {'version': self.version,
|
||||||
@ -396,8 +395,8 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
if k in ipv6_values])
|
if k in ipv6_values])
|
||||||
ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)
|
ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)
|
||||||
|
|
||||||
eq_(str(self.ip), ipv6_str)
|
self.assertEqual(str(self.ip), ipv6_str)
|
||||||
eq_(repr(self.ip), ipv6_str)
|
self.assertEqual(repr(self.ip), ipv6_str)
|
||||||
|
|
||||||
def test_to_string_with_hop_opts(self):
|
def test_to_string_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
@ -420,43 +419,43 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
self.test_to_string()
|
self.test_to_string()
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(len(self.ip), 40)
|
self.assertEqual(len(self.ip), 40)
|
||||||
|
|
||||||
def test_len_with_hop_opts(self):
|
def test_len_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
eq_(len(self.ip), 40 + len(self.hop_opts))
|
self.assertEqual(len(self.ip), 40 + len(self.hop_opts))
|
||||||
|
|
||||||
def test_len_with_dst_opts(self):
|
def test_len_with_dst_opts(self):
|
||||||
self.setUp_with_dst_opts()
|
self.setUp_with_dst_opts()
|
||||||
eq_(len(self.ip), 40 + len(self.dst_opts))
|
self.assertEqual(len(self.ip), 40 + len(self.dst_opts))
|
||||||
|
|
||||||
def test_len_with_routing_type3(self):
|
def test_len_with_routing_type3(self):
|
||||||
self.setUp_with_routing_type3()
|
self.setUp_with_routing_type3()
|
||||||
eq_(len(self.ip), 40 + len(self.routing))
|
self.assertEqual(len(self.ip), 40 + len(self.routing))
|
||||||
|
|
||||||
def test_len_with_fragment(self):
|
def test_len_with_fragment(self):
|
||||||
self.setUp_with_fragment()
|
self.setUp_with_fragment()
|
||||||
eq_(len(self.ip), 40 + len(self.fragment))
|
self.assertEqual(len(self.ip), 40 + len(self.fragment))
|
||||||
|
|
||||||
def test_len_with_auth(self):
|
def test_len_with_auth(self):
|
||||||
self.setUp_with_auth()
|
self.setUp_with_auth()
|
||||||
eq_(len(self.ip), 40 + len(self.auth))
|
self.assertEqual(len(self.ip), 40 + len(self.auth))
|
||||||
|
|
||||||
def test_len_with_multi_headers(self):
|
def test_len_with_multi_headers(self):
|
||||||
self.setUp_with_multi_headers()
|
self.setUp_with_multi_headers()
|
||||||
eq_(len(self.ip), 40 + len(self.hop_opts) + len(self.auth))
|
self.assertEqual(len(self.ip), 40 + len(self.hop_opts) + len(self.auth))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
ip = ipv6.ipv6()
|
ip = ipv6.ipv6()
|
||||||
buf = ip.serialize(bytearray(), None)
|
buf = ip.serialize(bytearray(), None)
|
||||||
res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 6 << 28)
|
self.assertEqual(res[0], 6 << 28)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[2], 6)
|
self.assertEqual(res[2], 6)
|
||||||
eq_(res[3], 255)
|
self.assertEqual(res[3], 255)
|
||||||
eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
self.assertEqual(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||||
eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
self.assertEqual(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||||
|
|
||||||
# with extension header
|
# with extension header
|
||||||
ip = ipv6.ipv6(
|
ip = ipv6.ipv6(
|
||||||
@ -467,18 +466,18 @@ class Test_ipv6(unittest.TestCase):
|
|||||||
buf = ip.serialize(bytearray(), None)
|
buf = ip.serialize(bytearray(), None)
|
||||||
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf))
|
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], 6 << 28)
|
self.assertEqual(res[0], 6 << 28)
|
||||||
eq_(res[1], 8)
|
self.assertEqual(res[1], 8)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], 255)
|
self.assertEqual(res[3], 255)
|
||||||
eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
self.assertEqual(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||||
eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
self.assertEqual(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||||
eq_(res[6], b'\x3a\x00\x05\x02\x00\x00\x01\x00')
|
self.assertEqual(res[6], b'\x3a\x00\x05\x02\x00\x00\x01\x00')
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.ip.to_jsondict()
|
jsondict = self.ip.to_jsondict()
|
||||||
ip = ipv6.ipv6.from_jsondict(jsondict['ipv6'])
|
ip = ipv6.ipv6.from_jsondict(jsondict['ipv6'])
|
||||||
eq_(str(self.ip), str(ip))
|
self.assertEqual(str(self.ip), str(ip))
|
||||||
|
|
||||||
def test_json_with_hop_opts(self):
|
def test_json_with_hop_opts(self):
|
||||||
self.setUp_with_hop_opts()
|
self.setUp_with_hop_opts()
|
||||||
@ -528,13 +527,12 @@ class Test_hop_opts(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.nxt, self.hop.nxt)
|
self.assertEqual(self.nxt, self.hop.nxt)
|
||||||
eq_(self.size, self.hop.size)
|
self.assertEqual(self.size, self.hop.size)
|
||||||
eq_(self.data, self.hop.data)
|
self.assertEqual(self.data, self.hop.data)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_size(self):
|
def test_invalid_size(self):
|
||||||
ipv6.hop_opts(self.nxt, 1, self.data)
|
self.assertRaises(Exception, ipv6.hop_opts, self.nxt, 1, self.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.hop_opts.parser(self.buf)
|
_res = ipv6.hop_opts.parser(self.buf)
|
||||||
@ -542,15 +540,15 @@ class Test_hop_opts(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.size, res.size)
|
self.assertEqual(self.size, res.size)
|
||||||
eq_(str(self.data), str(res.data))
|
self.assertEqual(str(self.data), str(res.data))
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.hop.serialize()
|
buf = self.hop.serialize()
|
||||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||||
eq_(self.nxt, res[0])
|
self.assertEqual(self.nxt, res[0])
|
||||||
eq_(self.size, res[1])
|
self.assertEqual(self.size, res[1])
|
||||||
offset = struct.calcsize(self.form)
|
offset = struct.calcsize(self.form)
|
||||||
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
offset += len(opt1)
|
offset += len(opt1)
|
||||||
@ -559,31 +557,31 @@ class Test_hop_opts(unittest.TestCase):
|
|||||||
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
offset += len(opt3)
|
offset += len(opt3)
|
||||||
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
eq_(5, opt1.type_)
|
self.assertEqual(5, opt1.type_)
|
||||||
eq_(2, opt1.len_)
|
self.assertEqual(2, opt1.len_)
|
||||||
eq_(b'\x00\x00', opt1.data)
|
self.assertEqual(b'\x00\x00', opt1.data)
|
||||||
eq_(1, opt2.type_)
|
self.assertEqual(1, opt2.type_)
|
||||||
eq_(0, opt2.len_)
|
self.assertEqual(0, opt2.len_)
|
||||||
eq_(None, opt2.data)
|
self.assertEqual(None, opt2.data)
|
||||||
eq_(0xc2, opt3.type_)
|
self.assertEqual(0xc2, opt3.type_)
|
||||||
eq_(4, opt3.len_)
|
self.assertEqual(4, opt3.len_)
|
||||||
eq_(b'\x00\x01\x00\x00', opt3.data)
|
self.assertEqual(b'\x00\x01\x00\x00', opt3.data)
|
||||||
eq_(1, opt4.type_)
|
self.assertEqual(1, opt4.type_)
|
||||||
eq_(0, opt4.len_)
|
self.assertEqual(0, opt4.len_)
|
||||||
eq_(None, opt4.data)
|
self.assertEqual(None, opt4.data)
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(16, len(self.hop))
|
self.assertEqual(16, len(self.hop))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
hdr = ipv6.hop_opts()
|
hdr = ipv6.hop_opts()
|
||||||
buf = hdr.serialize()
|
buf = hdr.serialize()
|
||||||
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
||||||
|
|
||||||
eq_(res[0], 6)
|
self.assertEqual(res[0], 6)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
|
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
|
||||||
eq_(six.binary_type(buf[2:]), opt.serialize())
|
self.assertEqual(six.binary_type(buf[2:]), opt.serialize())
|
||||||
|
|
||||||
|
|
||||||
class Test_dst_opts(unittest.TestCase):
|
class Test_dst_opts(unittest.TestCase):
|
||||||
@ -609,13 +607,12 @@ class Test_dst_opts(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.nxt, self.dst.nxt)
|
self.assertEqual(self.nxt, self.dst.nxt)
|
||||||
eq_(self.size, self.dst.size)
|
self.assertEqual(self.size, self.dst.size)
|
||||||
eq_(self.data, self.dst.data)
|
self.assertEqual(self.data, self.dst.data)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_size(self):
|
def test_invalid_size(self):
|
||||||
ipv6.dst_opts(self.nxt, 1, self.data)
|
self.assertRaises(Exception, ipv6.dst_opts, self.nxt, 1, self.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.dst_opts.parser(self.buf)
|
_res = ipv6.dst_opts.parser(self.buf)
|
||||||
@ -623,15 +620,15 @@ class Test_dst_opts(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.size, res.size)
|
self.assertEqual(self.size, res.size)
|
||||||
eq_(str(self.data), str(res.data))
|
self.assertEqual(str(self.data), str(res.data))
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.dst.serialize()
|
buf = self.dst.serialize()
|
||||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||||
eq_(self.nxt, res[0])
|
self.assertEqual(self.nxt, res[0])
|
||||||
eq_(self.size, res[1])
|
self.assertEqual(self.size, res[1])
|
||||||
offset = struct.calcsize(self.form)
|
offset = struct.calcsize(self.form)
|
||||||
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
offset += len(opt1)
|
offset += len(opt1)
|
||||||
@ -640,31 +637,31 @@ class Test_dst_opts(unittest.TestCase):
|
|||||||
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
offset += len(opt3)
|
offset += len(opt3)
|
||||||
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||||
eq_(5, opt1.type_)
|
self.assertEqual(5, opt1.type_)
|
||||||
eq_(2, opt1.len_)
|
self.assertEqual(2, opt1.len_)
|
||||||
eq_(b'\x00\x00', opt1.data)
|
self.assertEqual(b'\x00\x00', opt1.data)
|
||||||
eq_(1, opt2.type_)
|
self.assertEqual(1, opt2.type_)
|
||||||
eq_(0, opt2.len_)
|
self.assertEqual(0, opt2.len_)
|
||||||
eq_(None, opt2.data)
|
self.assertEqual(None, opt2.data)
|
||||||
eq_(0xc2, opt3.type_)
|
self.assertEqual(0xc2, opt3.type_)
|
||||||
eq_(4, opt3.len_)
|
self.assertEqual(4, opt3.len_)
|
||||||
eq_(b'\x00\x01\x00\x00', opt3.data)
|
self.assertEqual(b'\x00\x01\x00\x00', opt3.data)
|
||||||
eq_(1, opt4.type_)
|
self.assertEqual(1, opt4.type_)
|
||||||
eq_(0, opt4.len_)
|
self.assertEqual(0, opt4.len_)
|
||||||
eq_(None, opt4.data)
|
self.assertEqual(None, opt4.data)
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(16, len(self.dst))
|
self.assertEqual(16, len(self.dst))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
hdr = ipv6.dst_opts()
|
hdr = ipv6.dst_opts()
|
||||||
buf = hdr.serialize()
|
buf = hdr.serialize()
|
||||||
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
||||||
|
|
||||||
eq_(res[0], 6)
|
self.assertEqual(res[0], 6)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
|
opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
|
||||||
eq_(six.binary_type(buf[2:]), opt.serialize())
|
self.assertEqual(six.binary_type(buf[2:]), opt.serialize())
|
||||||
|
|
||||||
|
|
||||||
class Test_option(unittest.TestCase):
|
class Test_option(unittest.TestCase):
|
||||||
@ -681,9 +678,9 @@ class Test_option(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.opt.type_)
|
self.assertEqual(self.type_, self.opt.type_)
|
||||||
eq_(self.len_, self.opt.len_)
|
self.assertEqual(self.len_, self.opt.len_)
|
||||||
eq_(self.data, self.opt.data)
|
self.assertEqual(self.data, self.opt.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.option.parser(self.buf)
|
_res = ipv6.option.parser(self.buf)
|
||||||
@ -691,19 +688,19 @@ class Test_option(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.type_, res.type_)
|
self.assertEqual(self.type_, res.type_)
|
||||||
eq_(self.len_, res.len_)
|
self.assertEqual(self.len_, res.len_)
|
||||||
eq_(self.data, res.data)
|
self.assertEqual(self.data, res.data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.opt.serialize()
|
buf = self.opt.serialize()
|
||||||
res = struct.unpack_from(self.form, buf)
|
res = struct.unpack_from(self.form, buf)
|
||||||
eq_(self.type_, res[0])
|
self.assertEqual(self.type_, res[0])
|
||||||
eq_(self.len_, res[1])
|
self.assertEqual(self.len_, res[1])
|
||||||
eq_(self.data, res[2])
|
self.assertEqual(self.data, res[2])
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(len(self.opt), 2 + self.len_)
|
self.assertEqual(len(self.opt), 2 + self.len_)
|
||||||
|
|
||||||
|
|
||||||
class Test_option_pad1(Test_option):
|
class Test_option_pad1(Test_option):
|
||||||
@ -719,14 +716,14 @@ class Test_option_pad1(Test_option):
|
|||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.opt.serialize()
|
buf = self.opt.serialize()
|
||||||
res = struct.unpack_from(self.form, buf)
|
res = struct.unpack_from(self.form, buf)
|
||||||
eq_(self.type_, res[0])
|
self.assertEqual(self.type_, res[0])
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
opt = ipv6.option()
|
opt = ipv6.option()
|
||||||
buf = opt.serialize()
|
buf = opt.serialize()
|
||||||
res = struct.unpack('!B', buf)
|
res = struct.unpack('!B', buf)
|
||||||
|
|
||||||
eq_(res[0], 0)
|
self.assertEqual(res[0], 0)
|
||||||
|
|
||||||
|
|
||||||
class Test_option_padN(Test_option):
|
class Test_option_padN(Test_option):
|
||||||
@ -742,8 +739,8 @@ class Test_option_padN(Test_option):
|
|||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.opt.serialize()
|
buf = self.opt.serialize()
|
||||||
res = struct.unpack_from(self.form, buf)
|
res = struct.unpack_from(self.form, buf)
|
||||||
eq_(self.type_, res[0])
|
self.assertEqual(self.type_, res[0])
|
||||||
eq_(self.len_, res[1])
|
self.assertEqual(self.len_, res[1])
|
||||||
|
|
||||||
|
|
||||||
class Test_routing(unittest.TestCase):
|
class Test_routing(unittest.TestCase):
|
||||||
@ -780,16 +777,16 @@ class Test_routing(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.size, res.size)
|
self.assertEqual(self.size, res.size)
|
||||||
eq_(self.type_, res.type_)
|
self.assertEqual(self.type_, res.type_)
|
||||||
eq_(self.seg, res.seg)
|
self.assertEqual(self.seg, res.seg)
|
||||||
eq_(self.cmpi, res.cmpi)
|
self.assertEqual(self.cmpi, res.cmpi)
|
||||||
eq_(self.cmpe, res.cmpe)
|
self.assertEqual(self.cmpe, res.cmpe)
|
||||||
eq_(self.pad, res._pad)
|
self.assertEqual(self.pad, res._pad)
|
||||||
eq_(self.adrs[0], res.adrs[0])
|
self.assertEqual(self.adrs[0], res.adrs[0])
|
||||||
eq_(self.adrs[1], res.adrs[1])
|
self.assertEqual(self.adrs[1], res.adrs[1])
|
||||||
eq_(self.adrs[2], res.adrs[2])
|
self.assertEqual(self.adrs[2], res.adrs[2])
|
||||||
|
|
||||||
def test_not_implemented_type(self):
|
def test_not_implemented_type(self):
|
||||||
not_implemented_buf = struct.pack(
|
not_implemented_buf = struct.pack(
|
||||||
@ -833,16 +830,16 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
addrconv.ipv6.text_to_bin(self.adrs[2]))
|
addrconv.ipv6.text_to_bin(self.adrs[2]))
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.nxt, self.routing.nxt)
|
self.assertEqual(self.nxt, self.routing.nxt)
|
||||||
eq_(self.size, self.routing.size)
|
self.assertEqual(self.size, self.routing.size)
|
||||||
eq_(self.type_, self.routing.type_)
|
self.assertEqual(self.type_, self.routing.type_)
|
||||||
eq_(self.seg, self.routing.seg)
|
self.assertEqual(self.seg, self.routing.seg)
|
||||||
eq_(self.cmpi, self.routing.cmpi)
|
self.assertEqual(self.cmpi, self.routing.cmpi)
|
||||||
eq_(self.cmpe, self.routing.cmpe)
|
self.assertEqual(self.cmpe, self.routing.cmpe)
|
||||||
eq_(self.pad, self.routing._pad)
|
self.assertEqual(self.pad, self.routing._pad)
|
||||||
eq_(self.adrs[0], self.routing.adrs[0])
|
self.assertEqual(self.adrs[0], self.routing.adrs[0])
|
||||||
eq_(self.adrs[1], self.routing.adrs[1])
|
self.assertEqual(self.adrs[1], self.routing.adrs[1])
|
||||||
eq_(self.adrs[2], self.routing.adrs[2])
|
self.assertEqual(self.adrs[2], self.routing.adrs[2])
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.routing.parser(self.buf)
|
_res = ipv6.routing.parser(self.buf)
|
||||||
@ -850,30 +847,30 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.size, res.size)
|
self.assertEqual(self.size, res.size)
|
||||||
eq_(self.type_, res.type_)
|
self.assertEqual(self.type_, res.type_)
|
||||||
eq_(self.seg, res.seg)
|
self.assertEqual(self.seg, res.seg)
|
||||||
eq_(self.cmpi, res.cmpi)
|
self.assertEqual(self.cmpi, res.cmpi)
|
||||||
eq_(self.cmpe, res.cmpe)
|
self.assertEqual(self.cmpe, res.cmpe)
|
||||||
eq_(self.pad, res._pad)
|
self.assertEqual(self.pad, res._pad)
|
||||||
eq_(self.adrs[0], res.adrs[0])
|
self.assertEqual(self.adrs[0], res.adrs[0])
|
||||||
eq_(self.adrs[1], res.adrs[1])
|
self.assertEqual(self.adrs[1], res.adrs[1])
|
||||||
eq_(self.adrs[2], res.adrs[2])
|
self.assertEqual(self.adrs[2], res.adrs[2])
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.routing.serialize()
|
buf = self.routing.serialize()
|
||||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||||
eq_(self.nxt, res[0])
|
self.assertEqual(self.nxt, res[0])
|
||||||
eq_(self.size, res[1])
|
self.assertEqual(self.size, res[1])
|
||||||
eq_(self.type_, res[2])
|
self.assertEqual(self.type_, res[2])
|
||||||
eq_(self.seg, res[3])
|
self.assertEqual(self.seg, res[3])
|
||||||
eq_(self.cmpi, res[4] >> 4)
|
self.assertEqual(self.cmpi, res[4] >> 4)
|
||||||
eq_(self.cmpe, res[4] & 0xf)
|
self.assertEqual(self.cmpe, res[4] & 0xf)
|
||||||
eq_(self.pad, res[5])
|
self.assertEqual(self.pad, res[5])
|
||||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[0]), res[6])
|
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[0]), res[6])
|
||||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[1]), res[7])
|
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[1]), res[7])
|
||||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[2]), res[8])
|
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[2]), res[8])
|
||||||
|
|
||||||
def test_parser_with_adrs_zero(self):
|
def test_parser_with_adrs_zero(self):
|
||||||
nxt = 0
|
nxt = 0
|
||||||
@ -894,13 +891,13 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(nxt, res.nxt)
|
self.assertEqual(nxt, res.nxt)
|
||||||
eq_(size, res.size)
|
self.assertEqual(size, res.size)
|
||||||
eq_(type_, res.type_)
|
self.assertEqual(type_, res.type_)
|
||||||
eq_(seg, res.seg)
|
self.assertEqual(seg, res.seg)
|
||||||
eq_(cmpi, res.cmpi)
|
self.assertEqual(cmpi, res.cmpi)
|
||||||
eq_(cmpe, res.cmpe)
|
self.assertEqual(cmpe, res.cmpe)
|
||||||
eq_(pad, res._pad)
|
self.assertEqual(pad, res._pad)
|
||||||
|
|
||||||
def test_serialize_with_adrs_zero(self):
|
def test_serialize_with_adrs_zero(self):
|
||||||
nxt = 0
|
nxt = 0
|
||||||
@ -918,13 +915,13 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
buf = routing.serialize()
|
buf = routing.serialize()
|
||||||
form = '!BBBBBB2x'
|
form = '!BBBBBB2x'
|
||||||
res = struct.unpack_from(form, six.binary_type(buf))
|
res = struct.unpack_from(form, six.binary_type(buf))
|
||||||
eq_(nxt, res[0])
|
self.assertEqual(nxt, res[0])
|
||||||
eq_(size, res[1])
|
self.assertEqual(size, res[1])
|
||||||
eq_(type_, res[2])
|
self.assertEqual(type_, res[2])
|
||||||
eq_(seg, res[3])
|
self.assertEqual(seg, res[3])
|
||||||
eq_(cmpi, res[4] >> 4)
|
self.assertEqual(cmpi, res[4] >> 4)
|
||||||
eq_(cmpe, res[4] & 0xf)
|
self.assertEqual(cmpe, res[4] & 0xf)
|
||||||
eq_(pad, res[5])
|
self.assertEqual(pad, res[5])
|
||||||
|
|
||||||
def test_parser_with_compression(self):
|
def test_parser_with_compression(self):
|
||||||
pass
|
pass
|
||||||
@ -952,16 +949,16 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(nxt, res.nxt)
|
self.assertEqual(nxt, res.nxt)
|
||||||
eq_(size, res.size)
|
self.assertEqual(size, res.size)
|
||||||
eq_(type_, res.type_)
|
self.assertEqual(type_, res.type_)
|
||||||
eq_(seg, res.seg)
|
self.assertEqual(seg, res.seg)
|
||||||
eq_(cmpi, res.cmpi)
|
self.assertEqual(cmpi, res.cmpi)
|
||||||
eq_(cmpe, res.cmpe)
|
self.assertEqual(cmpe, res.cmpe)
|
||||||
eq_(pad, res._pad)
|
self.assertEqual(pad, res._pad)
|
||||||
eq_("::4567:89ab:cdef:1", res.adrs[0])
|
self.assertEqual("::4567:89ab:cdef:1", res.adrs[0])
|
||||||
eq_("::4567:89ab:cdef:2", res.adrs[1])
|
self.assertEqual("::4567:89ab:cdef:2", res.adrs[1])
|
||||||
eq_("::205.239.0.3", res.adrs[2])
|
self.assertEqual("::205.239.0.3", res.adrs[2])
|
||||||
|
|
||||||
def test_serialize_with_compression(self):
|
def test_serialize_with_compression(self):
|
||||||
nxt = 0
|
nxt = 0
|
||||||
@ -982,19 +979,19 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
buf = routing.serialize()
|
buf = routing.serialize()
|
||||||
form = '!BBBBBB2x8s8s8s'
|
form = '!BBBBBB2x8s8s8s'
|
||||||
res = struct.unpack_from(form, six.binary_type(buf))
|
res = struct.unpack_from(form, six.binary_type(buf))
|
||||||
eq_(nxt, res[0])
|
self.assertEqual(nxt, res[0])
|
||||||
eq_(size, res[1])
|
self.assertEqual(size, res[1])
|
||||||
eq_(type_, res[2])
|
self.assertEqual(type_, res[2])
|
||||||
eq_(seg, res[3])
|
self.assertEqual(seg, res[3])
|
||||||
eq_(cmpi, res[4] >> 4)
|
self.assertEqual(cmpi, res[4] >> 4)
|
||||||
eq_(cmpe, res[4] & 0xf)
|
self.assertEqual(cmpe, res[4] & 0xf)
|
||||||
eq_(pad, res[5])
|
self.assertEqual(pad, res[5])
|
||||||
eq_(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6])
|
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6])
|
||||||
eq_(addrconv.ipv6.text_to_bin(adrs[1])[slice_i], res[7])
|
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[1])[slice_i], res[7])
|
||||||
eq_(addrconv.ipv6.text_to_bin(adrs[2])[slice_e], res[8])
|
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[2])[slice_e], res[8])
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_((6 + 1) * 8, len(self.routing))
|
self.assertEqual((6 + 1) * 8, len(self.routing))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
hdr = ipv6.routing_type3()
|
hdr = ipv6.routing_type3()
|
||||||
@ -1003,12 +1000,12 @@ class Test_routing_type3(unittest.TestCase):
|
|||||||
res = struct.unpack_from(ipv6.routing_type3._PACK_STR, six.binary_type(buf))
|
res = struct.unpack_from(ipv6.routing_type3._PACK_STR, six.binary_type(buf))
|
||||||
LOG.info(res)
|
LOG.info(res)
|
||||||
|
|
||||||
eq_(res[0], 6)
|
self.assertEqual(res[0], 6)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[2], 3)
|
self.assertEqual(res[2], 3)
|
||||||
eq_(res[3], 0)
|
self.assertEqual(res[3], 0)
|
||||||
eq_(res[4], (0 << 4) | 0)
|
self.assertEqual(res[4], (0 << 4) | 0)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
|
|
||||||
|
|
||||||
class Test_fragment(unittest.TestCase):
|
class Test_fragment(unittest.TestCase):
|
||||||
@ -1026,10 +1023,10 @@ class Test_fragment(unittest.TestCase):
|
|||||||
self.buf = struct.pack(self.form, self.nxt, self.off_m, self.id_)
|
self.buf = struct.pack(self.form, self.nxt, self.off_m, self.id_)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.nxt, self.fragment.nxt)
|
self.assertEqual(self.nxt, self.fragment.nxt)
|
||||||
eq_(self.offset, self.fragment.offset)
|
self.assertEqual(self.offset, self.fragment.offset)
|
||||||
eq_(self.more, self.fragment.more)
|
self.assertEqual(self.more, self.fragment.more)
|
||||||
eq_(self.id_, self.fragment.id_)
|
self.assertEqual(self.id_, self.fragment.id_)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.fragment.parser(self.buf)
|
_res = ipv6.fragment.parser(self.buf)
|
||||||
@ -1037,29 +1034,29 @@ class Test_fragment(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.offset, res.offset)
|
self.assertEqual(self.offset, res.offset)
|
||||||
eq_(self.more, res.more)
|
self.assertEqual(self.more, res.more)
|
||||||
eq_(self.id_, res.id_)
|
self.assertEqual(self.id_, res.id_)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.fragment.serialize()
|
buf = self.fragment.serialize()
|
||||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||||
eq_(self.nxt, res[0])
|
self.assertEqual(self.nxt, res[0])
|
||||||
eq_(self.off_m, res[1])
|
self.assertEqual(self.off_m, res[1])
|
||||||
eq_(self.id_, res[2])
|
self.assertEqual(self.id_, res[2])
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_(8, len(self.fragment))
|
self.assertEqual(8, len(self.fragment))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
hdr = ipv6.fragment()
|
hdr = ipv6.fragment()
|
||||||
buf = hdr.serialize()
|
buf = hdr.serialize()
|
||||||
res = struct.unpack_from(ipv6.fragment._PACK_STR, buf)
|
res = struct.unpack_from(ipv6.fragment._PACK_STR, buf)
|
||||||
|
|
||||||
eq_(res[0], 6)
|
self.assertEqual(res[0], 6)
|
||||||
eq_(res[1], 0)
|
self.assertEqual(res[1], 0)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
|
|
||||||
|
|
||||||
class Test_auth(unittest.TestCase):
|
class Test_auth(unittest.TestCase):
|
||||||
@ -1077,11 +1074,11 @@ class Test_auth(unittest.TestCase):
|
|||||||
self.seq, self.data)
|
self.seq, self.data)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.nxt, self.auth.nxt)
|
self.assertEqual(self.nxt, self.auth.nxt)
|
||||||
eq_(self.size, self.auth.size)
|
self.assertEqual(self.size, self.auth.size)
|
||||||
eq_(self.spi, self.auth.spi)
|
self.assertEqual(self.spi, self.auth.spi)
|
||||||
eq_(self.seq, self.auth.seq)
|
self.assertEqual(self.seq, self.auth.seq)
|
||||||
eq_(self.data, self.auth.data)
|
self.assertEqual(self.data, self.auth.data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = ipv6.auth.parser(self.buf)
|
_res = ipv6.auth.parser(self.buf)
|
||||||
@ -1089,30 +1086,30 @@ class Test_auth(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(self.nxt, res.nxt)
|
self.assertEqual(self.nxt, res.nxt)
|
||||||
eq_(self.size, res.size)
|
self.assertEqual(self.size, res.size)
|
||||||
eq_(self.spi, res.spi)
|
self.assertEqual(self.spi, res.spi)
|
||||||
eq_(self.seq, res.seq)
|
self.assertEqual(self.seq, res.seq)
|
||||||
eq_(self.data, res.data)
|
self.assertEqual(self.data, res.data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
buf = self.auth.serialize()
|
buf = self.auth.serialize()
|
||||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||||
eq_(self.nxt, res[0])
|
self.assertEqual(self.nxt, res[0])
|
||||||
eq_(self.size, res[1])
|
self.assertEqual(self.size, res[1])
|
||||||
eq_(self.spi, res[2])
|
self.assertEqual(self.spi, res[2])
|
||||||
eq_(self.seq, res[3])
|
self.assertEqual(self.seq, res[3])
|
||||||
eq_(self.data, res[4])
|
self.assertEqual(self.data, res[4])
|
||||||
|
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
eq_((4 + 2) * 4, len(self.auth))
|
self.assertEqual((4 + 2) * 4, len(self.auth))
|
||||||
|
|
||||||
def test_len_re(self):
|
def test_len_re(self):
|
||||||
size = 5
|
size = 5
|
||||||
auth = ipv6.auth(
|
auth = ipv6.auth(
|
||||||
0, size, 256, 1,
|
0, size, 256, 1,
|
||||||
b'\x21\xd3\xa9\x5c\x5f\xfd\x4d\x18\x46\x22\xb9\xf8\xf8\xf8\xf8\xf8')
|
b'\x21\xd3\xa9\x5c\x5f\xfd\x4d\x18\x46\x22\xb9\xf8\xf8\xf8\xf8\xf8')
|
||||||
eq_((size + 2) * 4, len(auth))
|
self.assertEqual((size + 2) * 4, len(auth))
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
hdr = ipv6.auth()
|
hdr = ipv6.auth()
|
||||||
@ -1121,8 +1118,8 @@ class Test_auth(unittest.TestCase):
|
|||||||
res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf))
|
res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf))
|
||||||
LOG.info(res)
|
LOG.info(res)
|
||||||
|
|
||||||
eq_(res[0], 6)
|
self.assertEqual(res[0], 6)
|
||||||
eq_(res[1], 2)
|
self.assertEqual(res[1], 2)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], 0)
|
self.assertEqual(res[3], 0)
|
||||||
eq_(buf[ipv6.auth._MIN_LEN:], b'\x00\x00\x00\x00')
|
self.assertEqual(buf[ipv6.auth._MIN_LEN:], b'\x00\x00\x00\x00')
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.lib.packet import llc
|
from os_ken.lib.packet import llc
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ class Test_ControlFormatI(unittest.TestCase):
|
|||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.msg.to_jsondict()
|
jsondict = self.msg.to_jsondict()
|
||||||
msg = llc.llc.from_jsondict(jsondict['llc'])
|
msg = llc.llc.from_jsondict(jsondict['llc'])
|
||||||
eq_(str(self.msg), str(msg))
|
self.assertEqual(str(self.msg), str(msg))
|
||||||
|
|
||||||
|
|
||||||
class Test_ControlFormatS(Test_ControlFormatI):
|
class Test_ControlFormatS(Test_ControlFormatI):
|
||||||
|
@ -20,7 +20,6 @@ import logging
|
|||||||
import six
|
import six
|
||||||
import struct
|
import struct
|
||||||
import inspect
|
import inspect
|
||||||
from nose.tools import ok_, eq_, nottest
|
|
||||||
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.lib.packet import packet
|
from os_ken.lib.packet import packet
|
||||||
@ -48,42 +47,42 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_tlv_type(self):
|
def test_get_tlv_type(self):
|
||||||
buf = b'\x02\x07\x04\x00\x04\x96\x1f\xa7\x26'
|
buf = b'\x02\x07\x04\x00\x04\x96\x1f\xa7\x26'
|
||||||
eq_(lldp.LLDPBasicTLV.get_type(buf), lldp.LLDP_TLV_CHASSIS_ID)
|
self.assertEqual(lldp.LLDPBasicTLV.get_type(buf), lldp.LLDP_TLV_CHASSIS_ID)
|
||||||
|
|
||||||
def test_parse_without_ethernet(self):
|
def test_parse_without_ethernet(self):
|
||||||
buf = self.data[ethernet.ethernet._MIN_LEN:]
|
buf = self.data[ethernet.ethernet._MIN_LEN:]
|
||||||
(lldp_pkt, cls, rest_buf) = lldp.lldp.parser(buf)
|
(lldp_pkt, cls, rest_buf) = lldp.lldp.parser(buf)
|
||||||
eq_(len(rest_buf), 0)
|
self.assertEqual(len(rest_buf), 0)
|
||||||
|
|
||||||
tlvs = lldp_pkt.tlvs
|
tlvs = lldp_pkt.tlvs
|
||||||
eq_(tlvs[0].tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
self.assertEqual(tlvs[0].tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||||
eq_(tlvs[0].len, 7)
|
self.assertEqual(tlvs[0].len, 7)
|
||||||
eq_(tlvs[0].subtype, lldp.ChassisID.SUB_MAC_ADDRESS)
|
self.assertEqual(tlvs[0].subtype, lldp.ChassisID.SUB_MAC_ADDRESS)
|
||||||
eq_(tlvs[0].chassis_id, b'\x00\x04\x96\x1f\xa7\x26')
|
self.assertEqual(tlvs[0].chassis_id, b'\x00\x04\x96\x1f\xa7\x26')
|
||||||
eq_(tlvs[1].tlv_type, lldp.LLDP_TLV_PORT_ID)
|
self.assertEqual(tlvs[1].tlv_type, lldp.LLDP_TLV_PORT_ID)
|
||||||
eq_(tlvs[1].len, 4)
|
self.assertEqual(tlvs[1].len, 4)
|
||||||
eq_(tlvs[1].subtype, lldp.PortID.SUB_INTERFACE_NAME)
|
self.assertEqual(tlvs[1].subtype, lldp.PortID.SUB_INTERFACE_NAME)
|
||||||
eq_(tlvs[1].port_id, b'1/3')
|
self.assertEqual(tlvs[1].port_id, b'1/3')
|
||||||
eq_(tlvs[2].tlv_type, lldp.LLDP_TLV_TTL)
|
self.assertEqual(tlvs[2].tlv_type, lldp.LLDP_TLV_TTL)
|
||||||
eq_(tlvs[2].len, 2)
|
self.assertEqual(tlvs[2].len, 2)
|
||||||
eq_(tlvs[2].ttl, 120)
|
self.assertEqual(tlvs[2].ttl, 120)
|
||||||
eq_(tlvs[3].tlv_type, lldp.LLDP_TLV_END)
|
self.assertEqual(tlvs[3].tlv_type, lldp.LLDP_TLV_END)
|
||||||
|
|
||||||
def test_parse(self):
|
def test_parse(self):
|
||||||
buf = self.data
|
buf = self.data
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
eq_(type(next(i)), lldp.lldp)
|
self.assertEqual(type(next(i)), lldp.lldp)
|
||||||
|
|
||||||
def test_tlv(self):
|
def test_tlv(self):
|
||||||
tlv = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
tlv = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
chassis_id=b'\x00\x04\x96\x1f\xa7\x26')
|
chassis_id=b'\x00\x04\x96\x1f\xa7\x26')
|
||||||
eq_(tlv.tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
self.assertEqual(tlv.tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||||
eq_(tlv.len, 7)
|
self.assertEqual(tlv.len, 7)
|
||||||
(typelen, ) = struct.unpack('!H', b'\x02\x07')
|
(typelen, ) = struct.unpack('!H', b'\x02\x07')
|
||||||
eq_(tlv.typelen, typelen)
|
self.assertEqual(tlv.typelen, typelen)
|
||||||
|
|
||||||
def test_serialize_without_ethernet(self):
|
def test_serialize_without_ethernet(self):
|
||||||
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
@ -95,7 +94,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
|
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
|
||||||
lldp_pkt = lldp.lldp(tlvs)
|
lldp_pkt = lldp.lldp(tlvs)
|
||||||
|
|
||||||
eq_(lldp_pkt.serialize(None, None),
|
self.assertEqual(lldp_pkt.serialize(None, None),
|
||||||
self.data[ethernet.ethernet._MIN_LEN:])
|
self.data[ethernet.ethernet._MIN_LEN:])
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
@ -118,7 +117,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
lldp_pkt = lldp.lldp(tlvs)
|
lldp_pkt = lldp.lldp(tlvs)
|
||||||
pkt.add_protocol(lldp_pkt)
|
pkt.add_protocol(lldp_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 2)
|
self.assertEqual(len(pkt.protocols), 2)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
|
|
||||||
@ -128,9 +127,9 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
data_len = len(self.data)
|
data_len = len(self.data)
|
||||||
pkt_data_lldp = pkt.data[:data_len]
|
pkt_data_lldp = pkt.data[:data_len]
|
||||||
pkt_data_pad = pkt.data[data_len:]
|
pkt_data_pad = pkt.data[data_len:]
|
||||||
eq_(b'\x00' * (60 - data_len), pkt_data_pad)
|
self.assertEqual(b'\x00' * (60 - data_len), pkt_data_pad)
|
||||||
|
|
||||||
eq_(self.data, pkt_data_lldp)
|
self.assertEqual(self.data, pkt_data_lldp)
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
@ -185,8 +184,8 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
lldp_str = _lldp_str % (lldp.lldp.__name__,
|
lldp_str = _lldp_str % (lldp.lldp.__name__,
|
||||||
tlvs_str)
|
tlvs_str)
|
||||||
|
|
||||||
eq_(str(lldp_pkt), lldp_str)
|
self.assertEqual(str(lldp_pkt), lldp_str)
|
||||||
eq_(repr(lldp_pkt), lldp_str)
|
self.assertEqual(repr(lldp_pkt), lldp_str)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
@ -199,7 +198,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
|||||||
lldp1 = lldp.lldp(tlvs)
|
lldp1 = lldp.lldp(tlvs)
|
||||||
jsondict = lldp1.to_jsondict()
|
jsondict = lldp1.to_jsondict()
|
||||||
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
|
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
|
||||||
eq_(str(lldp1), str(lldp2))
|
self.assertEqual(str(lldp1), str(lldp2))
|
||||||
|
|
||||||
|
|
||||||
class TestLLDPOptionalTLV(unittest.TestCase):
|
class TestLLDPOptionalTLV(unittest.TestCase):
|
||||||
@ -250,49 +249,49 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
|||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
i = iter(pkt)
|
i = iter(pkt)
|
||||||
|
|
||||||
eq_(type(next(i)), ethernet.ethernet)
|
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||||
lldp_pkt = next(i)
|
lldp_pkt = next(i)
|
||||||
eq_(type(lldp_pkt), lldp.lldp)
|
self.assertEqual(type(lldp_pkt), lldp.lldp)
|
||||||
|
|
||||||
tlvs = lldp_pkt.tlvs
|
tlvs = lldp_pkt.tlvs
|
||||||
|
|
||||||
# Port Description
|
# Port Description
|
||||||
eq_(tlvs[3].tlv_type, lldp.LLDP_TLV_PORT_DESCRIPTION)
|
self.assertEqual(tlvs[3].tlv_type, lldp.LLDP_TLV_PORT_DESCRIPTION)
|
||||||
eq_(tlvs[3].port_description, b'Summit300-48-Port 1001\x00')
|
self.assertEqual(tlvs[3].port_description, b'Summit300-48-Port 1001\x00')
|
||||||
|
|
||||||
# System Name
|
# System Name
|
||||||
eq_(tlvs[4].tlv_type, lldp.LLDP_TLV_SYSTEM_NAME)
|
self.assertEqual(tlvs[4].tlv_type, lldp.LLDP_TLV_SYSTEM_NAME)
|
||||||
eq_(tlvs[4].system_name, b'Summit300-48\x00')
|
self.assertEqual(tlvs[4].system_name, b'Summit300-48\x00')
|
||||||
|
|
||||||
# System Description
|
# System Description
|
||||||
|
|
||||||
eq_(tlvs[5].tlv_type, lldp.LLDP_TLV_SYSTEM_DESCRIPTION)
|
self.assertEqual(tlvs[5].tlv_type, lldp.LLDP_TLV_SYSTEM_DESCRIPTION)
|
||||||
eq_(tlvs[5].system_description,
|
self.assertEqual(tlvs[5].system_description,
|
||||||
b'Summit300-48 - Version 7.4e.1 (Build 5) '
|
b'Summit300-48 - Version 7.4e.1 (Build 5) '
|
||||||
+ b'by Release_Master 05/27/05 04:53:11\x00')
|
+ b'by Release_Master 05/27/05 04:53:11\x00')
|
||||||
|
|
||||||
# SystemCapabilities
|
# SystemCapabilities
|
||||||
eq_(tlvs[6].tlv_type, lldp.LLDP_TLV_SYSTEM_CAPABILITIES)
|
self.assertEqual(tlvs[6].tlv_type, lldp.LLDP_TLV_SYSTEM_CAPABILITIES)
|
||||||
eq_(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_MAC_BRIDGE,
|
self.assertEqual(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_MAC_BRIDGE,
|
||||||
lldp.SystemCapabilities.CAP_MAC_BRIDGE)
|
lldp.SystemCapabilities.CAP_MAC_BRIDGE)
|
||||||
eq_(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_MAC_BRIDGE,
|
self.assertEqual(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_MAC_BRIDGE,
|
||||||
lldp.SystemCapabilities.CAP_MAC_BRIDGE)
|
lldp.SystemCapabilities.CAP_MAC_BRIDGE)
|
||||||
eq_(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
self.assertEqual(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||||
eq_(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
self.assertEqual(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||||
|
|
||||||
# Management Address
|
# Management Address
|
||||||
eq_(tlvs[7].tlv_type, lldp.LLDP_TLV_MANAGEMENT_ADDRESS)
|
self.assertEqual(tlvs[7].tlv_type, lldp.LLDP_TLV_MANAGEMENT_ADDRESS)
|
||||||
eq_(tlvs[7].addr_len, 7)
|
self.assertEqual(tlvs[7].addr_len, 7)
|
||||||
eq_(tlvs[7].addr, b'\x00\x01\x30\xf9\xad\xa0')
|
self.assertEqual(tlvs[7].addr, b'\x00\x01\x30\xf9\xad\xa0')
|
||||||
eq_(tlvs[7].intf_num, 1001)
|
self.assertEqual(tlvs[7].intf_num, 1001)
|
||||||
|
|
||||||
# Organizationally Specific
|
# Organizationally Specific
|
||||||
eq_(tlvs[8].tlv_type, lldp.LLDP_TLV_ORGANIZATIONALLY_SPECIFIC)
|
self.assertEqual(tlvs[8].tlv_type, lldp.LLDP_TLV_ORGANIZATIONALLY_SPECIFIC)
|
||||||
eq_(tlvs[8].oui, b'\x00\x12\x0f') # IEEE 802.3
|
self.assertEqual(tlvs[8].oui, b'\x00\x12\x0f') # IEEE 802.3
|
||||||
eq_(tlvs[8].subtype, 0x02) # Power Via MDI
|
self.assertEqual(tlvs[8].subtype, 0x02) # Power Via MDI
|
||||||
|
|
||||||
# End
|
# End
|
||||||
eq_(tlvs[16].tlv_type, lldp.LLDP_TLV_END)
|
self.assertEqual(tlvs[16].tlv_type, lldp.LLDP_TLV_END)
|
||||||
|
|
||||||
def test_parse_corrupted(self):
|
def test_parse_corrupted(self):
|
||||||
buf = self.data
|
buf = self.data
|
||||||
@ -336,13 +335,13 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
|||||||
lldp_pkt = lldp.lldp(tlvs)
|
lldp_pkt = lldp.lldp(tlvs)
|
||||||
pkt.add_protocol(lldp_pkt)
|
pkt.add_protocol(lldp_pkt)
|
||||||
|
|
||||||
eq_(len(pkt.protocols), 2)
|
self.assertEqual(len(pkt.protocols), 2)
|
||||||
|
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
|
|
||||||
# self.data has many organizationally specific TLVs
|
# self.data has many organizationally specific TLVs
|
||||||
data = six.binary_type(pkt.data[:-2])
|
data = six.binary_type(pkt.data[:-2])
|
||||||
eq_(data, self.data[:len(data)])
|
self.assertEqual(data, self.data[:len(data)])
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
@ -494,8 +493,8 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
|||||||
lldp_str = _lldp_str % (lldp.lldp.__name__,
|
lldp_str = _lldp_str % (lldp.lldp.__name__,
|
||||||
tlvs_str)
|
tlvs_str)
|
||||||
|
|
||||||
eq_(str(lldp_pkt), lldp_str)
|
self.assertEqual(str(lldp_pkt), lldp_str)
|
||||||
eq_(repr(lldp_pkt), lldp_str)
|
self.assertEqual(repr(lldp_pkt), lldp_str)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||||
@ -524,4 +523,4 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
|||||||
lldp1 = lldp.lldp(tlvs)
|
lldp1 = lldp.lldp(tlvs)
|
||||||
jsondict = lldp1.to_jsondict()
|
jsondict = lldp1.to_jsondict()
|
||||||
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
|
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
|
||||||
eq_(str(lldp1), str(lldp2))
|
self.assertEqual(str(lldp1), str(lldp2))
|
||||||
|
@ -18,7 +18,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from os_ken.lib.packet import mpls
|
from os_ken.lib.packet import mpls
|
||||||
|
|
||||||
|
|
||||||
@ -49,13 +48,13 @@ class Test_mpls(unittest.TestCase):
|
|||||||
if k in mpls_values])
|
if k in mpls_values])
|
||||||
mpls_str = '%s(%s)' % (mpls.mpls.__name__, _mpls_str)
|
mpls_str = '%s(%s)' % (mpls.mpls.__name__, _mpls_str)
|
||||||
|
|
||||||
eq_(str(self.mp), mpls_str)
|
self.assertEqual(str(self.mp), mpls_str)
|
||||||
eq_(repr(self.mp), mpls_str)
|
self.assertEqual(repr(self.mp), mpls_str)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.mp.to_jsondict()
|
jsondict = self.mp.to_jsondict()
|
||||||
mp = mpls.mpls.from_jsondict(jsondict['mpls'])
|
mp = mpls.mpls.from_jsondict(jsondict['mpls'])
|
||||||
eq_(str(self.mp), str(mp))
|
self.assertEqual(str(self.mp), str(mp))
|
||||||
|
|
||||||
def test_label_from_bin_true(self):
|
def test_label_from_bin_true(self):
|
||||||
mpls_label = 0xfffff
|
mpls_label = 0xfffff
|
||||||
@ -63,8 +62,8 @@ class Test_mpls(unittest.TestCase):
|
|||||||
buf = b'\xff\xff\xf1'
|
buf = b'\xff\xff\xf1'
|
||||||
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
||||||
|
|
||||||
eq_(mpls_label, mpls_label_out)
|
self.assertEqual(mpls_label, mpls_label_out)
|
||||||
eq_(is_bos, is_bos_out)
|
self.assertEqual(is_bos, is_bos_out)
|
||||||
|
|
||||||
def test_label_from_bin_false(self):
|
def test_label_from_bin_false(self):
|
||||||
mpls_label = 0xfffff
|
mpls_label = 0xfffff
|
||||||
@ -72,8 +71,8 @@ class Test_mpls(unittest.TestCase):
|
|||||||
buf = b'\xff\xff\xf0'
|
buf = b'\xff\xff\xf0'
|
||||||
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
||||||
|
|
||||||
eq_(mpls_label, mpls_label_out)
|
self.assertEqual(mpls_label, mpls_label_out)
|
||||||
eq_(is_bos, is_bos_out)
|
self.assertEqual(is_bos, is_bos_out)
|
||||||
|
|
||||||
def test_label_to_bin_true(self):
|
def test_label_to_bin_true(self):
|
||||||
mpls_label = 0xfffff
|
mpls_label = 0xfffff
|
||||||
@ -81,7 +80,7 @@ class Test_mpls(unittest.TestCase):
|
|||||||
label = b'\xff\xff\xf1'
|
label = b'\xff\xff\xf1'
|
||||||
label_out = mpls.label_to_bin(mpls_label, is_bos)
|
label_out = mpls.label_to_bin(mpls_label, is_bos)
|
||||||
|
|
||||||
eq_(label, label_out)
|
self.assertEqual(label, label_out)
|
||||||
|
|
||||||
def test_label_to_bin_false(self):
|
def test_label_to_bin_false(self):
|
||||||
mpls_label = 0xfffff
|
mpls_label = 0xfffff
|
||||||
@ -89,4 +88,4 @@ class Test_mpls(unittest.TestCase):
|
|||||||
label = b'\xff\xff\xf0'
|
label = b'\xff\xff\xf0'
|
||||||
label_out = mpls.label_to_bin(mpls_label, is_bos)
|
label_out = mpls.label_to_bin(mpls_label, is_bos)
|
||||||
|
|
||||||
eq_(label, label_out)
|
self.assertEqual(label, label_out)
|
||||||
|
@ -18,8 +18,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.lib import pcaplib
|
from os_ken.lib import pcaplib
|
||||||
from os_ken.lib.packet import openflow
|
from os_ken.lib.packet import openflow
|
||||||
@ -53,10 +51,10 @@ class Test_openflow(unittest.TestCase):
|
|||||||
# Checks if message can be parsed as expected.
|
# Checks if message can be parsed as expected.
|
||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
openflow_pkt = pkt.get_protocol(openflow.openflow)
|
openflow_pkt = pkt.get_protocol(openflow.openflow)
|
||||||
ok_(isinstance(openflow_pkt, openflow.openflow),
|
self.assertTrue(isinstance(openflow_pkt, openflow.openflow),
|
||||||
'Failed to parse OpenFlow message: %s' % pkt)
|
'Failed to parse OpenFlow message: %s' % pkt)
|
||||||
|
|
||||||
# Checks if message can be serialized as expected.
|
# Checks if message can be serialized as expected.
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(buf, pkt.data,
|
self.assertEqual(buf, pkt.data,
|
||||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
from os_ken.lib.packet import ospf
|
from os_ken.lib.packet import ospf
|
||||||
|
|
||||||
@ -37,18 +35,18 @@ class Test_ospf(unittest.TestCase):
|
|||||||
links=[link1])
|
links=[link1])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||||
eq_(msg.header.checksum, msg2.header.checksum)
|
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_network_lsa(self):
|
def test_network_lsa(self):
|
||||||
msg = ospf.NetworkLSA(id_='192.168.0.1', adv_router='192.168.0.2',
|
msg = ospf.NetworkLSA(id_='192.168.0.1', adv_router='192.168.0.2',
|
||||||
mask='255.255.255.0', routers=['192.168.0.2'])
|
mask='255.255.255.0', routers=['192.168.0.2'])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||||
eq_(msg.header.checksum, msg2.header.checksum)
|
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_as_external_lsa(self):
|
def test_as_external_lsa(self):
|
||||||
extnw1 = ospf.ASExternalLSA.ExternalNetwork(mask='255.255.255.0',
|
extnw1 = ospf.ASExternalLSA.ExternalNetwork(mask='255.255.255.0',
|
||||||
@ -58,18 +56,18 @@ class Test_ospf(unittest.TestCase):
|
|||||||
extnws=[extnw1])
|
extnws=[extnw1])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||||
eq_(msg.header.checksum, msg2.header.checksum)
|
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_hello(self):
|
def test_hello(self):
|
||||||
msg = ospf.OSPFHello(router_id='192.168.0.1',
|
msg = ospf.OSPFHello(router_id='192.168.0.1',
|
||||||
neighbors=['192.168.0.2'])
|
neighbors=['192.168.0.2'])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||||
eq_(msg.checksum, msg2.checksum)
|
self.assertEqual(msg.checksum, msg2.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_dbdesc(self):
|
def test_dbdesc(self):
|
||||||
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
||||||
@ -80,9 +78,9 @@ class Test_ospf(unittest.TestCase):
|
|||||||
lsa_headers=[lsa1.header])
|
lsa_headers=[lsa1.header])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||||
eq_(msg.checksum, msg2.checksum)
|
self.assertEqual(msg.checksum, msg2.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_lsreq(self):
|
def test_lsreq(self):
|
||||||
req = ospf.OSPFLSReq.Request(type_=ospf.OSPF_ROUTER_LSA,
|
req = ospf.OSPFLSReq.Request(type_=ospf.OSPF_ROUTER_LSA,
|
||||||
@ -91,9 +89,9 @@ class Test_ospf(unittest.TestCase):
|
|||||||
msg = ospf.OSPFLSReq(router_id='192.168.0.1', lsa_requests=[req])
|
msg = ospf.OSPFLSReq(router_id='192.168.0.1', lsa_requests=[req])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||||
eq_(msg.checksum, msg2.checksum)
|
self.assertEqual(msg.checksum, msg2.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_lsupd(self):
|
def test_lsupd(self):
|
||||||
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
||||||
@ -103,9 +101,9 @@ class Test_ospf(unittest.TestCase):
|
|||||||
msg = ospf.OSPFLSUpd(router_id='192.168.0.1', lsas=[lsa1])
|
msg = ospf.OSPFLSUpd(router_id='192.168.0.1', lsas=[lsa1])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||||
eq_(msg.checksum, msg2.checksum)
|
self.assertEqual(msg.checksum, msg2.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
|
||||||
def test_lsack(self):
|
def test_lsack(self):
|
||||||
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
|
||||||
@ -116,6 +114,6 @@ class Test_ospf(unittest.TestCase):
|
|||||||
lsa_headers=[lsa1.header])
|
lsa_headers=[lsa1.header])
|
||||||
binmsg = msg.serialize()
|
binmsg = msg.serialize()
|
||||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||||
eq_(msg.checksum, msg2.checksum)
|
self.assertEqual(msg.checksum, msg2.checksum)
|
||||||
eq_(str(msg), str(msg2))
|
self.assertEqual(str(msg), str(msg2))
|
||||||
eq_(rest, b'')
|
self.assertEqual(rest, b'')
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
import inspect
|
import inspect
|
||||||
from nose.tools import ok_, eq_
|
|
||||||
import six
|
import six
|
||||||
from os_ken.ofproto import ether, inet
|
from os_ken.ofproto import ether, inet
|
||||||
from os_ken.lib.packet import arp
|
from os_ken.lib.packet import arp
|
||||||
@ -106,7 +105,7 @@ class TestPacket(unittest.TestCase):
|
|||||||
pad_len = 60 - len(buf)
|
pad_len = 60 - len(buf)
|
||||||
if pad_len > 0:
|
if pad_len > 0:
|
||||||
buf += b'\x00' * pad_len
|
buf += b'\x00' * pad_len
|
||||||
eq_(buf, p.data)
|
self.assertEqual(buf, p.data)
|
||||||
|
|
||||||
# parse
|
# parse
|
||||||
pkt = packet.Packet(p.data)
|
pkt = packet.Packet(p.data)
|
||||||
@ -115,22 +114,22 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_arp = protocols['arp']
|
p_arp = protocols['arp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_(self.dst_mac, p_eth.dst)
|
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||||
eq_(self.src_mac, p_eth.src)
|
self.assertEqual(self.src_mac, p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_ARP, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_ARP, p_eth.ethertype)
|
||||||
|
|
||||||
# arp
|
# arp
|
||||||
ok_(p_arp)
|
self.assertTrue(p_arp)
|
||||||
eq_(1, p_arp.hwtype)
|
self.assertEqual(1, p_arp.hwtype)
|
||||||
eq_(ether.ETH_TYPE_IP, p_arp.proto)
|
self.assertEqual(ether.ETH_TYPE_IP, p_arp.proto)
|
||||||
eq_(6, p_arp.hlen)
|
self.assertEqual(6, p_arp.hlen)
|
||||||
eq_(4, p_arp.plen)
|
self.assertEqual(4, p_arp.plen)
|
||||||
eq_(2, p_arp.opcode)
|
self.assertEqual(2, p_arp.opcode)
|
||||||
eq_(self.src_mac, p_arp.src_mac)
|
self.assertEqual(self.src_mac, p_arp.src_mac)
|
||||||
eq_(self.src_ip, p_arp.src_ip)
|
self.assertEqual(self.src_ip, p_arp.src_ip)
|
||||||
eq_(self.dst_mac, p_arp.dst_mac)
|
self.assertEqual(self.dst_mac, p_arp.dst_mac)
|
||||||
eq_(self.dst_ip, p_arp.dst_ip)
|
self.assertEqual(self.dst_ip, p_arp.dst_ip)
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': self.dst_mac,
|
eth_values = {'dst': self.dst_mac,
|
||||||
@ -157,14 +156,14 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s' % (eth_str, arp_str)
|
pkt_str = '%s, %s' % (eth_str, arp_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(arp_str, str(p_arp))
|
self.assertEqual(arp_str, str(p_arp))
|
||||||
eq_(arp_str, repr(p_arp))
|
self.assertEqual(arp_str, repr(p_arp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_vlan_arp(self):
|
def test_vlan_arp(self):
|
||||||
# buid packet
|
# buid packet
|
||||||
@ -206,7 +205,7 @@ class TestPacket(unittest.TestCase):
|
|||||||
pad_len = 60 - len(buf)
|
pad_len = 60 - len(buf)
|
||||||
if pad_len > 0:
|
if pad_len > 0:
|
||||||
buf += b'\x00' * pad_len
|
buf += b'\x00' * pad_len
|
||||||
eq_(buf, p.data)
|
self.assertEqual(buf, p.data)
|
||||||
|
|
||||||
# parse
|
# parse
|
||||||
pkt = packet.Packet(p.data)
|
pkt = packet.Packet(p.data)
|
||||||
@ -216,29 +215,29 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_arp = protocols['arp']
|
p_arp = protocols['arp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_(self.dst_mac, p_eth.dst)
|
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||||
eq_(self.src_mac, p_eth.src)
|
self.assertEqual(self.src_mac, p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_8021Q, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_8021Q, p_eth.ethertype)
|
||||||
|
|
||||||
# vlan
|
# vlan
|
||||||
ok_(p_vlan)
|
self.assertTrue(p_vlan)
|
||||||
eq_(0b111, p_vlan.pcp)
|
self.assertEqual(0b111, p_vlan.pcp)
|
||||||
eq_(0b1, p_vlan.cfi)
|
self.assertEqual(0b1, p_vlan.cfi)
|
||||||
eq_(3, p_vlan.vid)
|
self.assertEqual(3, p_vlan.vid)
|
||||||
eq_(ether.ETH_TYPE_ARP, p_vlan.ethertype)
|
self.assertEqual(ether.ETH_TYPE_ARP, p_vlan.ethertype)
|
||||||
|
|
||||||
# arp
|
# arp
|
||||||
ok_(p_arp)
|
self.assertTrue(p_arp)
|
||||||
eq_(1, p_arp.hwtype)
|
self.assertEqual(1, p_arp.hwtype)
|
||||||
eq_(ether.ETH_TYPE_IP, p_arp.proto)
|
self.assertEqual(ether.ETH_TYPE_IP, p_arp.proto)
|
||||||
eq_(6, p_arp.hlen)
|
self.assertEqual(6, p_arp.hlen)
|
||||||
eq_(4, p_arp.plen)
|
self.assertEqual(4, p_arp.plen)
|
||||||
eq_(2, p_arp.opcode)
|
self.assertEqual(2, p_arp.opcode)
|
||||||
eq_(self.src_mac, p_arp.src_mac)
|
self.assertEqual(self.src_mac, p_arp.src_mac)
|
||||||
eq_(self.src_ip, p_arp.src_ip)
|
self.assertEqual(self.src_ip, p_arp.src_ip)
|
||||||
eq_(self.dst_mac, p_arp.dst_mac)
|
self.assertEqual(self.dst_mac, p_arp.dst_mac)
|
||||||
eq_(self.dst_ip, p_arp.dst_ip)
|
self.assertEqual(self.dst_ip, p_arp.dst_ip)
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': self.dst_mac,
|
eth_values = {'dst': self.dst_mac,
|
||||||
@ -274,17 +273,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, vlan_str, arp_str)
|
pkt_str = '%s, %s, %s' % (eth_str, vlan_str, arp_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(vlan_str, str(p_vlan))
|
self.assertEqual(vlan_str, str(p_vlan))
|
||||||
eq_(vlan_str, repr(p_vlan))
|
self.assertEqual(vlan_str, repr(p_vlan))
|
||||||
|
|
||||||
eq_(arp_str, str(p_arp))
|
self.assertEqual(arp_str, str(p_arp))
|
||||||
eq_(arp_str, repr(p_arp))
|
self.assertEqual(arp_str, repr(p_arp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv4_udp(self):
|
def test_ipv4_udp(self):
|
||||||
# buid packet
|
# buid packet
|
||||||
@ -334,44 +333,44 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_udp = protocols['udp']
|
p_udp = protocols['udp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_(self.dst_mac, p_eth.dst)
|
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||||
eq_(self.src_mac, p_eth.src)
|
self.assertEqual(self.src_mac, p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv4
|
# ipv4
|
||||||
ok_(p_ipv4)
|
self.assertTrue(p_ipv4)
|
||||||
eq_(4, p_ipv4.version)
|
self.assertEqual(4, p_ipv4.version)
|
||||||
eq_(5, p_ipv4.header_length)
|
self.assertEqual(5, p_ipv4.header_length)
|
||||||
eq_(1, p_ipv4.tos)
|
self.assertEqual(1, p_ipv4.tos)
|
||||||
l = len(ip_buf) + len(u_buf) + len(self.payload)
|
l = len(ip_buf) + len(u_buf) + len(self.payload)
|
||||||
eq_(l, p_ipv4.total_length)
|
self.assertEqual(l, p_ipv4.total_length)
|
||||||
eq_(3, p_ipv4.identification)
|
self.assertEqual(3, p_ipv4.identification)
|
||||||
eq_(1, p_ipv4.flags)
|
self.assertEqual(1, p_ipv4.flags)
|
||||||
eq_(64, p_ipv4.ttl)
|
self.assertEqual(64, p_ipv4.ttl)
|
||||||
eq_(inet.IPPROTO_UDP, p_ipv4.proto)
|
self.assertEqual(inet.IPPROTO_UDP, p_ipv4.proto)
|
||||||
eq_(self.src_ip, p_ipv4.src)
|
self.assertEqual(self.src_ip, p_ipv4.src)
|
||||||
eq_(self.dst_ip, p_ipv4.dst)
|
self.assertEqual(self.dst_ip, p_ipv4.dst)
|
||||||
t = bytearray(ip_buf)
|
t = bytearray(ip_buf)
|
||||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||||
eq_(packet_utils.checksum(t), 0)
|
self.assertEqual(packet_utils.checksum(t), 0)
|
||||||
|
|
||||||
# udp
|
# udp
|
||||||
ok_(p_udp)
|
self.assertTrue(p_udp)
|
||||||
eq_(0x190f, p_udp.src_port)
|
self.assertEqual(0x190f, p_udp.src_port)
|
||||||
eq_(0x1F90, p_udp.dst_port)
|
self.assertEqual(0x1F90, p_udp.dst_port)
|
||||||
eq_(len(u_buf) + len(self.payload), p_udp.total_length)
|
self.assertEqual(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||||
eq_(0x77b2, p_udp.csum)
|
self.assertEqual(0x77b2, p_udp.csum)
|
||||||
t = bytearray(u_buf)
|
t = bytearray(u_buf)
|
||||||
struct.pack_into('!H', t, 6, p_udp.csum)
|
struct.pack_into('!H', t, 6, p_udp.csum)
|
||||||
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
||||||
17, len(u_buf) + len(self.payload))
|
17, len(u_buf) + len(self.payload))
|
||||||
t = ph + t + self.payload
|
t = ph + t + self.payload
|
||||||
eq_(packet_utils.checksum(t), 0)
|
self.assertEqual(packet_utils.checksum(t), 0)
|
||||||
|
|
||||||
# payload
|
# payload
|
||||||
ok_('payload' in protocols)
|
self.assertTrue('payload' in protocols)
|
||||||
eq_(self.payload, protocols['payload'])
|
self.assertEqual(self.payload, protocols['payload'])
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': self.dst_mac,
|
eth_values = {'dst': self.dst_mac,
|
||||||
@ -412,17 +411,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv4_str, udp_str,
|
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv4_str, udp_str,
|
||||||
repr(protocols['payload']))
|
repr(protocols['payload']))
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv4_str, str(p_ipv4))
|
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||||
eq_(ipv4_str, repr(p_ipv4))
|
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||||
|
|
||||||
eq_(udp_str, str(p_udp))
|
self.assertEqual(udp_str, str(p_udp))
|
||||||
eq_(udp_str, repr(p_udp))
|
self.assertEqual(udp_str, repr(p_udp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv4_tcp(self):
|
def test_ipv4_tcp(self):
|
||||||
# buid packet
|
# buid packet
|
||||||
@ -479,49 +478,49 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_tcp = protocols['tcp']
|
p_tcp = protocols['tcp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_(self.dst_mac, p_eth.dst)
|
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||||
eq_(self.src_mac, p_eth.src)
|
self.assertEqual(self.src_mac, p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv4
|
# ipv4
|
||||||
ok_(p_ipv4)
|
self.assertTrue(p_ipv4)
|
||||||
eq_(4, p_ipv4.version)
|
self.assertEqual(4, p_ipv4.version)
|
||||||
eq_(5, p_ipv4.header_length)
|
self.assertEqual(5, p_ipv4.header_length)
|
||||||
eq_(0, p_ipv4.tos)
|
self.assertEqual(0, p_ipv4.tos)
|
||||||
l = len(ip_buf) + len(t_buf) + len(self.payload)
|
l = len(ip_buf) + len(t_buf) + len(self.payload)
|
||||||
eq_(l, p_ipv4.total_length)
|
self.assertEqual(l, p_ipv4.total_length)
|
||||||
eq_(0, p_ipv4.identification)
|
self.assertEqual(0, p_ipv4.identification)
|
||||||
eq_(0, p_ipv4.flags)
|
self.assertEqual(0, p_ipv4.flags)
|
||||||
eq_(64, p_ipv4.ttl)
|
self.assertEqual(64, p_ipv4.ttl)
|
||||||
eq_(inet.IPPROTO_TCP, p_ipv4.proto)
|
self.assertEqual(inet.IPPROTO_TCP, p_ipv4.proto)
|
||||||
eq_(self.src_ip, p_ipv4.src)
|
self.assertEqual(self.src_ip, p_ipv4.src)
|
||||||
eq_(self.dst_ip, p_ipv4.dst)
|
self.assertEqual(self.dst_ip, p_ipv4.dst)
|
||||||
t = bytearray(ip_buf)
|
t = bytearray(ip_buf)
|
||||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||||
eq_(packet_utils.checksum(t), 0)
|
self.assertEqual(packet_utils.checksum(t), 0)
|
||||||
|
|
||||||
# tcp
|
# tcp
|
||||||
ok_(p_tcp)
|
self.assertTrue(p_tcp)
|
||||||
eq_(0x190f, p_tcp.src_port)
|
self.assertEqual(0x190f, p_tcp.src_port)
|
||||||
eq_(0x1F90, p_tcp.dst_port)
|
self.assertEqual(0x1F90, p_tcp.dst_port)
|
||||||
eq_(0x123, p_tcp.seq)
|
self.assertEqual(0x123, p_tcp.seq)
|
||||||
eq_(1, p_tcp.ack)
|
self.assertEqual(1, p_tcp.ack)
|
||||||
eq_(6, p_tcp.offset)
|
self.assertEqual(6, p_tcp.offset)
|
||||||
eq_(0b101010, p_tcp.bits)
|
self.assertEqual(0b101010, p_tcp.bits)
|
||||||
eq_(2048, p_tcp.window_size)
|
self.assertEqual(2048, p_tcp.window_size)
|
||||||
eq_(0x6f, p_tcp.urgent)
|
self.assertEqual(0x6f, p_tcp.urgent)
|
||||||
eq_(len(t_buf), len(p_tcp))
|
self.assertEqual(len(t_buf), len(p_tcp))
|
||||||
t = bytearray(t_buf)
|
t = bytearray(t_buf)
|
||||||
struct.pack_into('!H', t, 16, p_tcp.csum)
|
struct.pack_into('!H', t, 16, p_tcp.csum)
|
||||||
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
||||||
6, len(t_buf) + len(self.payload))
|
6, len(t_buf) + len(self.payload))
|
||||||
t = ph + t + self.payload
|
t = ph + t + self.payload
|
||||||
eq_(packet_utils.checksum(t), 0)
|
self.assertEqual(packet_utils.checksum(t), 0)
|
||||||
|
|
||||||
# payload
|
# payload
|
||||||
ok_('payload' in protocols)
|
self.assertTrue('payload' in protocols)
|
||||||
eq_(self.payload, protocols['payload'])
|
self.assertEqual(self.payload, protocols['payload'])
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': self.dst_mac,
|
eth_values = {'dst': self.dst_mac,
|
||||||
@ -568,17 +567,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv4_str, tcp_str,
|
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv4_str, tcp_str,
|
||||||
repr(protocols['payload']))
|
repr(protocols['payload']))
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv4_str, str(p_ipv4))
|
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||||
eq_(ipv4_str, repr(p_ipv4))
|
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||||
|
|
||||||
eq_(tcp_str, str(p_tcp))
|
self.assertEqual(tcp_str, str(p_tcp))
|
||||||
eq_(tcp_str, repr(p_tcp))
|
self.assertEqual(tcp_str, repr(p_tcp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv4_sctp(self):
|
def test_ipv4_sctp(self):
|
||||||
# build packet
|
# build packet
|
||||||
@ -632,45 +631,45 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_sctp = protocols['sctp']
|
p_sctp = protocols['sctp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv4
|
# ipv4
|
||||||
ok_(p_ipv4)
|
self.assertTrue(p_ipv4)
|
||||||
eq_(4, p_ipv4.version)
|
self.assertEqual(4, p_ipv4.version)
|
||||||
eq_(5, p_ipv4.header_length)
|
self.assertEqual(5, p_ipv4.header_length)
|
||||||
eq_(0, p_ipv4.tos)
|
self.assertEqual(0, p_ipv4.tos)
|
||||||
l = len(ip_buf) + len(s_buf)
|
l = len(ip_buf) + len(s_buf)
|
||||||
eq_(l, p_ipv4.total_length)
|
self.assertEqual(l, p_ipv4.total_length)
|
||||||
eq_(0, p_ipv4.identification)
|
self.assertEqual(0, p_ipv4.identification)
|
||||||
eq_(0, p_ipv4.flags)
|
self.assertEqual(0, p_ipv4.flags)
|
||||||
eq_(255, p_ipv4.ttl)
|
self.assertEqual(255, p_ipv4.ttl)
|
||||||
eq_(inet.IPPROTO_SCTP, p_ipv4.proto)
|
self.assertEqual(inet.IPPROTO_SCTP, p_ipv4.proto)
|
||||||
eq_('10.0.0.1', p_ipv4.src)
|
self.assertEqual('10.0.0.1', p_ipv4.src)
|
||||||
eq_('10.0.0.2', p_ipv4.dst)
|
self.assertEqual('10.0.0.2', p_ipv4.dst)
|
||||||
t = bytearray(ip_buf)
|
t = bytearray(ip_buf)
|
||||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||||
eq_(packet_utils.checksum(t), 0x1403)
|
self.assertEqual(packet_utils.checksum(t), 0x1403)
|
||||||
|
|
||||||
# sctp
|
# sctp
|
||||||
ok_(p_sctp)
|
self.assertTrue(p_sctp)
|
||||||
eq_(1, p_sctp.src_port)
|
self.assertEqual(1, p_sctp.src_port)
|
||||||
eq_(1, p_sctp.dst_port)
|
self.assertEqual(1, p_sctp.dst_port)
|
||||||
eq_(0, p_sctp.vtag)
|
self.assertEqual(0, p_sctp.vtag)
|
||||||
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
||||||
eq_(0, p_sctp.chunks[0]._type)
|
self.assertEqual(0, p_sctp.chunks[0]._type)
|
||||||
eq_(0, p_sctp.chunks[0].unordered)
|
self.assertEqual(0, p_sctp.chunks[0].unordered)
|
||||||
eq_(0, p_sctp.chunks[0].begin)
|
self.assertEqual(0, p_sctp.chunks[0].begin)
|
||||||
eq_(0, p_sctp.chunks[0].end)
|
self.assertEqual(0, p_sctp.chunks[0].end)
|
||||||
eq_(16 + len(self.payload), p_sctp.chunks[0].length)
|
self.assertEqual(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||||
eq_(0, p_sctp.chunks[0].tsn)
|
self.assertEqual(0, p_sctp.chunks[0].tsn)
|
||||||
eq_(0, p_sctp.chunks[0].sid)
|
self.assertEqual(0, p_sctp.chunks[0].sid)
|
||||||
eq_(0, p_sctp.chunks[0].seq)
|
self.assertEqual(0, p_sctp.chunks[0].seq)
|
||||||
eq_(0, p_sctp.chunks[0].payload_id)
|
self.assertEqual(0, p_sctp.chunks[0].payload_id)
|
||||||
eq_(self.payload, p_sctp.chunks[0].payload_data)
|
self.assertEqual(self.payload, p_sctp.chunks[0].payload_data)
|
||||||
eq_(len(s_buf), len(p_sctp))
|
self.assertEqual(len(s_buf), len(p_sctp))
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -724,17 +723,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, ipv4_str, sctp_str)
|
pkt_str = '%s, %s, %s' % (eth_str, ipv4_str, sctp_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv4_str, str(p_ipv4))
|
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||||
eq_(ipv4_str, repr(p_ipv4))
|
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||||
|
|
||||||
eq_(sctp_str, str(p_sctp))
|
self.assertEqual(sctp_str, str(p_sctp))
|
||||||
eq_(sctp_str, repr(p_sctp))
|
self.assertEqual(sctp_str, repr(p_sctp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv4_icmp(self):
|
def test_ipv4_icmp(self):
|
||||||
# buid packet
|
# buid packet
|
||||||
@ -781,38 +780,38 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_icmp = protocols['icmp']
|
p_icmp = protocols['icmp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv4
|
# ipv4
|
||||||
ok_(p_ipv4)
|
self.assertTrue(p_ipv4)
|
||||||
eq_(4, p_ipv4.version)
|
self.assertEqual(4, p_ipv4.version)
|
||||||
eq_(5, p_ipv4.header_length)
|
self.assertEqual(5, p_ipv4.header_length)
|
||||||
eq_(0, p_ipv4.tos)
|
self.assertEqual(0, p_ipv4.tos)
|
||||||
l = len(ip_buf) + len(ic_buf)
|
l = len(ip_buf) + len(ic_buf)
|
||||||
eq_(l, p_ipv4.total_length)
|
self.assertEqual(l, p_ipv4.total_length)
|
||||||
eq_(0, p_ipv4.identification)
|
self.assertEqual(0, p_ipv4.identification)
|
||||||
eq_(0, p_ipv4.flags)
|
self.assertEqual(0, p_ipv4.flags)
|
||||||
eq_(255, p_ipv4.ttl)
|
self.assertEqual(255, p_ipv4.ttl)
|
||||||
eq_(inet.IPPROTO_ICMP, p_ipv4.proto)
|
self.assertEqual(inet.IPPROTO_ICMP, p_ipv4.proto)
|
||||||
eq_('10.0.0.1', p_ipv4.src)
|
self.assertEqual('10.0.0.1', p_ipv4.src)
|
||||||
eq_('10.0.0.2', p_ipv4.dst)
|
self.assertEqual('10.0.0.2', p_ipv4.dst)
|
||||||
t = bytearray(ip_buf)
|
t = bytearray(ip_buf)
|
||||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||||
eq_(packet_utils.checksum(t), 0x1403)
|
self.assertEqual(packet_utils.checksum(t), 0x1403)
|
||||||
|
|
||||||
# icmp
|
# icmp
|
||||||
ok_(p_icmp)
|
self.assertTrue(p_icmp)
|
||||||
eq_(8, p_icmp.type)
|
self.assertEqual(8, p_icmp.type)
|
||||||
eq_(0, p_icmp.code)
|
self.assertEqual(0, p_icmp.code)
|
||||||
eq_(0, p_icmp.data.id)
|
self.assertEqual(0, p_icmp.data.id)
|
||||||
eq_(0, p_icmp.data.seq)
|
self.assertEqual(0, p_icmp.data.seq)
|
||||||
eq_(len(ic_buf), len(p_icmp))
|
self.assertEqual(len(ic_buf), len(p_icmp))
|
||||||
t = bytearray(ic_buf)
|
t = bytearray(ic_buf)
|
||||||
struct.pack_into('!H', t, 2, p_icmp.csum)
|
struct.pack_into('!H', t, 2, p_icmp.csum)
|
||||||
eq_(packet_utils.checksum(t), 0)
|
self.assertEqual(packet_utils.checksum(t), 0)
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -858,17 +857,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, ipv4_str, icmp_str)
|
pkt_str = '%s, %s, %s' % (eth_str, ipv4_str, icmp_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv4_str, str(p_ipv4))
|
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||||
eq_(ipv4_str, repr(p_ipv4))
|
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||||
|
|
||||||
eq_(icmp_str, str(p_icmp))
|
self.assertEqual(icmp_str, str(p_icmp))
|
||||||
eq_(icmp_str, repr(p_icmp))
|
self.assertEqual(icmp_str, repr(p_icmp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv6_udp(self):
|
def test_ipv6_udp(self):
|
||||||
# build packet
|
# build packet
|
||||||
@ -911,38 +910,38 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_udp = protocols['udp']
|
p_udp = protocols['udp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv6
|
# ipv6
|
||||||
ok_(p_ipv6)
|
self.assertTrue(p_ipv6)
|
||||||
eq_(6, p_ipv6.version)
|
self.assertEqual(6, p_ipv6.version)
|
||||||
eq_(0, p_ipv6.traffic_class)
|
self.assertEqual(0, p_ipv6.traffic_class)
|
||||||
eq_(0, p_ipv6.flow_label)
|
self.assertEqual(0, p_ipv6.flow_label)
|
||||||
eq_(len(u_buf) + len(self.payload), p_ipv6.payload_length)
|
self.assertEqual(len(u_buf) + len(self.payload), p_ipv6.payload_length)
|
||||||
eq_(inet.IPPROTO_UDP, p_ipv6.nxt)
|
self.assertEqual(inet.IPPROTO_UDP, p_ipv6.nxt)
|
||||||
eq_(255, p_ipv6.hop_limit)
|
self.assertEqual(255, p_ipv6.hop_limit)
|
||||||
eq_('10::10', p_ipv6.src)
|
self.assertEqual('10::10', p_ipv6.src)
|
||||||
eq_('20::20', p_ipv6.dst)
|
self.assertEqual('20::20', p_ipv6.dst)
|
||||||
|
|
||||||
# udp
|
# udp
|
||||||
ok_(p_udp)
|
self.assertTrue(p_udp)
|
||||||
eq_(1, p_udp.src_port)
|
self.assertEqual(1, p_udp.src_port)
|
||||||
eq_(1, p_udp.dst_port)
|
self.assertEqual(1, p_udp.dst_port)
|
||||||
eq_(len(u_buf) + len(self.payload), p_udp.total_length)
|
self.assertEqual(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||||
eq_(0x2B60, p_udp.csum)
|
self.assertEqual(0x2B60, p_udp.csum)
|
||||||
t = bytearray(u_buf)
|
t = bytearray(u_buf)
|
||||||
struct.pack_into('!H', t, 6, p_udp.csum)
|
struct.pack_into('!H', t, 6, p_udp.csum)
|
||||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
||||||
len(u_buf) + len(self.payload), 17)
|
len(u_buf) + len(self.payload), 17)
|
||||||
t = ph + t + self.payload
|
t = ph + t + self.payload
|
||||||
eq_(packet_utils.checksum(t), 0x62)
|
self.assertEqual(packet_utils.checksum(t), 0x62)
|
||||||
|
|
||||||
# payload
|
# payload
|
||||||
ok_('payload' in protocols)
|
self.assertTrue('payload' in protocols)
|
||||||
eq_(self.payload, protocols['payload'])
|
self.assertEqual(self.payload, protocols['payload'])
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -979,17 +978,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv6_str, udp_str,
|
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv6_str, udp_str,
|
||||||
repr(protocols['payload']))
|
repr(protocols['payload']))
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv6_str, str(p_ipv6))
|
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||||
eq_(ipv6_str, repr(p_ipv6))
|
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||||
|
|
||||||
eq_(udp_str, str(p_udp))
|
self.assertEqual(udp_str, str(p_udp))
|
||||||
eq_(udp_str, repr(p_udp))
|
self.assertEqual(udp_str, repr(p_udp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv6_tcp(self):
|
def test_ipv6_tcp(self):
|
||||||
# build packet
|
# build packet
|
||||||
@ -1038,43 +1037,43 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_tcp = protocols['tcp']
|
p_tcp = protocols['tcp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv6
|
# ipv6
|
||||||
ok_(p_ipv6)
|
self.assertTrue(p_ipv6)
|
||||||
eq_(6, p_ipv6.version)
|
self.assertEqual(6, p_ipv6.version)
|
||||||
eq_(0, p_ipv6.traffic_class)
|
self.assertEqual(0, p_ipv6.traffic_class)
|
||||||
eq_(0, p_ipv6.flow_label)
|
self.assertEqual(0, p_ipv6.flow_label)
|
||||||
eq_(len(t_buf) + len(self.payload), p_ipv6.payload_length)
|
self.assertEqual(len(t_buf) + len(self.payload), p_ipv6.payload_length)
|
||||||
eq_(inet.IPPROTO_TCP, p_ipv6.nxt)
|
self.assertEqual(inet.IPPROTO_TCP, p_ipv6.nxt)
|
||||||
eq_(255, p_ipv6.hop_limit)
|
self.assertEqual(255, p_ipv6.hop_limit)
|
||||||
eq_('10::10', p_ipv6.src)
|
self.assertEqual('10::10', p_ipv6.src)
|
||||||
eq_('20::20', p_ipv6.dst)
|
self.assertEqual('20::20', p_ipv6.dst)
|
||||||
|
|
||||||
# tcp
|
# tcp
|
||||||
ok_(p_tcp)
|
self.assertTrue(p_tcp)
|
||||||
eq_(1, p_tcp.src_port)
|
self.assertEqual(1, p_tcp.src_port)
|
||||||
eq_(1, p_tcp.dst_port)
|
self.assertEqual(1, p_tcp.dst_port)
|
||||||
eq_(0, p_tcp.seq)
|
self.assertEqual(0, p_tcp.seq)
|
||||||
eq_(0, p_tcp.ack)
|
self.assertEqual(0, p_tcp.ack)
|
||||||
eq_(6, p_tcp.offset)
|
self.assertEqual(6, p_tcp.offset)
|
||||||
eq_(0, p_tcp.bits)
|
self.assertEqual(0, p_tcp.bits)
|
||||||
eq_(0, p_tcp.window_size)
|
self.assertEqual(0, p_tcp.window_size)
|
||||||
eq_(0, p_tcp.urgent)
|
self.assertEqual(0, p_tcp.urgent)
|
||||||
eq_(len(t_buf), len(p_tcp))
|
self.assertEqual(len(t_buf), len(p_tcp))
|
||||||
t = bytearray(t_buf)
|
t = bytearray(t_buf)
|
||||||
struct.pack_into('!H', t, 16, p_tcp.csum)
|
struct.pack_into('!H', t, 16, p_tcp.csum)
|
||||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
||||||
len(t_buf) + len(self.payload), 6)
|
len(t_buf) + len(self.payload), 6)
|
||||||
t = ph + t + self.payload
|
t = ph + t + self.payload
|
||||||
eq_(packet_utils.checksum(t), 0x62)
|
self.assertEqual(packet_utils.checksum(t), 0x62)
|
||||||
|
|
||||||
# payload
|
# payload
|
||||||
ok_('payload' in protocols)
|
self.assertTrue('payload' in protocols)
|
||||||
eq_(self.payload, protocols['payload'])
|
self.assertEqual(self.payload, protocols['payload'])
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -1117,17 +1116,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv6_str, tcp_str,
|
pkt_str = '%s, %s, %s, %s' % (eth_str, ipv6_str, tcp_str,
|
||||||
repr(protocols['payload']))
|
repr(protocols['payload']))
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv6_str, str(p_ipv6))
|
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||||
eq_(ipv6_str, repr(p_ipv6))
|
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||||
|
|
||||||
eq_(tcp_str, str(p_tcp))
|
self.assertEqual(tcp_str, str(p_tcp))
|
||||||
eq_(tcp_str, repr(p_tcp))
|
self.assertEqual(tcp_str, repr(p_tcp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv6_sctp(self):
|
def test_ipv6_sctp(self):
|
||||||
# build packet
|
# build packet
|
||||||
@ -1178,39 +1177,39 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_sctp = protocols['sctp']
|
p_sctp = protocols['sctp']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv6
|
# ipv6
|
||||||
ok_(p_ipv6)
|
self.assertTrue(p_ipv6)
|
||||||
eq_(6, p_ipv6.version)
|
self.assertEqual(6, p_ipv6.version)
|
||||||
eq_(0, p_ipv6.traffic_class)
|
self.assertEqual(0, p_ipv6.traffic_class)
|
||||||
eq_(0, p_ipv6.flow_label)
|
self.assertEqual(0, p_ipv6.flow_label)
|
||||||
eq_(len(s_buf), p_ipv6.payload_length)
|
self.assertEqual(len(s_buf), p_ipv6.payload_length)
|
||||||
eq_(inet.IPPROTO_SCTP, p_ipv6.nxt)
|
self.assertEqual(inet.IPPROTO_SCTP, p_ipv6.nxt)
|
||||||
eq_(255, p_ipv6.hop_limit)
|
self.assertEqual(255, p_ipv6.hop_limit)
|
||||||
eq_('10::10', p_ipv6.src)
|
self.assertEqual('10::10', p_ipv6.src)
|
||||||
eq_('20::20', p_ipv6.dst)
|
self.assertEqual('20::20', p_ipv6.dst)
|
||||||
|
|
||||||
# sctp
|
# sctp
|
||||||
ok_(p_sctp)
|
self.assertTrue(p_sctp)
|
||||||
eq_(1, p_sctp.src_port)
|
self.assertEqual(1, p_sctp.src_port)
|
||||||
eq_(1, p_sctp.dst_port)
|
self.assertEqual(1, p_sctp.dst_port)
|
||||||
eq_(0, p_sctp.vtag)
|
self.assertEqual(0, p_sctp.vtag)
|
||||||
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
||||||
eq_(0, p_sctp.chunks[0]._type)
|
self.assertEqual(0, p_sctp.chunks[0]._type)
|
||||||
eq_(0, p_sctp.chunks[0].unordered)
|
self.assertEqual(0, p_sctp.chunks[0].unordered)
|
||||||
eq_(0, p_sctp.chunks[0].begin)
|
self.assertEqual(0, p_sctp.chunks[0].begin)
|
||||||
eq_(0, p_sctp.chunks[0].end)
|
self.assertEqual(0, p_sctp.chunks[0].end)
|
||||||
eq_(16 + len(self.payload), p_sctp.chunks[0].length)
|
self.assertEqual(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||||
eq_(0, p_sctp.chunks[0].tsn)
|
self.assertEqual(0, p_sctp.chunks[0].tsn)
|
||||||
eq_(0, p_sctp.chunks[0].sid)
|
self.assertEqual(0, p_sctp.chunks[0].sid)
|
||||||
eq_(0, p_sctp.chunks[0].seq)
|
self.assertEqual(0, p_sctp.chunks[0].seq)
|
||||||
eq_(0, p_sctp.chunks[0].payload_id)
|
self.assertEqual(0, p_sctp.chunks[0].payload_id)
|
||||||
eq_(self.payload, p_sctp.chunks[0].payload_data)
|
self.assertEqual(self.payload, p_sctp.chunks[0].payload_data)
|
||||||
eq_(len(s_buf), len(p_sctp))
|
self.assertEqual(len(s_buf), len(p_sctp))
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -1260,17 +1259,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, ipv6_str, sctp_str)
|
pkt_str = '%s, %s, %s' % (eth_str, ipv6_str, sctp_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv6_str, str(p_ipv6))
|
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||||
eq_(ipv6_str, repr(p_ipv6))
|
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||||
|
|
||||||
eq_(sctp_str, str(p_sctp))
|
self.assertEqual(sctp_str, str(p_sctp))
|
||||||
eq_(sctp_str, repr(p_sctp))
|
self.assertEqual(sctp_str, repr(p_sctp))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_ipv6_icmpv6(self):
|
def test_ipv6_icmpv6(self):
|
||||||
# build packet
|
# build packet
|
||||||
@ -1312,32 +1311,32 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_icmpv6 = protocols['icmpv6']
|
p_icmpv6 = protocols['icmpv6']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||||
eq_('00:00:00:00:00:00', p_eth.src)
|
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||||
|
|
||||||
# ipv6
|
# ipv6
|
||||||
ok_(p_ipv6)
|
self.assertTrue(p_ipv6)
|
||||||
eq_(6, p_ipv6.version)
|
self.assertEqual(6, p_ipv6.version)
|
||||||
eq_(0, p_ipv6.traffic_class)
|
self.assertEqual(0, p_ipv6.traffic_class)
|
||||||
eq_(0, p_ipv6.flow_label)
|
self.assertEqual(0, p_ipv6.flow_label)
|
||||||
eq_(len(ic_buf), p_ipv6.payload_length)
|
self.assertEqual(len(ic_buf), p_ipv6.payload_length)
|
||||||
eq_(inet.IPPROTO_ICMPV6, p_ipv6.nxt)
|
self.assertEqual(inet.IPPROTO_ICMPV6, p_ipv6.nxt)
|
||||||
eq_(255, p_ipv6.hop_limit)
|
self.assertEqual(255, p_ipv6.hop_limit)
|
||||||
eq_('10::10', p_ipv6.src)
|
self.assertEqual('10::10', p_ipv6.src)
|
||||||
eq_('20::20', p_ipv6.dst)
|
self.assertEqual('20::20', p_ipv6.dst)
|
||||||
|
|
||||||
# icmpv6
|
# icmpv6
|
||||||
ok_(p_icmpv6)
|
self.assertTrue(p_icmpv6)
|
||||||
eq_(0, p_icmpv6.type_)
|
self.assertEqual(0, p_icmpv6.type_)
|
||||||
eq_(0, p_icmpv6.code)
|
self.assertEqual(0, p_icmpv6.code)
|
||||||
eq_(len(ic_buf), len(p_icmpv6))
|
self.assertEqual(len(ic_buf), len(p_icmpv6))
|
||||||
t = bytearray(ic_buf)
|
t = bytearray(ic_buf)
|
||||||
struct.pack_into('!H', t, 2, p_icmpv6.csum)
|
struct.pack_into('!H', t, 2, p_icmpv6.csum)
|
||||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr, len(ic_buf), 58)
|
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr, len(ic_buf), 58)
|
||||||
t = ph + t
|
t = ph + t
|
||||||
eq_(packet_utils.checksum(t), 0x60)
|
self.assertEqual(packet_utils.checksum(t), 0x60)
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
|
||||||
@ -1373,17 +1372,17 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, ipv6_str, icmpv6_str)
|
pkt_str = '%s, %s, %s' % (eth_str, ipv6_str, icmpv6_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(ipv6_str, str(p_ipv6))
|
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||||
eq_(ipv6_str, repr(p_ipv6))
|
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||||
|
|
||||||
eq_(icmpv6_str, str(p_icmpv6))
|
self.assertEqual(icmpv6_str, str(p_icmpv6))
|
||||||
eq_(icmpv6_str, repr(p_icmpv6))
|
self.assertEqual(icmpv6_str, repr(p_icmpv6))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_llc_bpdu(self):
|
def test_llc_bpdu(self):
|
||||||
# buid packet
|
# buid packet
|
||||||
@ -1440,7 +1439,7 @@ class TestPacket(unittest.TestCase):
|
|||||||
pad_len = 60 - len(buf)
|
pad_len = 60 - len(buf)
|
||||||
if pad_len > 0:
|
if pad_len > 0:
|
||||||
buf += b'\x00' * pad_len
|
buf += b'\x00' * pad_len
|
||||||
eq_(buf, p.data)
|
self.assertEqual(buf, p.data)
|
||||||
|
|
||||||
# parse
|
# parse
|
||||||
pkt = packet.Packet(p.data)
|
pkt = packet.Packet(p.data)
|
||||||
@ -1450,38 +1449,38 @@ class TestPacket(unittest.TestCase):
|
|||||||
p_bpdu = protocols['ConfigurationBPDUs']
|
p_bpdu = protocols['ConfigurationBPDUs']
|
||||||
|
|
||||||
# ethernet
|
# ethernet
|
||||||
ok_(p_eth)
|
self.assertTrue(p_eth)
|
||||||
eq_(self.dst_mac, p_eth.dst)
|
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||||
eq_(self.src_mac, p_eth.src)
|
self.assertEqual(self.src_mac, p_eth.src)
|
||||||
eq_(ether.ETH_TYPE_IEEE802_3, p_eth.ethertype)
|
self.assertEqual(ether.ETH_TYPE_IEEE802_3, p_eth.ethertype)
|
||||||
|
|
||||||
# llc
|
# llc
|
||||||
ok_(p_llc)
|
self.assertTrue(p_llc)
|
||||||
eq_(llc.SAP_BPDU, p_llc.dsap_addr)
|
self.assertEqual(llc.SAP_BPDU, p_llc.dsap_addr)
|
||||||
eq_(llc.SAP_BPDU, p_llc.ssap_addr)
|
self.assertEqual(llc.SAP_BPDU, p_llc.ssap_addr)
|
||||||
eq_(0, p_llc.control.modifier_function1)
|
self.assertEqual(0, p_llc.control.modifier_function1)
|
||||||
eq_(0, p_llc.control.pf_bit)
|
self.assertEqual(0, p_llc.control.pf_bit)
|
||||||
eq_(0, p_llc.control.modifier_function2)
|
self.assertEqual(0, p_llc.control.modifier_function2)
|
||||||
|
|
||||||
# bpdu
|
# bpdu
|
||||||
ok_(p_bpdu)
|
self.assertTrue(p_bpdu)
|
||||||
eq_(bpdu.PROTOCOL_IDENTIFIER, p_bpdu._protocol_id)
|
self.assertEqual(bpdu.PROTOCOL_IDENTIFIER, p_bpdu._protocol_id)
|
||||||
eq_(bpdu.PROTOCOLVERSION_ID_BPDU, p_bpdu._version_id)
|
self.assertEqual(bpdu.PROTOCOLVERSION_ID_BPDU, p_bpdu._version_id)
|
||||||
eq_(bpdu.TYPE_CONFIG_BPDU, p_bpdu._bpdu_type)
|
self.assertEqual(bpdu.TYPE_CONFIG_BPDU, p_bpdu._bpdu_type)
|
||||||
eq_(0, p_bpdu.flags)
|
self.assertEqual(0, p_bpdu.flags)
|
||||||
eq_(32768, p_bpdu.root_priority)
|
self.assertEqual(32768, p_bpdu.root_priority)
|
||||||
eq_(0, p_bpdu.root_system_id_extension)
|
self.assertEqual(0, p_bpdu.root_system_id_extension)
|
||||||
eq_(self.src_mac, p_bpdu.root_mac_address)
|
self.assertEqual(self.src_mac, p_bpdu.root_mac_address)
|
||||||
eq_(0, p_bpdu.root_path_cost)
|
self.assertEqual(0, p_bpdu.root_path_cost)
|
||||||
eq_(32768, p_bpdu.bridge_priority)
|
self.assertEqual(32768, p_bpdu.bridge_priority)
|
||||||
eq_(0, p_bpdu.bridge_system_id_extension)
|
self.assertEqual(0, p_bpdu.bridge_system_id_extension)
|
||||||
eq_(self.dst_mac, p_bpdu.bridge_mac_address)
|
self.assertEqual(self.dst_mac, p_bpdu.bridge_mac_address)
|
||||||
eq_(128, p_bpdu.port_priority)
|
self.assertEqual(128, p_bpdu.port_priority)
|
||||||
eq_(4, p_bpdu.port_number)
|
self.assertEqual(4, p_bpdu.port_number)
|
||||||
eq_(1, p_bpdu.message_age)
|
self.assertEqual(1, p_bpdu.message_age)
|
||||||
eq_(20, p_bpdu.max_age)
|
self.assertEqual(20, p_bpdu.max_age)
|
||||||
eq_(2, p_bpdu.hello_time)
|
self.assertEqual(2, p_bpdu.hello_time)
|
||||||
eq_(15, p_bpdu.forward_delay)
|
self.assertEqual(15, p_bpdu.forward_delay)
|
||||||
|
|
||||||
# to string
|
# to string
|
||||||
eth_values = {'dst': self.dst_mac,
|
eth_values = {'dst': self.dst_mac,
|
||||||
@ -1530,24 +1529,24 @@ class TestPacket(unittest.TestCase):
|
|||||||
|
|
||||||
pkt_str = '%s, %s, %s' % (eth_str, llc_str, bpdu_str)
|
pkt_str = '%s, %s, %s' % (eth_str, llc_str, bpdu_str)
|
||||||
|
|
||||||
eq_(eth_str, str(p_eth))
|
self.assertEqual(eth_str, str(p_eth))
|
||||||
eq_(eth_str, repr(p_eth))
|
self.assertEqual(eth_str, repr(p_eth))
|
||||||
|
|
||||||
eq_(llc_str, str(p_llc))
|
self.assertEqual(llc_str, str(p_llc))
|
||||||
eq_(llc_str, repr(p_llc))
|
self.assertEqual(llc_str, repr(p_llc))
|
||||||
|
|
||||||
eq_(bpdu_str, str(p_bpdu))
|
self.assertEqual(bpdu_str, str(p_bpdu))
|
||||||
eq_(bpdu_str, repr(p_bpdu))
|
self.assertEqual(bpdu_str, repr(p_bpdu))
|
||||||
|
|
||||||
eq_(pkt_str, str(pkt))
|
self.assertEqual(pkt_str, str(pkt))
|
||||||
eq_(pkt_str, repr(pkt))
|
self.assertEqual(pkt_str, repr(pkt))
|
||||||
|
|
||||||
def test_div_api(self):
|
def test_div_api(self):
|
||||||
e = ethernet.ethernet(self.dst_mac, self.src_mac, ether.ETH_TYPE_IP)
|
e = ethernet.ethernet(self.dst_mac, self.src_mac, ether.ETH_TYPE_IP)
|
||||||
i = ipv4.ipv4()
|
i = ipv4.ipv4()
|
||||||
u = udp.udp(self.src_port, self.dst_port)
|
u = udp.udp(self.src_port, self.dst_port)
|
||||||
pkt = e / i / u
|
pkt = e / i / u
|
||||||
ok_(isinstance(pkt, packet.Packet))
|
self.assertTrue(isinstance(pkt, packet.Packet))
|
||||||
ok_(isinstance(pkt.protocols[0], ethernet.ethernet))
|
self.assertTrue(isinstance(pkt.protocols[0], ethernet.ethernet))
|
||||||
ok_(isinstance(pkt.protocols[1], ipv4.ipv4))
|
self.assertTrue(isinstance(pkt.protocols[1], ipv4.ipv4))
|
||||||
ok_(isinstance(pkt.protocols[2], udp.udp))
|
self.assertTrue(isinstance(pkt.protocols[2], udp.udp))
|
||||||
|
@ -17,9 +17,6 @@ import logging
|
|||||||
import struct
|
import struct
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
from nose.tools import raises
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.ofproto import inet
|
from os_ken.ofproto import inet
|
||||||
from os_ken.lib.packet import ethernet
|
from os_ken.lib.packet import ethernet
|
||||||
@ -49,10 +46,10 @@ class Test_itag(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.pcp, self.it.pcp)
|
self.assertEqual(self.pcp, self.it.pcp)
|
||||||
eq_(self.dei, self.it.dei)
|
self.assertEqual(self.dei, self.it.dei)
|
||||||
eq_(self.uca, self.it.uca)
|
self.assertEqual(self.uca, self.it.uca)
|
||||||
eq_(self.sid, self.it.sid)
|
self.assertEqual(self.sid, self.it.sid)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = pbb.itag.parser(self.buf)
|
_res = pbb.itag.parser(self.buf)
|
||||||
@ -60,17 +57,17 @@ class Test_itag(unittest.TestCase):
|
|||||||
res = _res[0]
|
res = _res[0]
|
||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
eq_(res.pcp, self.pcp)
|
self.assertEqual(res.pcp, self.pcp)
|
||||||
eq_(res.dei, self.dei)
|
self.assertEqual(res.dei, self.dei)
|
||||||
eq_(res.uca, self.uca)
|
self.assertEqual(res.uca, self.uca)
|
||||||
eq_(res.sid, self.sid)
|
self.assertEqual(res.sid, self.sid)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
prev = None
|
prev = None
|
||||||
buf = self.it.serialize(data, prev)
|
buf = self.it.serialize(data, prev)
|
||||||
res = struct.unpack(pbb.itag._PACK_STR, buf)
|
res = struct.unpack(pbb.itag._PACK_STR, buf)
|
||||||
eq_(res[0], self.data)
|
self.assertEqual(res[0], self.data)
|
||||||
|
|
||||||
def _build_itag(self):
|
def _build_itag(self):
|
||||||
b_src_mac = '00:07:0d:af:f4:54'
|
b_src_mac = '00:07:0d:af:f4:54'
|
||||||
@ -135,38 +132,37 @@ class Test_itag(unittest.TestCase):
|
|||||||
p = self._build_itag()
|
p = self._build_itag()
|
||||||
|
|
||||||
e = p.get_protocols(ethernet.ethernet)
|
e = p.get_protocols(ethernet.ethernet)
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
ok_(isinstance(e, list))
|
self.assertTrue(isinstance(e, list))
|
||||||
eq_(e[0].ethertype, ether.ETH_TYPE_8021AD)
|
self.assertEqual(e[0].ethertype, ether.ETH_TYPE_8021AD)
|
||||||
eq_(e[1].ethertype, ether.ETH_TYPE_8021AD)
|
self.assertEqual(e[1].ethertype, ether.ETH_TYPE_8021AD)
|
||||||
|
|
||||||
sv = p.get_protocols(vlan.svlan)
|
sv = p.get_protocols(vlan.svlan)
|
||||||
ok_(sv)
|
self.assertTrue(sv)
|
||||||
ok_(isinstance(sv, list))
|
self.assertTrue(isinstance(sv, list))
|
||||||
eq_(sv[0].ethertype, ether.ETH_TYPE_8021Q)
|
self.assertEqual(sv[0].ethertype, ether.ETH_TYPE_8021Q)
|
||||||
eq_(sv[1].ethertype, ether.ETH_TYPE_8021Q)
|
self.assertEqual(sv[1].ethertype, ether.ETH_TYPE_8021Q)
|
||||||
|
|
||||||
it = p.get_protocol(pbb.itag)
|
it = p.get_protocol(pbb.itag)
|
||||||
ok_(it)
|
self.assertTrue(it)
|
||||||
|
|
||||||
v = p.get_protocol(vlan.vlan)
|
v = p.get_protocol(vlan.vlan)
|
||||||
ok_(v)
|
self.assertTrue(v)
|
||||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
ip = p.get_protocol(ipv4.ipv4)
|
ip = p.get_protocol(ipv4.ipv4)
|
||||||
ok_(ip)
|
self.assertTrue(ip)
|
||||||
|
|
||||||
eq_(it.pcp, self.pcp)
|
self.assertEqual(it.pcp, self.pcp)
|
||||||
eq_(it.dei, self.dei)
|
self.assertEqual(it.dei, self.dei)
|
||||||
eq_(it.uca, self.uca)
|
self.assertEqual(it.uca, self.uca)
|
||||||
eq_(it.sid, self.sid)
|
self.assertEqual(it.sid, self.sid)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_itag(self):
|
def test_malformed_itag(self):
|
||||||
m_short_buf = self.buf[1:pbb.itag._MIN_LEN]
|
m_short_buf = self.buf[1:pbb.itag._MIN_LEN]
|
||||||
pbb.itag.parser(m_short_buf)
|
self.assertRaises(Exception, pbb.itag.parser, m_short_buf)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.it.to_jsondict()
|
jsondict = self.it.to_jsondict()
|
||||||
it = pbb.itag.from_jsondict(jsondict['itag'])
|
it = pbb.itag.from_jsondict(jsondict['itag'])
|
||||||
eq_(str(self.it), str(it))
|
self.assertEqual(str(self.it), str(it))
|
||||||
|
@ -20,8 +20,6 @@ import six
|
|||||||
import struct
|
import struct
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
from os_ken.lib import addrconv
|
from os_ken.lib import addrconv
|
||||||
from os_ken.lib.packet import packet
|
from os_ken.lib.packet import packet
|
||||||
from os_ken.lib.packet import ethernet
|
from os_ken.lib.packet import ethernet
|
||||||
@ -518,11 +516,11 @@ class Test_sctp(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.src_port, self.sc.src_port)
|
self.assertEqual(self.src_port, self.sc.src_port)
|
||||||
eq_(self.dst_port, self.sc.dst_port)
|
self.assertEqual(self.dst_port, self.sc.dst_port)
|
||||||
eq_(self.vtag, self.sc.vtag)
|
self.assertEqual(self.vtag, self.sc.vtag)
|
||||||
eq_(self.csum, self.sc.csum)
|
self.assertEqual(self.csum, self.sc.csum)
|
||||||
eq_(self.chunks, self.sc.chunks)
|
self.assertEqual(self.chunks, self.sc.chunks)
|
||||||
|
|
||||||
def test_init_with_data(self):
|
def test_init_with_data(self):
|
||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
@ -597,11 +595,11 @@ class Test_sctp(unittest.TestCase):
|
|||||||
# to calculate the lengths of parameters.
|
# to calculate the lengths of parameters.
|
||||||
self.sc.serialize(None, None)
|
self.sc.serialize(None, None)
|
||||||
|
|
||||||
eq_(self.src_port, res.src_port)
|
self.assertEqual(self.src_port, res.src_port)
|
||||||
eq_(self.dst_port, res.dst_port)
|
self.assertEqual(self.dst_port, res.dst_port)
|
||||||
eq_(self.vtag, res.vtag)
|
self.assertEqual(self.vtag, res.vtag)
|
||||||
eq_(self.csum, res.csum)
|
self.assertEqual(self.csum, res.csum)
|
||||||
eq_(str(self.chunks), str(res.chunks))
|
self.assertEqual(str(self.chunks), str(res.chunks))
|
||||||
|
|
||||||
def test_parser_with_data(self):
|
def test_parser_with_data(self):
|
||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
@ -670,11 +668,11 @@ class Test_sctp(unittest.TestCase):
|
|||||||
def _test_serialize(self):
|
def _test_serialize(self):
|
||||||
buf = self.sc.serialize(bytearray(), None)
|
buf = self.sc.serialize(bytearray(), None)
|
||||||
res = struct.unpack_from(sctp.sctp._PACK_STR, buf)
|
res = struct.unpack_from(sctp.sctp._PACK_STR, buf)
|
||||||
eq_(self.src_port, res[0])
|
self.assertEqual(self.src_port, res[0])
|
||||||
eq_(self.dst_port, res[1])
|
self.assertEqual(self.dst_port, res[1])
|
||||||
eq_(self.vtag, res[2])
|
self.assertEqual(self.vtag, res[2])
|
||||||
# skip compare checksum
|
# skip compare checksum
|
||||||
# eq_(self.csum, res[3])
|
# self.assertEqual(self.csum, res[3])
|
||||||
|
|
||||||
return buf[sctp.sctp._MIN_LEN:]
|
return buf[sctp.sctp._MIN_LEN:]
|
||||||
|
|
||||||
@ -685,71 +683,71 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_data.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_data.chunk_type(), res[0])
|
||||||
flags = (
|
flags = (
|
||||||
(self.unordered << 2) |
|
(self.unordered << 2) |
|
||||||
(self.begin << 1) |
|
(self.begin << 1) |
|
||||||
(self.end << 0))
|
(self.end << 0))
|
||||||
eq_(flags, res[1])
|
self.assertEqual(flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.tsn, res[3])
|
self.assertEqual(self.tsn, res[3])
|
||||||
eq_(self.sid, res[4])
|
self.assertEqual(self.sid, res[4])
|
||||||
eq_(self.seq, res[5])
|
self.assertEqual(self.seq, res[5])
|
||||||
eq_(self.payload_id, res[6])
|
self.assertEqual(self.payload_id, res[6])
|
||||||
eq_(self.payload_data, buf[sctp.chunk_data._MIN_LEN:])
|
self.assertEqual(self.payload_data, buf[sctp.chunk_data._MIN_LEN:])
|
||||||
|
|
||||||
def test_serialize_with_init(self):
|
def test_serialize_with_init(self):
|
||||||
self.setUp_with_init()
|
self.setUp_with_init()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_init._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_init._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_init.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_init.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.init_tag, res[3])
|
self.assertEqual(self.init_tag, res[3])
|
||||||
eq_(self.a_rwnd, res[4])
|
self.assertEqual(self.a_rwnd, res[4])
|
||||||
eq_(self.os, res[5])
|
self.assertEqual(self.os, res[5])
|
||||||
eq_(self.mis, res[6])
|
self.assertEqual(self.mis, res[6])
|
||||||
eq_(self.i_tsn, res[7])
|
self.assertEqual(self.i_tsn, res[7])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_init._MIN_LEN:]
|
buf = buf[sctp.chunk_init._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
||||||
eq_(sctp.param_ipv4.param_type(), res1[0])
|
self.assertEqual(sctp.param_ipv4.param_type(), res1[0])
|
||||||
eq_(8, res1[1])
|
self.assertEqual(8, res1[1])
|
||||||
eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
|
self.assertEqual('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||||
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res2 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
res2 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
||||||
eq_(sctp.param_ipv6.param_type(), res2[0])
|
self.assertEqual(sctp.param_ipv6.param_type(), res2[0])
|
||||||
eq_(20, res2[1])
|
self.assertEqual(20, res2[1])
|
||||||
eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
self.assertEqual('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
||||||
buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
|
buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
|
||||||
|
|
||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res3 = struct.unpack_from(sctp.param_cookie_preserve._PACK_STR,
|
res3 = struct.unpack_from(sctp.param_cookie_preserve._PACK_STR,
|
||||||
buf)
|
buf)
|
||||||
eq_(sctp.param_cookie_preserve.param_type(), res3[0])
|
self.assertEqual(sctp.param_cookie_preserve.param_type(), res3[0])
|
||||||
eq_(8, res3[1])
|
self.assertEqual(8, res3[1])
|
||||||
eq_(5000, res3[2])
|
self.assertEqual(5000, res3[2])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res4 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
res4 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
||||||
eq_(sctp.param_ecn.param_type(), res4[0])
|
self.assertEqual(sctp.param_ecn.param_type(), res4[0])
|
||||||
eq_(4, res4[1])
|
self.assertEqual(4, res4[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res5 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
res5 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
||||||
eq_(sctp.param_host_addr.param_type(), res5[0])
|
self.assertEqual(sctp.param_host_addr.param_type(), res5[0])
|
||||||
eq_(14, res5[1])
|
self.assertEqual(14, res5[1])
|
||||||
eq_(b'test host\x00',
|
self.assertEqual(b'test host\x00',
|
||||||
buf[sctp.param_host_addr._MIN_LEN:
|
buf[sctp.param_host_addr._MIN_LEN:
|
||||||
sctp.param_host_addr._MIN_LEN + 10])
|
sctp.param_host_addr._MIN_LEN + 10])
|
||||||
|
|
||||||
buf = buf[16:]
|
buf = buf[16:]
|
||||||
res6 = struct.unpack_from(sctp.param_supported_addr._PACK_STR, buf)
|
res6 = struct.unpack_from(sctp.param_supported_addr._PACK_STR, buf)
|
||||||
res6 = list(res6)
|
res6 = list(res6)
|
||||||
eq_(sctp.param_supported_addr.param_type(), res6[0])
|
self.assertEqual(sctp.param_supported_addr.param_type(), res6[0])
|
||||||
eq_(14, res6[1])
|
self.assertEqual(14, res6[1])
|
||||||
buf = buf[sctp.param_supported_addr._MIN_LEN:]
|
buf = buf[sctp.param_supported_addr._MIN_LEN:]
|
||||||
offset = 0
|
offset = 0
|
||||||
tmplist = []
|
tmplist = []
|
||||||
@ -758,66 +756,66 @@ class Test_sctp(unittest.TestCase):
|
|||||||
tmplist.append(tmp)
|
tmplist.append(tmp)
|
||||||
offset += struct.calcsize('!H')
|
offset += struct.calcsize('!H')
|
||||||
res6.extend(tmplist)
|
res6.extend(tmplist)
|
||||||
eq_(sctp.PTYPE_IPV4, res6[2])
|
self.assertEqual(sctp.PTYPE_IPV4, res6[2])
|
||||||
eq_(sctp.PTYPE_IPV6, res6[3])
|
self.assertEqual(sctp.PTYPE_IPV6, res6[3])
|
||||||
eq_(sctp.PTYPE_COOKIE_PRESERVE, res6[4])
|
self.assertEqual(sctp.PTYPE_COOKIE_PRESERVE, res6[4])
|
||||||
eq_(sctp.PTYPE_ECN, res6[5])
|
self.assertEqual(sctp.PTYPE_ECN, res6[5])
|
||||||
eq_(sctp.PTYPE_HOST_ADDR, res6[6])
|
self.assertEqual(sctp.PTYPE_HOST_ADDR, res6[6])
|
||||||
|
|
||||||
def test_serialize_with_init_ack(self):
|
def test_serialize_with_init_ack(self):
|
||||||
self.setUp_with_init_ack()
|
self.setUp_with_init_ack()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_init_ack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_init_ack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_init_ack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_init_ack.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.init_tag, res[3])
|
self.assertEqual(self.init_tag, res[3])
|
||||||
eq_(self.a_rwnd, res[4])
|
self.assertEqual(self.a_rwnd, res[4])
|
||||||
eq_(self.os, res[5])
|
self.assertEqual(self.os, res[5])
|
||||||
eq_(self.mis, res[6])
|
self.assertEqual(self.mis, res[6])
|
||||||
eq_(self.i_tsn, res[7])
|
self.assertEqual(self.i_tsn, res[7])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_init_ack._MIN_LEN:]
|
buf = buf[sctp.chunk_init_ack._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.param_state_cookie._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.param_state_cookie._PACK_STR, buf)
|
||||||
eq_(sctp.param_state_cookie.param_type(), res1[0])
|
self.assertEqual(sctp.param_state_cookie.param_type(), res1[0])
|
||||||
eq_(7, res1[1])
|
self.assertEqual(7, res1[1])
|
||||||
eq_(b'\x01\x02\x03',
|
self.assertEqual(b'\x01\x02\x03',
|
||||||
buf[sctp.param_state_cookie._MIN_LEN:
|
buf[sctp.param_state_cookie._MIN_LEN:
|
||||||
sctp.param_state_cookie._MIN_LEN + 3])
|
sctp.param_state_cookie._MIN_LEN + 3])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res2 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
res2 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
||||||
eq_(sctp.param_ipv4.param_type(), res2[0])
|
self.assertEqual(sctp.param_ipv4.param_type(), res2[0])
|
||||||
eq_(8, res2[1])
|
self.assertEqual(8, res2[1])
|
||||||
eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
|
self.assertEqual('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||||
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res3 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
res3 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
||||||
eq_(sctp.param_ipv6.param_type(), res3[0])
|
self.assertEqual(sctp.param_ipv6.param_type(), res3[0])
|
||||||
eq_(20, res3[1])
|
self.assertEqual(20, res3[1])
|
||||||
eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
self.assertEqual('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
||||||
buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
|
buf[sctp.param_ipv6._MIN_LEN:sctp.param_ipv6._MIN_LEN + 16]))
|
||||||
|
|
||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res4 = struct.unpack_from(
|
res4 = struct.unpack_from(
|
||||||
sctp.param_unrecognized_param._PACK_STR, buf)
|
sctp.param_unrecognized_param._PACK_STR, buf)
|
||||||
eq_(sctp.param_unrecognized_param.param_type(), res4[0])
|
self.assertEqual(sctp.param_unrecognized_param.param_type(), res4[0])
|
||||||
eq_(8, res4[1])
|
self.assertEqual(8, res4[1])
|
||||||
eq_(b'\xff\xff\x00\x04',
|
self.assertEqual(b'\xff\xff\x00\x04',
|
||||||
buf[sctp.param_unrecognized_param._MIN_LEN:
|
buf[sctp.param_unrecognized_param._MIN_LEN:
|
||||||
sctp.param_unrecognized_param._MIN_LEN + 4])
|
sctp.param_unrecognized_param._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res5 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
res5 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
||||||
eq_(sctp.param_ecn.param_type(), res5[0])
|
self.assertEqual(sctp.param_ecn.param_type(), res5[0])
|
||||||
eq_(4, res5[1])
|
self.assertEqual(4, res5[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res6 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
res6 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
||||||
eq_(sctp.param_host_addr.param_type(), res6[0])
|
self.assertEqual(sctp.param_host_addr.param_type(), res6[0])
|
||||||
eq_(14, res6[1])
|
self.assertEqual(14, res6[1])
|
||||||
eq_(b'test host\x00',
|
self.assertEqual(b'test host\x00',
|
||||||
buf[sctp.param_host_addr._MIN_LEN:
|
buf[sctp.param_host_addr._MIN_LEN:
|
||||||
sctp.param_host_addr._MIN_LEN + 10])
|
sctp.param_host_addr._MIN_LEN + 10])
|
||||||
|
|
||||||
@ -825,13 +823,13 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_sack()
|
self.setUp_with_sack()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_sack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_sack.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.tsn_ack, res[3])
|
self.assertEqual(self.tsn_ack, res[3])
|
||||||
eq_(self.a_rwnd, res[4])
|
self.assertEqual(self.a_rwnd, res[4])
|
||||||
eq_(self.gapack_num, res[5])
|
self.assertEqual(self.gapack_num, res[5])
|
||||||
eq_(self.duptsn_num, res[6])
|
self.assertEqual(self.duptsn_num, res[6])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_sack._MIN_LEN:]
|
buf = buf[sctp.chunk_sack._MIN_LEN:]
|
||||||
gapacks = []
|
gapacks = []
|
||||||
@ -847,22 +845,22 @@ class Test_sctp(unittest.TestCase):
|
|||||||
sctp.chunk_sack._DUPTSN_STR, buf)
|
sctp.chunk_sack._DUPTSN_STR, buf)
|
||||||
duptsns.append(duptsn)
|
duptsns.append(duptsn)
|
||||||
buf = buf[sctp.chunk_sack._DUPTSN_LEN:]
|
buf = buf[sctp.chunk_sack._DUPTSN_LEN:]
|
||||||
eq_(self.gapacks, gapacks)
|
self.assertEqual(self.gapacks, gapacks)
|
||||||
eq_(self.duptsns, duptsns)
|
self.assertEqual(self.duptsns, duptsns)
|
||||||
|
|
||||||
def test_serialize_with_heartbeat(self):
|
def test_serialize_with_heartbeat(self):
|
||||||
self.setUp_with_heartbeat()
|
self.setUp_with_heartbeat()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_heartbeat._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_heartbeat._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_heartbeat.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_heartbeat.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_heartbeat._MIN_LEN:]
|
buf = buf[sctp.chunk_heartbeat._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
||||||
eq_(sctp.param_heartbeat.param_type(), res1[0])
|
self.assertEqual(sctp.param_heartbeat.param_type(), res1[0])
|
||||||
eq_(8, res1[1])
|
self.assertEqual(8, res1[1])
|
||||||
eq_(b'\x01\x02\x03\x04',
|
self.assertEqual(b'\x01\x02\x03\x04',
|
||||||
buf[sctp.param_heartbeat._MIN_LEN:
|
buf[sctp.param_heartbeat._MIN_LEN:
|
||||||
sctp.param_heartbeat._MIN_LEN + 4])
|
sctp.param_heartbeat._MIN_LEN + 4])
|
||||||
|
|
||||||
@ -870,15 +868,15 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_heartbeat_ack()
|
self.setUp_with_heartbeat_ack()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_heartbeat_ack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_heartbeat_ack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_heartbeat_ack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_heartbeat_ack.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_heartbeat_ack._MIN_LEN:]
|
buf = buf[sctp.chunk_heartbeat_ack._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
||||||
eq_(sctp.param_heartbeat.param_type(), res1[0])
|
self.assertEqual(sctp.param_heartbeat.param_type(), res1[0])
|
||||||
eq_(12, res1[1])
|
self.assertEqual(12, res1[1])
|
||||||
eq_(b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88',
|
self.assertEqual(b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88',
|
||||||
buf[sctp.param_heartbeat._MIN_LEN:
|
buf[sctp.param_heartbeat._MIN_LEN:
|
||||||
sctp.param_heartbeat._MIN_LEN + 8])
|
sctp.param_heartbeat._MIN_LEN + 8])
|
||||||
|
|
||||||
@ -886,50 +884,50 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_abort()
|
self.setUp_with_abort()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_abort._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_abort._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_abort.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_abort.chunk_type(), res[0])
|
||||||
flags = self.tflag << 0
|
flags = self.tflag << 0
|
||||||
eq_(flags, res[1])
|
self.assertEqual(flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_abort._MIN_LEN:]
|
buf = buf[sctp.chunk_abort._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
||||||
eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
self.assertEqual(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||||
eq_(8, res1[1])
|
self.assertEqual(8, res1[1])
|
||||||
eq_(4096, res1[2])
|
self.assertEqual(4096, res1[2])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_missing_param.cause_code(), res2[0])
|
self.assertEqual(sctp.cause_missing_param.cause_code(), res2[0])
|
||||||
eq_(16, res2[1])
|
self.assertEqual(16, res2[1])
|
||||||
eq_(4, res2[2])
|
self.assertEqual(4, res2[2])
|
||||||
types = []
|
types = []
|
||||||
for count in range(4):
|
for count in range(4):
|
||||||
(tmp, ) = struct.unpack_from(
|
(tmp, ) = struct.unpack_from(
|
||||||
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
||||||
types.append(tmp)
|
types.append(tmp)
|
||||||
eq_(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
|
self.assertEqual(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
|
||||||
sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
|
sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
|
||||||
str(types))
|
str(types))
|
||||||
|
|
||||||
buf = buf[16:]
|
buf = buf[16:]
|
||||||
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
||||||
eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
|
self.assertEqual(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||||
eq_(8, res3[1])
|
self.assertEqual(8, res3[1])
|
||||||
eq_(b'\x00\x00\x13\x88',
|
self.assertEqual(b'\x00\x00\x13\x88',
|
||||||
buf[sctp.cause_stale_cookie._MIN_LEN:
|
buf[sctp.cause_stale_cookie._MIN_LEN:
|
||||||
sctp.cause_stale_cookie._MIN_LEN + 4])
|
sctp.cause_stale_cookie._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
||||||
eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
|
self.assertEqual(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||||
eq_(4, res4[1])
|
self.assertEqual(4, res4[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res5 = struct.unpack_from(
|
res5 = struct.unpack_from(
|
||||||
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
self.assertEqual(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||||
eq_(20, res5[1])
|
self.assertEqual(20, res5[1])
|
||||||
eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
self.assertEqual(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||||
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
||||||
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
||||||
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
||||||
@ -937,64 +935,64 @@ class Test_sctp(unittest.TestCase):
|
|||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res6 = struct.unpack_from(
|
res6 = struct.unpack_from(
|
||||||
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
self.assertEqual(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||||
eq_(8, res6[1])
|
self.assertEqual(8, res6[1])
|
||||||
eq_(b'\xff\x00\x00\x04',
|
self.assertEqual(b'\xff\x00\x00\x04',
|
||||||
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
||||||
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_invalid_param.cause_code(), res7[0])
|
self.assertEqual(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||||
eq_(4, res7[1])
|
self.assertEqual(4, res7[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res8 = struct.unpack_from(
|
res8 = struct.unpack_from(
|
||||||
sctp.cause_unrecognized_param._PACK_STR, buf)
|
sctp.cause_unrecognized_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
self.assertEqual(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||||
eq_(8, res8[1])
|
self.assertEqual(8, res8[1])
|
||||||
eq_(b'\xff\xff\x00\x04',
|
self.assertEqual(b'\xff\xff\x00\x04',
|
||||||
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
||||||
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
||||||
eq_(sctp.cause_no_userdata.cause_code(), res9[0])
|
self.assertEqual(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||||
eq_(8, res9[1])
|
self.assertEqual(8, res9[1])
|
||||||
eq_(b'\x00\x01\xe2\x40',
|
self.assertEqual(b'\x00\x01\xe2\x40',
|
||||||
buf[sctp.cause_no_userdata._MIN_LEN:
|
buf[sctp.cause_no_userdata._MIN_LEN:
|
||||||
sctp.cause_no_userdata._MIN_LEN + 4])
|
sctp.cause_no_userdata._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res10 = struct.unpack_from(
|
res10 = struct.unpack_from(
|
||||||
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
||||||
eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
self.assertEqual(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||||
eq_(4, res10[1])
|
self.assertEqual(4, res10[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res11 = struct.unpack_from(
|
res11 = struct.unpack_from(
|
||||||
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
||||||
eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
self.assertEqual(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||||
eq_(12, res11[1])
|
self.assertEqual(12, res11[1])
|
||||||
eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
self.assertEqual(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||||
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
||||||
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
||||||
|
|
||||||
buf = buf[12:]
|
buf = buf[12:]
|
||||||
res12 = struct.unpack_from(
|
res12 = struct.unpack_from(
|
||||||
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
||||||
eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
self.assertEqual(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||||
eq_(19, res12[1])
|
self.assertEqual(19, res12[1])
|
||||||
eq_(b'Key Interrupt.\x00',
|
self.assertEqual(b'Key Interrupt.\x00',
|
||||||
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
||||||
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
||||||
|
|
||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res13 = struct.unpack_from(
|
res13 = struct.unpack_from(
|
||||||
sctp.cause_protocol_violation._PACK_STR, buf)
|
sctp.cause_protocol_violation._PACK_STR, buf)
|
||||||
eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
|
self.assertEqual(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||||
eq_(20, res13[1])
|
self.assertEqual(20, res13[1])
|
||||||
eq_(b'Unknown reason.\x00',
|
self.assertEqual(b'Unknown reason.\x00',
|
||||||
buf[sctp.cause_protocol_violation._MIN_LEN:
|
buf[sctp.cause_protocol_violation._MIN_LEN:
|
||||||
sctp.cause_protocol_violation._MIN_LEN + 16])
|
sctp.cause_protocol_violation._MIN_LEN + 16])
|
||||||
|
|
||||||
@ -1002,66 +1000,66 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_shutdown()
|
self.setUp_with_shutdown()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_shutdown._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_shutdown._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_shutdown.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_shutdown.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.tsn_ack, res[3])
|
self.assertEqual(self.tsn_ack, res[3])
|
||||||
|
|
||||||
def test_serialize_with_shutdown_ack(self):
|
def test_serialize_with_shutdown_ack(self):
|
||||||
self.setUp_with_shutdown_ack()
|
self.setUp_with_shutdown_ack()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_shutdown_ack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_shutdown_ack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_shutdown_ack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_shutdown_ack.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
def test_serialize_with_error(self):
|
def test_serialize_with_error(self):
|
||||||
self.setUp_with_error()
|
self.setUp_with_error()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_error._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_error._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_error.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_error.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
buf = buf[sctp.chunk_error._MIN_LEN:]
|
buf = buf[sctp.chunk_error._MIN_LEN:]
|
||||||
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
||||||
eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
self.assertEqual(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||||
eq_(8, res1[1])
|
self.assertEqual(8, res1[1])
|
||||||
eq_(4096, res1[2])
|
self.assertEqual(4096, res1[2])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_missing_param.cause_code(), res2[0])
|
self.assertEqual(sctp.cause_missing_param.cause_code(), res2[0])
|
||||||
eq_(16, res2[1])
|
self.assertEqual(16, res2[1])
|
||||||
eq_(4, res2[2])
|
self.assertEqual(4, res2[2])
|
||||||
types = []
|
types = []
|
||||||
for count in range(4):
|
for count in range(4):
|
||||||
(tmp, ) = struct.unpack_from(
|
(tmp, ) = struct.unpack_from(
|
||||||
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
||||||
types.append(tmp)
|
types.append(tmp)
|
||||||
eq_(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
|
self.assertEqual(str([sctp.PTYPE_IPV4, sctp.PTYPE_IPV6,
|
||||||
sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
|
sctp.PTYPE_COOKIE_PRESERVE, sctp.PTYPE_HOST_ADDR]),
|
||||||
str(types))
|
str(types))
|
||||||
|
|
||||||
buf = buf[16:]
|
buf = buf[16:]
|
||||||
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
||||||
eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
|
self.assertEqual(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||||
eq_(8, res3[1])
|
self.assertEqual(8, res3[1])
|
||||||
eq_(b'\x00\x00\x13\x88',
|
self.assertEqual(b'\x00\x00\x13\x88',
|
||||||
buf[sctp.cause_stale_cookie._MIN_LEN:
|
buf[sctp.cause_stale_cookie._MIN_LEN:
|
||||||
sctp.cause_stale_cookie._MIN_LEN + 4])
|
sctp.cause_stale_cookie._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
||||||
eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
|
self.assertEqual(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||||
eq_(4, res4[1])
|
self.assertEqual(4, res4[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res5 = struct.unpack_from(
|
res5 = struct.unpack_from(
|
||||||
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
self.assertEqual(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||||
eq_(20, res5[1])
|
self.assertEqual(20, res5[1])
|
||||||
eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
self.assertEqual(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||||
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
||||||
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
||||||
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
||||||
@ -1069,64 +1067,64 @@ class Test_sctp(unittest.TestCase):
|
|||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res6 = struct.unpack_from(
|
res6 = struct.unpack_from(
|
||||||
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
self.assertEqual(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||||
eq_(8, res6[1])
|
self.assertEqual(8, res6[1])
|
||||||
eq_(b'\xff\x00\x00\x04',
|
self.assertEqual(b'\xff\x00\x00\x04',
|
||||||
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
||||||
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_invalid_param.cause_code(), res7[0])
|
self.assertEqual(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||||
eq_(4, res7[1])
|
self.assertEqual(4, res7[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res8 = struct.unpack_from(
|
res8 = struct.unpack_from(
|
||||||
sctp.cause_unrecognized_param._PACK_STR, buf)
|
sctp.cause_unrecognized_param._PACK_STR, buf)
|
||||||
eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
self.assertEqual(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||||
eq_(8, res8[1])
|
self.assertEqual(8, res8[1])
|
||||||
eq_(b'\xff\xff\x00\x04',
|
self.assertEqual(b'\xff\xff\x00\x04',
|
||||||
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
||||||
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
||||||
eq_(sctp.cause_no_userdata.cause_code(), res9[0])
|
self.assertEqual(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||||
eq_(8, res9[1])
|
self.assertEqual(8, res9[1])
|
||||||
eq_(b'\x00\x01\xe2\x40',
|
self.assertEqual(b'\x00\x01\xe2\x40',
|
||||||
buf[sctp.cause_no_userdata._MIN_LEN:
|
buf[sctp.cause_no_userdata._MIN_LEN:
|
||||||
sctp.cause_no_userdata._MIN_LEN + 4])
|
sctp.cause_no_userdata._MIN_LEN + 4])
|
||||||
|
|
||||||
buf = buf[8:]
|
buf = buf[8:]
|
||||||
res10 = struct.unpack_from(
|
res10 = struct.unpack_from(
|
||||||
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
||||||
eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
self.assertEqual(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||||
eq_(4, res10[1])
|
self.assertEqual(4, res10[1])
|
||||||
|
|
||||||
buf = buf[4:]
|
buf = buf[4:]
|
||||||
res11 = struct.unpack_from(
|
res11 = struct.unpack_from(
|
||||||
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
||||||
eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
self.assertEqual(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||||
eq_(12, res11[1])
|
self.assertEqual(12, res11[1])
|
||||||
eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
self.assertEqual(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||||
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
||||||
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
||||||
|
|
||||||
buf = buf[12:]
|
buf = buf[12:]
|
||||||
res12 = struct.unpack_from(
|
res12 = struct.unpack_from(
|
||||||
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
||||||
eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
self.assertEqual(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||||
eq_(19, res12[1])
|
self.assertEqual(19, res12[1])
|
||||||
eq_(b'Key Interrupt.\x00',
|
self.assertEqual(b'Key Interrupt.\x00',
|
||||||
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
||||||
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
||||||
|
|
||||||
buf = buf[20:]
|
buf = buf[20:]
|
||||||
res13 = struct.unpack_from(
|
res13 = struct.unpack_from(
|
||||||
sctp.cause_protocol_violation._PACK_STR, buf)
|
sctp.cause_protocol_violation._PACK_STR, buf)
|
||||||
eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
|
self.assertEqual(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||||
eq_(20, res13[1])
|
self.assertEqual(20, res13[1])
|
||||||
eq_(b'Unknown reason.\x00',
|
self.assertEqual(b'Unknown reason.\x00',
|
||||||
buf[sctp.cause_protocol_violation._MIN_LEN:
|
buf[sctp.cause_protocol_violation._MIN_LEN:
|
||||||
sctp.cause_protocol_violation._MIN_LEN + 16])
|
sctp.cause_protocol_violation._MIN_LEN + 16])
|
||||||
|
|
||||||
@ -1134,10 +1132,10 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_cookie_echo()
|
self.setUp_with_cookie_echo()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_cookie_echo._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_cookie_echo._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_cookie_echo.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_cookie_echo.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.cookie,
|
self.assertEqual(self.cookie,
|
||||||
buf[sctp.chunk_cookie_echo._MIN_LEN:
|
buf[sctp.chunk_cookie_echo._MIN_LEN:
|
||||||
sctp.chunk_cookie_echo._MIN_LEN + 4])
|
sctp.chunk_cookie_echo._MIN_LEN + 4])
|
||||||
|
|
||||||
@ -1145,81 +1143,81 @@ class Test_sctp(unittest.TestCase):
|
|||||||
self.setUp_with_cookie_ack()
|
self.setUp_with_cookie_ack()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_cookie_ack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_cookie_ack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_cookie_ack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_cookie_ack.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
def test_serialize_with_ecn_echo(self):
|
def test_serialize_with_ecn_echo(self):
|
||||||
self.setUp_with_ecn_echo()
|
self.setUp_with_ecn_echo()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_ecn_echo._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_ecn_echo._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_ecn_echo.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_ecn_echo.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.low_tsn, res[3])
|
self.assertEqual(self.low_tsn, res[3])
|
||||||
|
|
||||||
def test_serialize_with_cwr(self):
|
def test_serialize_with_cwr(self):
|
||||||
self.setUp_with_cwr()
|
self.setUp_with_cwr()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_cwr._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_cwr._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_cwr.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_cwr.chunk_type(), res[0])
|
||||||
eq_(self.flags, res[1])
|
self.assertEqual(self.flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
eq_(self.low_tsn, res[3])
|
self.assertEqual(self.low_tsn, res[3])
|
||||||
|
|
||||||
def test_serialize_with_shutdown_complete(self):
|
def test_serialize_with_shutdown_complete(self):
|
||||||
self.setUp_with_shutdown_complete()
|
self.setUp_with_shutdown_complete()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(
|
res = struct.unpack_from(
|
||||||
sctp.chunk_shutdown_complete._PACK_STR, buf)
|
sctp.chunk_shutdown_complete._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_shutdown_complete.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_shutdown_complete.chunk_type(), res[0])
|
||||||
flags = self.tflag << 0
|
flags = self.tflag << 0
|
||||||
eq_(flags, res[1])
|
self.assertEqual(flags, res[1])
|
||||||
eq_(self.length, res[2])
|
self.assertEqual(self.length, res[2])
|
||||||
|
|
||||||
def test_serialize_with_multi_chunks(self):
|
def test_serialize_with_multi_chunks(self):
|
||||||
self.setUp_with_multi_chunks()
|
self.setUp_with_multi_chunks()
|
||||||
buf = self._test_serialize()
|
buf = self._test_serialize()
|
||||||
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_sack.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_sack.chunk_type(), res[0])
|
||||||
eq_(self.s_flags, res[1])
|
self.assertEqual(self.s_flags, res[1])
|
||||||
eq_(self.s_length, res[2])
|
self.assertEqual(self.s_length, res[2])
|
||||||
eq_(self.s_tsn_ack, res[3])
|
self.assertEqual(self.s_tsn_ack, res[3])
|
||||||
eq_(self.s_a_rwnd, res[4])
|
self.assertEqual(self.s_a_rwnd, res[4])
|
||||||
eq_(self.s_gapack_num, res[5])
|
self.assertEqual(self.s_gapack_num, res[5])
|
||||||
eq_(self.s_duptsn_num, res[6])
|
self.assertEqual(self.s_duptsn_num, res[6])
|
||||||
|
|
||||||
buf = buf[self.s_length:]
|
buf = buf[self.s_length:]
|
||||||
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_data.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_data.chunk_type(), res[0])
|
||||||
d1_flags = (
|
d1_flags = (
|
||||||
(self.d1_unordered << 2) |
|
(self.d1_unordered << 2) |
|
||||||
(self.d1_begin << 1) |
|
(self.d1_begin << 1) |
|
||||||
(self.d1_end << 0))
|
(self.d1_end << 0))
|
||||||
eq_(d1_flags, res[1])
|
self.assertEqual(d1_flags, res[1])
|
||||||
eq_(self.d1_length, res[2])
|
self.assertEqual(self.d1_length, res[2])
|
||||||
eq_(self.d1_tsn, res[3])
|
self.assertEqual(self.d1_tsn, res[3])
|
||||||
eq_(self.d1_sid, res[4])
|
self.assertEqual(self.d1_sid, res[4])
|
||||||
eq_(self.d1_seq, res[5])
|
self.assertEqual(self.d1_seq, res[5])
|
||||||
eq_(self.d1_payload_id, res[6])
|
self.assertEqual(self.d1_payload_id, res[6])
|
||||||
eq_(self.d1_payload_data,
|
self.assertEqual(self.d1_payload_data,
|
||||||
buf[sctp.chunk_data._MIN_LEN:
|
buf[sctp.chunk_data._MIN_LEN:
|
||||||
sctp.chunk_data._MIN_LEN + 10])
|
sctp.chunk_data._MIN_LEN + 10])
|
||||||
|
|
||||||
buf = buf[self.d1_length:]
|
buf = buf[self.d1_length:]
|
||||||
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
res = struct.unpack_from(sctp.chunk_data._PACK_STR, buf)
|
||||||
eq_(sctp.chunk_data.chunk_type(), res[0])
|
self.assertEqual(sctp.chunk_data.chunk_type(), res[0])
|
||||||
d2_flags = (
|
d2_flags = (
|
||||||
(self.d2_unordered << 2) |
|
(self.d2_unordered << 2) |
|
||||||
(self.d2_begin << 1) |
|
(self.d2_begin << 1) |
|
||||||
(self.d2_end << 0))
|
(self.d2_end << 0))
|
||||||
eq_(d2_flags, res[1])
|
self.assertEqual(d2_flags, res[1])
|
||||||
eq_(self.d2_length, res[2])
|
self.assertEqual(self.d2_length, res[2])
|
||||||
eq_(self.d2_tsn, res[3])
|
self.assertEqual(self.d2_tsn, res[3])
|
||||||
eq_(self.d2_sid, res[4])
|
self.assertEqual(self.d2_sid, res[4])
|
||||||
eq_(self.d2_seq, res[5])
|
self.assertEqual(self.d2_seq, res[5])
|
||||||
eq_(self.d2_payload_id, res[6])
|
self.assertEqual(self.d2_payload_id, res[6])
|
||||||
eq_(self.d2_payload_data,
|
self.assertEqual(self.d2_payload_data,
|
||||||
buf[sctp.chunk_data._MIN_LEN:
|
buf[sctp.chunk_data._MIN_LEN:
|
||||||
sctp.chunk_data._MIN_LEN + 10])
|
sctp.chunk_data._MIN_LEN + 10])
|
||||||
|
|
||||||
@ -1231,16 +1229,16 @@ class Test_sctp(unittest.TestCase):
|
|||||||
pkt = eth / ip4 / self.sc
|
pkt = eth / ip4 / self.sc
|
||||||
|
|
||||||
eth = pkt.get_protocol(ethernet.ethernet)
|
eth = pkt.get_protocol(ethernet.ethernet)
|
||||||
ok_(eth)
|
self.assertTrue(eth)
|
||||||
eq_(eth.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(eth.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
ip4 = pkt.get_protocol(ipv4.ipv4)
|
ip4 = pkt.get_protocol(ipv4.ipv4)
|
||||||
ok_(ip4)
|
self.assertTrue(ip4)
|
||||||
eq_(ip4.proto, inet.IPPROTO_SCTP)
|
self.assertEqual(ip4.proto, inet.IPPROTO_SCTP)
|
||||||
|
|
||||||
sc = pkt.get_protocol(sctp.sctp)
|
sc = pkt.get_protocol(sctp.sctp)
|
||||||
ok_(sc)
|
self.assertTrue(sc)
|
||||||
eq_(sc, self.sc)
|
self.assertEqual(sc, self.sc)
|
||||||
|
|
||||||
def test_build_sctp_with_data(self):
|
def test_build_sctp_with_data(self):
|
||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
@ -1317,8 +1315,8 @@ class Test_sctp(unittest.TestCase):
|
|||||||
if k in sctp_values])
|
if k in sctp_values])
|
||||||
sctp_str = '%s(%s)' % (sctp.sctp.__name__, _sctp_str)
|
sctp_str = '%s(%s)' % (sctp.sctp.__name__, _sctp_str)
|
||||||
|
|
||||||
eq_(str(self.sc), sctp_str)
|
self.assertEqual(str(self.sc), sctp_str)
|
||||||
eq_(repr(self.sc), sctp_str)
|
self.assertEqual(repr(self.sc), sctp_str)
|
||||||
|
|
||||||
def test_to_string_with_data(self):
|
def test_to_string_with_data(self):
|
||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
@ -1387,7 +1385,7 @@ class Test_sctp(unittest.TestCase):
|
|||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.sc.to_jsondict()
|
jsondict = self.sc.to_jsondict()
|
||||||
sc = sctp.sctp.from_jsondict(jsondict['sctp'])
|
sc = sctp.sctp.from_jsondict(jsondict['sctp'])
|
||||||
eq_(str(self.sc), str(sc))
|
self.assertEqual(str(self.sc), str(sc))
|
||||||
|
|
||||||
def test_json_with_data(self):
|
def test_json_with_data(self):
|
||||||
self.setUp_with_data()
|
self.setUp_with_data()
|
||||||
|
@ -20,7 +20,6 @@ import logging
|
|||||||
from struct import pack, unpack_from
|
from struct import pack, unpack_from
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import ok_, eq_, raises
|
|
||||||
from os_ken.ofproto import ether
|
from os_ken.ofproto import ether
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
from os_ken.lib.packet.packet import Packet
|
from os_ken.lib.packet.packet import Packet
|
||||||
@ -303,55 +302,55 @@ class Test_lacp(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.subtype, self.l._subtype)
|
self.assertEqual(self.subtype, self.l._subtype)
|
||||||
eq_(self.version, self.l.version)
|
self.assertEqual(self.version, self.l.version)
|
||||||
eq_(self.actor_tag, self.l._actor_tag)
|
self.assertEqual(self.actor_tag, self.l._actor_tag)
|
||||||
eq_(self.actor_length, self.l._actor_length)
|
self.assertEqual(self.actor_length, self.l._actor_length)
|
||||||
eq_(self.actor_system_priority, self.l.actor_system_priority)
|
self.assertEqual(self.actor_system_priority, self.l.actor_system_priority)
|
||||||
eq_(self.actor_system, self.l.actor_system)
|
self.assertEqual(self.actor_system, self.l.actor_system)
|
||||||
eq_(self.actor_key, self.l.actor_key)
|
self.assertEqual(self.actor_key, self.l.actor_key)
|
||||||
eq_(self.actor_port_priority, self.l.actor_port_priority)
|
self.assertEqual(self.actor_port_priority, self.l.actor_port_priority)
|
||||||
eq_(self.actor_port, self.l.actor_port)
|
self.assertEqual(self.actor_port, self.l.actor_port)
|
||||||
eq_(self.actor_state_activity, self.l.actor_state_activity)
|
self.assertEqual(self.actor_state_activity, self.l.actor_state_activity)
|
||||||
eq_(self.actor_state_timeout, self.l.actor_state_timeout)
|
self.assertEqual(self.actor_state_timeout, self.l.actor_state_timeout)
|
||||||
eq_(self.actor_state_aggregation,
|
self.assertEqual(self.actor_state_aggregation,
|
||||||
self.l.actor_state_aggregation)
|
self.l.actor_state_aggregation)
|
||||||
eq_(self.actor_state_synchronization,
|
self.assertEqual(self.actor_state_synchronization,
|
||||||
self.l.actor_state_synchronization)
|
self.l.actor_state_synchronization)
|
||||||
eq_(self.actor_state_collecting,
|
self.assertEqual(self.actor_state_collecting,
|
||||||
self.l.actor_state_collecting)
|
self.l.actor_state_collecting)
|
||||||
eq_(self.actor_state_distributing,
|
self.assertEqual(self.actor_state_distributing,
|
||||||
self.l.actor_state_distributing)
|
self.l.actor_state_distributing)
|
||||||
eq_(self.actor_state_defaulted, self.l.actor_state_defaulted)
|
self.assertEqual(self.actor_state_defaulted, self.l.actor_state_defaulted)
|
||||||
eq_(self.actor_state_expired, self.l.actor_state_expired)
|
self.assertEqual(self.actor_state_expired, self.l.actor_state_expired)
|
||||||
eq_(self.actor_state, self.l._actor_state)
|
self.assertEqual(self.actor_state, self.l._actor_state)
|
||||||
eq_(self.partner_tag, self.l._partner_tag)
|
self.assertEqual(self.partner_tag, self.l._partner_tag)
|
||||||
eq_(self.partner_length, self.l._partner_length)
|
self.assertEqual(self.partner_length, self.l._partner_length)
|
||||||
eq_(self.partner_system_priority,
|
self.assertEqual(self.partner_system_priority,
|
||||||
self.l.partner_system_priority)
|
self.l.partner_system_priority)
|
||||||
eq_(self.partner_system, self.l.partner_system)
|
self.assertEqual(self.partner_system, self.l.partner_system)
|
||||||
eq_(self.partner_key, self.l.partner_key)
|
self.assertEqual(self.partner_key, self.l.partner_key)
|
||||||
eq_(self.partner_port_priority, self.l.partner_port_priority)
|
self.assertEqual(self.partner_port_priority, self.l.partner_port_priority)
|
||||||
eq_(self.partner_port, self.l.partner_port)
|
self.assertEqual(self.partner_port, self.l.partner_port)
|
||||||
eq_(self.partner_state_activity, self.l.partner_state_activity)
|
self.assertEqual(self.partner_state_activity, self.l.partner_state_activity)
|
||||||
eq_(self.partner_state_timeout, self.l.partner_state_timeout)
|
self.assertEqual(self.partner_state_timeout, self.l.partner_state_timeout)
|
||||||
eq_(self.partner_state_aggregation,
|
self.assertEqual(self.partner_state_aggregation,
|
||||||
self.l.partner_state_aggregation)
|
self.l.partner_state_aggregation)
|
||||||
eq_(self.partner_state_synchronization,
|
self.assertEqual(self.partner_state_synchronization,
|
||||||
self.l.partner_state_synchronization)
|
self.l.partner_state_synchronization)
|
||||||
eq_(self.partner_state_collecting,
|
self.assertEqual(self.partner_state_collecting,
|
||||||
self.l.partner_state_collecting)
|
self.l.partner_state_collecting)
|
||||||
eq_(self.partner_state_distributing,
|
self.assertEqual(self.partner_state_distributing,
|
||||||
self.l.partner_state_distributing)
|
self.l.partner_state_distributing)
|
||||||
eq_(self.partner_state_defaulted,
|
self.assertEqual(self.partner_state_defaulted,
|
||||||
self.l.partner_state_defaulted)
|
self.l.partner_state_defaulted)
|
||||||
eq_(self.partner_state_expired, self.l.partner_state_expired)
|
self.assertEqual(self.partner_state_expired, self.l.partner_state_expired)
|
||||||
eq_(self.partner_state, self.l._partner_state)
|
self.assertEqual(self.partner_state, self.l._partner_state)
|
||||||
eq_(self.collector_tag, self.l._collector_tag)
|
self.assertEqual(self.collector_tag, self.l._collector_tag)
|
||||||
eq_(self.collector_length, self.l._collector_length)
|
self.assertEqual(self.collector_length, self.l._collector_length)
|
||||||
eq_(self.collector_max_delay, self.l.collector_max_delay)
|
self.assertEqual(self.collector_max_delay, self.l.collector_max_delay)
|
||||||
eq_(self.terminator_tag, self.l._terminator_tag)
|
self.assertEqual(self.terminator_tag, self.l._terminator_tag)
|
||||||
eq_(self.terminator_length, self.l._terminator_length)
|
self.assertEqual(self.terminator_length, self.l._terminator_length)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
_res = self.l.parser(self.buf)
|
_res = self.l.parser(self.buf)
|
||||||
@ -360,49 +359,49 @@ class Test_lacp(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
res = _res
|
res = _res
|
||||||
|
|
||||||
eq_(res._subtype, self.subtype)
|
self.assertEqual(res._subtype, self.subtype)
|
||||||
eq_(res.version, self.version)
|
self.assertEqual(res.version, self.version)
|
||||||
eq_(res._actor_tag, self.actor_tag)
|
self.assertEqual(res._actor_tag, self.actor_tag)
|
||||||
eq_(res._actor_length, self.actor_length)
|
self.assertEqual(res._actor_length, self.actor_length)
|
||||||
eq_(res.actor_system_priority, self.actor_system_priority)
|
self.assertEqual(res.actor_system_priority, self.actor_system_priority)
|
||||||
eq_(res.actor_system, self.actor_system)
|
self.assertEqual(res.actor_system, self.actor_system)
|
||||||
eq_(res.actor_key, self.actor_key)
|
self.assertEqual(res.actor_key, self.actor_key)
|
||||||
eq_(res.actor_port_priority, self.actor_port_priority)
|
self.assertEqual(res.actor_port_priority, self.actor_port_priority)
|
||||||
eq_(res.actor_port, self.actor_port)
|
self.assertEqual(res.actor_port, self.actor_port)
|
||||||
eq_(res.actor_state_activity, self.actor_state_activity)
|
self.assertEqual(res.actor_state_activity, self.actor_state_activity)
|
||||||
eq_(res.actor_state_timeout, self.actor_state_timeout)
|
self.assertEqual(res.actor_state_timeout, self.actor_state_timeout)
|
||||||
eq_(res.actor_state_aggregation, self.actor_state_aggregation)
|
self.assertEqual(res.actor_state_aggregation, self.actor_state_aggregation)
|
||||||
eq_(res.actor_state_synchronization,
|
self.assertEqual(res.actor_state_synchronization,
|
||||||
self.actor_state_synchronization)
|
self.actor_state_synchronization)
|
||||||
eq_(res.actor_state_collecting, self.actor_state_collecting)
|
self.assertEqual(res.actor_state_collecting, self.actor_state_collecting)
|
||||||
eq_(res.actor_state_distributing, self.actor_state_distributing)
|
self.assertEqual(res.actor_state_distributing, self.actor_state_distributing)
|
||||||
eq_(res.actor_state_defaulted, self.actor_state_defaulted)
|
self.assertEqual(res.actor_state_defaulted, self.actor_state_defaulted)
|
||||||
eq_(res.actor_state_expired, self.actor_state_expired)
|
self.assertEqual(res.actor_state_expired, self.actor_state_expired)
|
||||||
eq_(res._actor_state, self.actor_state)
|
self.assertEqual(res._actor_state, self.actor_state)
|
||||||
eq_(res._partner_tag, self.partner_tag)
|
self.assertEqual(res._partner_tag, self.partner_tag)
|
||||||
eq_(res._partner_length, self.partner_length)
|
self.assertEqual(res._partner_length, self.partner_length)
|
||||||
eq_(res.partner_system_priority, self.partner_system_priority)
|
self.assertEqual(res.partner_system_priority, self.partner_system_priority)
|
||||||
eq_(res.partner_system, self.partner_system)
|
self.assertEqual(res.partner_system, self.partner_system)
|
||||||
eq_(res.partner_key, self.partner_key)
|
self.assertEqual(res.partner_key, self.partner_key)
|
||||||
eq_(res.partner_port_priority, self.partner_port_priority)
|
self.assertEqual(res.partner_port_priority, self.partner_port_priority)
|
||||||
eq_(res.partner_port, self.partner_port)
|
self.assertEqual(res.partner_port, self.partner_port)
|
||||||
eq_(res.partner_state_activity, self.partner_state_activity)
|
self.assertEqual(res.partner_state_activity, self.partner_state_activity)
|
||||||
eq_(res.partner_state_timeout, self.partner_state_timeout)
|
self.assertEqual(res.partner_state_timeout, self.partner_state_timeout)
|
||||||
eq_(res.partner_state_aggregation,
|
self.assertEqual(res.partner_state_aggregation,
|
||||||
self.partner_state_aggregation)
|
self.partner_state_aggregation)
|
||||||
eq_(res.partner_state_synchronization,
|
self.assertEqual(res.partner_state_synchronization,
|
||||||
self.partner_state_synchronization)
|
self.partner_state_synchronization)
|
||||||
eq_(res.partner_state_collecting, self.partner_state_collecting)
|
self.assertEqual(res.partner_state_collecting, self.partner_state_collecting)
|
||||||
eq_(res.partner_state_distributing,
|
self.assertEqual(res.partner_state_distributing,
|
||||||
self.partner_state_distributing)
|
self.partner_state_distributing)
|
||||||
eq_(res.partner_state_defaulted, self.partner_state_defaulted)
|
self.assertEqual(res.partner_state_defaulted, self.partner_state_defaulted)
|
||||||
eq_(res.partner_state_expired, self.partner_state_expired)
|
self.assertEqual(res.partner_state_expired, self.partner_state_expired)
|
||||||
eq_(res._partner_state, self.partner_state)
|
self.assertEqual(res._partner_state, self.partner_state)
|
||||||
eq_(res._collector_tag, self.collector_tag)
|
self.assertEqual(res._collector_tag, self.collector_tag)
|
||||||
eq_(res._collector_length, self.collector_length)
|
self.assertEqual(res._collector_length, self.collector_length)
|
||||||
eq_(res.collector_max_delay, self.collector_max_delay)
|
self.assertEqual(res.collector_max_delay, self.collector_max_delay)
|
||||||
eq_(res._terminator_tag, self.terminator_tag)
|
self.assertEqual(res._terminator_tag, self.terminator_tag)
|
||||||
eq_(res._terminator_length, self.terminator_length)
|
self.assertEqual(res._terminator_length, self.terminator_length)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -420,33 +419,33 @@ class Test_lacp(unittest.TestCase):
|
|||||||
offset += self.col_len
|
offset += self.col_len
|
||||||
trm_res = unpack_from(self.trm_fmt, buf, offset)
|
trm_res = unpack_from(self.trm_fmt, buf, offset)
|
||||||
|
|
||||||
eq_(head_res[0], self.subtype)
|
self.assertEqual(head_res[0], self.subtype)
|
||||||
eq_(head_res[1], self.version)
|
self.assertEqual(head_res[1], self.version)
|
||||||
|
|
||||||
eq_(act_res[0], self.actor_tag)
|
self.assertEqual(act_res[0], self.actor_tag)
|
||||||
eq_(act_res[1], self.actor_length)
|
self.assertEqual(act_res[1], self.actor_length)
|
||||||
eq_(act_res[2], self.actor_system_priority)
|
self.assertEqual(act_res[2], self.actor_system_priority)
|
||||||
eq_(act_res[3], addrconv.mac.text_to_bin(self.actor_system))
|
self.assertEqual(act_res[3], addrconv.mac.text_to_bin(self.actor_system))
|
||||||
eq_(act_res[4], self.actor_key)
|
self.assertEqual(act_res[4], self.actor_key)
|
||||||
eq_(act_res[5], self.actor_port_priority)
|
self.assertEqual(act_res[5], self.actor_port_priority)
|
||||||
eq_(act_res[6], self.actor_port)
|
self.assertEqual(act_res[6], self.actor_port)
|
||||||
eq_(act_res[7], self.actor_state)
|
self.assertEqual(act_res[7], self.actor_state)
|
||||||
|
|
||||||
eq_(prt_res[0], self.partner_tag)
|
self.assertEqual(prt_res[0], self.partner_tag)
|
||||||
eq_(prt_res[1], self.partner_length)
|
self.assertEqual(prt_res[1], self.partner_length)
|
||||||
eq_(prt_res[2], self.partner_system_priority)
|
self.assertEqual(prt_res[2], self.partner_system_priority)
|
||||||
eq_(prt_res[3], addrconv.mac.text_to_bin(self.partner_system))
|
self.assertEqual(prt_res[3], addrconv.mac.text_to_bin(self.partner_system))
|
||||||
eq_(prt_res[4], self.partner_key)
|
self.assertEqual(prt_res[4], self.partner_key)
|
||||||
eq_(prt_res[5], self.partner_port_priority)
|
self.assertEqual(prt_res[5], self.partner_port_priority)
|
||||||
eq_(prt_res[6], self.partner_port)
|
self.assertEqual(prt_res[6], self.partner_port)
|
||||||
eq_(prt_res[7], self.partner_state)
|
self.assertEqual(prt_res[7], self.partner_state)
|
||||||
|
|
||||||
eq_(col_res[0], self.collector_tag)
|
self.assertEqual(col_res[0], self.collector_tag)
|
||||||
eq_(col_res[1], self.collector_length)
|
self.assertEqual(col_res[1], self.collector_length)
|
||||||
eq_(col_res[2], self.collector_max_delay)
|
self.assertEqual(col_res[2], self.collector_max_delay)
|
||||||
|
|
||||||
eq_(trm_res[0], self.terminator_tag)
|
self.assertEqual(trm_res[0], self.terminator_tag)
|
||||||
eq_(trm_res[1], self.terminator_length)
|
self.assertEqual(trm_res[1], self.terminator_length)
|
||||||
|
|
||||||
def _build_lacp(self):
|
def _build_lacp(self):
|
||||||
ethertype = ether.ETH_TYPE_SLOW
|
ethertype = ether.ETH_TYPE_SLOW
|
||||||
@ -463,133 +462,152 @@ class Test_lacp(unittest.TestCase):
|
|||||||
p = self._build_lacp()
|
p = self._build_lacp()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_SLOW)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_SLOW)
|
||||||
|
|
||||||
l = self.find_protocol(p, "lacp")
|
l = self.find_protocol(p, "lacp")
|
||||||
ok_(l)
|
self.assertTrue(l)
|
||||||
|
|
||||||
eq_(l._subtype, self.subtype)
|
self.assertEqual(l._subtype, self.subtype)
|
||||||
eq_(l.version, self.version)
|
self.assertEqual(l.version, self.version)
|
||||||
eq_(l._actor_tag, self.actor_tag)
|
self.assertEqual(l._actor_tag, self.actor_tag)
|
||||||
eq_(l._actor_length, self.actor_length)
|
self.assertEqual(l._actor_length, self.actor_length)
|
||||||
eq_(l.actor_system_priority, self.actor_system_priority)
|
self.assertEqual(l.actor_system_priority, self.actor_system_priority)
|
||||||
eq_(l.actor_system, self.actor_system)
|
self.assertEqual(l.actor_system, self.actor_system)
|
||||||
eq_(l.actor_key, self.actor_key)
|
self.assertEqual(l.actor_key, self.actor_key)
|
||||||
eq_(l.actor_port_priority, self.actor_port_priority)
|
self.assertEqual(l.actor_port_priority, self.actor_port_priority)
|
||||||
eq_(l.actor_port, self.actor_port)
|
self.assertEqual(l.actor_port, self.actor_port)
|
||||||
eq_(l.actor_state_activity, self.actor_state_activity)
|
self.assertEqual(l.actor_state_activity, self.actor_state_activity)
|
||||||
eq_(l.actor_state_timeout, self.actor_state_timeout)
|
self.assertEqual(l.actor_state_timeout, self.actor_state_timeout)
|
||||||
eq_(l.actor_state_aggregation, self.actor_state_aggregation)
|
self.assertEqual(l.actor_state_aggregation, self.actor_state_aggregation)
|
||||||
eq_(l.actor_state_synchronization,
|
self.assertEqual(l.actor_state_synchronization,
|
||||||
self.actor_state_synchronization)
|
self.actor_state_synchronization)
|
||||||
eq_(l.actor_state_collecting, self.actor_state_collecting)
|
self.assertEqual(l.actor_state_collecting, self.actor_state_collecting)
|
||||||
eq_(l.actor_state_distributing, self.actor_state_distributing)
|
self.assertEqual(l.actor_state_distributing, self.actor_state_distributing)
|
||||||
eq_(l.actor_state_defaulted, self.actor_state_defaulted)
|
self.assertEqual(l.actor_state_defaulted, self.actor_state_defaulted)
|
||||||
eq_(l.actor_state_expired, self.actor_state_expired)
|
self.assertEqual(l.actor_state_expired, self.actor_state_expired)
|
||||||
eq_(l._actor_state, self.actor_state)
|
self.assertEqual(l._actor_state, self.actor_state)
|
||||||
eq_(l._partner_tag, self.partner_tag)
|
self.assertEqual(l._partner_tag, self.partner_tag)
|
||||||
eq_(l._partner_length, self.partner_length)
|
self.assertEqual(l._partner_length, self.partner_length)
|
||||||
eq_(l.partner_system_priority, self.partner_system_priority)
|
self.assertEqual(l.partner_system_priority, self.partner_system_priority)
|
||||||
eq_(l.partner_system, self.partner_system)
|
self.assertEqual(l.partner_system, self.partner_system)
|
||||||
eq_(l.partner_key, self.partner_key)
|
self.assertEqual(l.partner_key, self.partner_key)
|
||||||
eq_(l.partner_port_priority, self.partner_port_priority)
|
self.assertEqual(l.partner_port_priority, self.partner_port_priority)
|
||||||
eq_(l.partner_port, self.partner_port)
|
self.assertEqual(l.partner_port, self.partner_port)
|
||||||
eq_(l.partner_state_activity, self.partner_state_activity)
|
self.assertEqual(l.partner_state_activity, self.partner_state_activity)
|
||||||
eq_(l.partner_state_timeout, self.partner_state_timeout)
|
self.assertEqual(l.partner_state_timeout, self.partner_state_timeout)
|
||||||
eq_(l.partner_state_aggregation, self.partner_state_aggregation)
|
self.assertEqual(l.partner_state_aggregation, self.partner_state_aggregation)
|
||||||
eq_(l.partner_state_synchronization,
|
self.assertEqual(l.partner_state_synchronization,
|
||||||
self.partner_state_synchronization)
|
self.partner_state_synchronization)
|
||||||
eq_(l.partner_state_collecting, self.partner_state_collecting)
|
self.assertEqual(l.partner_state_collecting, self.partner_state_collecting)
|
||||||
eq_(l.partner_state_distributing,
|
self.assertEqual(l.partner_state_distributing,
|
||||||
self.partner_state_distributing)
|
self.partner_state_distributing)
|
||||||
eq_(l.partner_state_defaulted, self.partner_state_defaulted)
|
self.assertEqual(l.partner_state_defaulted, self.partner_state_defaulted)
|
||||||
eq_(l.partner_state_expired, self.partner_state_expired)
|
self.assertEqual(l.partner_state_expired, self.partner_state_expired)
|
||||||
eq_(l._partner_state, self.partner_state)
|
self.assertEqual(l._partner_state, self.partner_state)
|
||||||
eq_(l._collector_tag, self.collector_tag)
|
self.assertEqual(l._collector_tag, self.collector_tag)
|
||||||
eq_(l._collector_length, self.collector_length)
|
self.assertEqual(l._collector_length, self.collector_length)
|
||||||
eq_(l.collector_max_delay, self.collector_max_delay)
|
self.assertEqual(l.collector_max_delay, self.collector_max_delay)
|
||||||
eq_(l._terminator_tag, self.terminator_tag)
|
self.assertEqual(l._terminator_tag, self.terminator_tag)
|
||||||
eq_(l._terminator_length, self.terminator_length)
|
self.assertEqual(l._terminator_length, self.terminator_length)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_lacp(self):
|
def test_malformed_lacp(self):
|
||||||
m_short_buf = self.buf[1:self.length]
|
m_short_buf = self.buf[1:self.length]
|
||||||
slow.parser(m_short_buf)
|
self.assertRaises(Exception, slow.parser, m_short_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_subtype(self):
|
def test_invalid_subtype(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.subtype = 0xff
|
invalid_lacv.subtype = 0xff
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_version(self):
|
def test_invalid_version(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.version = 0xff
|
invalid_lacv.version = 0xff
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_tag(self):
|
def test_invalid_actor_tag(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.actor_tag = 0x04
|
invalid_lacv.actor_tag = 0x04
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_length(self):
|
def test_invalid_actor_length(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.actor_length = 50
|
invalid_lacv.actor_length = 50
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_tag(self):
|
def test_invalid_partner_tag(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.partner_tag = 0x01
|
invalid_lacv.partner_tag = 0x01
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_length(self):
|
def test_invalid_partner_length(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.partner_length = 0
|
invalid_lacv.partner_length = 0
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_collector_tag(self):
|
def test_invalid_collector_tag(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.collector_tag = 0x00
|
invalid_lacv.collector_tag = 0x00
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_collector_length(self):
|
def test_invalid_collector_length(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.collector_length = 20
|
invalid_lacv.collector_length = 20
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_terminator_tag(self):
|
def test_invalid_terminator_tag(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.terminator_tag = 0x04
|
invalid_lacv.terminator_tag = 0x04
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_terminator_length(self):
|
def test_invalid_terminator_length(self):
|
||||||
|
self.skipTest('This test needs to be refactored: "serialize" method '
|
||||||
|
'requires two input parameters that are not provided '
|
||||||
|
'here.')
|
||||||
invalid_lacv = copy.deepcopy(self.l)
|
invalid_lacv = copy.deepcopy(self.l)
|
||||||
invalid_lacv.terminator_length = self.trm_len
|
invalid_lacv.terminator_length = self.trm_len
|
||||||
invalid_buf = invalid_lacv.serialize()
|
invalid_buf = invalid_lacv.serialize()
|
||||||
slow.parser(invalid_buf)
|
slow.parser(invalid_buf)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_activity(self):
|
def test_invalid_actor_state_activity(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -617,11 +635,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_timeout(self):
|
def test_invalid_actor_state_timeout(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -649,11 +666,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_aggregation(self):
|
def test_invalid_actor_state_aggregation(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -681,11 +697,9 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_synchronization(self):
|
def test_invalid_actor_state_synchronization(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -713,11 +727,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_collecting(self):
|
def test_invalid_actor_state_collecting(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -745,11 +758,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_distributing(self):
|
def test_invalid_actor_state_distributing(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -777,11 +789,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_defaulted(self):
|
def test_invalid_actor_state_defaulted(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -809,11 +820,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_actor_state_expired(self):
|
def test_invalid_actor_state_expired(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -841,11 +851,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_activity(self):
|
def test_invalid_partner_state_activity(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -873,11 +882,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_timeout(self):
|
def test_invalid_partner_state_timeout(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -905,11 +913,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_aggregation(self):
|
def test_invalid_partner_state_aggregation(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -937,11 +944,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_synchronization(self):
|
def test_invalid_partner_state_synchronization(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -969,11 +975,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_collecting(self):
|
def test_invalid_partner_state_collecting(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -1001,11 +1006,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_distributing(self):
|
def test_invalid_partner_state_distributing(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -1033,11 +1037,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_defaulted(self):
|
def test_invalid_partner_state_defaulted(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -1065,11 +1068,10 @@ class Test_lacp(unittest.TestCase):
|
|||||||
-1,
|
-1,
|
||||||
self.partner_state_expired,
|
self.partner_state_expired,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_invalid_partner_state_expired(self):
|
def test_invalid_partner_state_expired(self):
|
||||||
l = lacp(self.version,
|
self.assertRaises(AssertionError, lacp,
|
||||||
|
self.version,
|
||||||
self.actor_system_priority,
|
self.actor_system_priority,
|
||||||
self.actor_system,
|
self.actor_system,
|
||||||
self.actor_key,
|
self.actor_key,
|
||||||
@ -1097,9 +1099,8 @@ class Test_lacp(unittest.TestCase):
|
|||||||
self.partner_state_defaulted,
|
self.partner_state_defaulted,
|
||||||
-1,
|
-1,
|
||||||
self.collector_max_delay)
|
self.collector_max_delay)
|
||||||
l.serialize()
|
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.l.to_jsondict()
|
jsondict = self.l.to_jsondict()
|
||||||
l = lacp.from_jsondict(jsondict['lacp'])
|
l = lacp.from_jsondict(jsondict['lacp'])
|
||||||
eq_(str(self.l), str(l))
|
self.assertEqual(str(self.l), str(l))
|
||||||
|
@ -20,7 +20,6 @@ import logging
|
|||||||
import six
|
import six
|
||||||
import struct
|
import struct
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import inet
|
from os_ken.ofproto import inet
|
||||||
from os_ken.lib.packet import tcp
|
from os_ken.lib.packet import tcp
|
||||||
from os_ken.lib.packet.ipv4 import ipv4
|
from os_ken.lib.packet.ipv4 import ipv4
|
||||||
@ -59,31 +58,31 @@ class Test_tcp(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.src_port, self.t.src_port)
|
self.assertEqual(self.src_port, self.t.src_port)
|
||||||
eq_(self.dst_port, self.t.dst_port)
|
self.assertEqual(self.dst_port, self.t.dst_port)
|
||||||
eq_(self.seq, self.t.seq)
|
self.assertEqual(self.seq, self.t.seq)
|
||||||
eq_(self.ack, self.t.ack)
|
self.assertEqual(self.ack, self.t.ack)
|
||||||
eq_(self.offset, self.t.offset)
|
self.assertEqual(self.offset, self.t.offset)
|
||||||
eq_(self.bits, self.t.bits)
|
self.assertEqual(self.bits, self.t.bits)
|
||||||
eq_(self.window_size, self.t.window_size)
|
self.assertEqual(self.window_size, self.t.window_size)
|
||||||
eq_(self.csum, self.t.csum)
|
self.assertEqual(self.csum, self.t.csum)
|
||||||
eq_(self.urgent, self.t.urgent)
|
self.assertEqual(self.urgent, self.t.urgent)
|
||||||
eq_(self.option, self.t.option)
|
self.assertEqual(self.option, self.t.option)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = self.t.parser(self.buf)
|
r1, r2, _ = self.t.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.src_port, r1.src_port)
|
self.assertEqual(self.src_port, r1.src_port)
|
||||||
eq_(self.dst_port, r1.dst_port)
|
self.assertEqual(self.dst_port, r1.dst_port)
|
||||||
eq_(self.seq, r1.seq)
|
self.assertEqual(self.seq, r1.seq)
|
||||||
eq_(self.ack, r1.ack)
|
self.assertEqual(self.ack, r1.ack)
|
||||||
eq_(self.offset, r1.offset)
|
self.assertEqual(self.offset, r1.offset)
|
||||||
eq_(self.bits, r1.bits)
|
self.assertEqual(self.bits, r1.bits)
|
||||||
eq_(self.window_size, r1.window_size)
|
self.assertEqual(self.window_size, r1.window_size)
|
||||||
eq_(self.csum, r1.csum)
|
self.assertEqual(self.csum, r1.csum)
|
||||||
eq_(self.urgent, r1.urgent)
|
self.assertEqual(self.urgent, r1.urgent)
|
||||||
eq_(self.option, r1.option)
|
self.assertEqual(self.option, r1.option)
|
||||||
eq_(None, r2)
|
self.assertEqual(None, r2)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
offset = 5
|
offset = 5
|
||||||
@ -99,20 +98,20 @@ class Test_tcp(unittest.TestCase):
|
|||||||
buf = t.serialize(bytearray(), prev)
|
buf = t.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(tcp.tcp._PACK_STR, six.binary_type(buf))
|
res = struct.unpack(tcp.tcp._PACK_STR, six.binary_type(buf))
|
||||||
|
|
||||||
eq_(res[0], self.src_port)
|
self.assertEqual(res[0], self.src_port)
|
||||||
eq_(res[1], self.dst_port)
|
self.assertEqual(res[1], self.dst_port)
|
||||||
eq_(res[2], self.seq)
|
self.assertEqual(res[2], self.seq)
|
||||||
eq_(res[3], self.ack)
|
self.assertEqual(res[3], self.ack)
|
||||||
eq_(res[4], offset << 4)
|
self.assertEqual(res[4], offset << 4)
|
||||||
eq_(res[5], self.bits)
|
self.assertEqual(res[5], self.bits)
|
||||||
eq_(res[6], self.window_size)
|
self.assertEqual(res[6], self.window_size)
|
||||||
eq_(res[8], self.urgent)
|
self.assertEqual(res[8], self.urgent)
|
||||||
|
|
||||||
# test __len__
|
# test __len__
|
||||||
# offset indicates the number of 32 bit (= 4 bytes)
|
# offset indicates the number of 32 bit (= 4 bytes)
|
||||||
# words in the TCP Header.
|
# words in the TCP Header.
|
||||||
# So, we compare len(tcp) with offset * 4, here.
|
# So, we compare len(tcp) with offset * 4, here.
|
||||||
eq_(offset * 4, len(t))
|
self.assertEqual(offset * 4, len(t))
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
ph = struct.pack('!4s4sBBH',
|
ph = struct.pack('!4s4sBBH',
|
||||||
@ -120,7 +119,7 @@ class Test_tcp(unittest.TestCase):
|
|||||||
addrconv.ipv4.text_to_bin(dst_ip), 0, 6, offset * 4)
|
addrconv.ipv4.text_to_bin(dst_ip), 0, 6, offset * 4)
|
||||||
d = ph + buf
|
d = ph + buf
|
||||||
s = packet_utils.checksum(d)
|
s = packet_utils.checksum(d)
|
||||||
eq_(0, s)
|
self.assertEqual(0, s)
|
||||||
|
|
||||||
def test_serialize_option(self):
|
def test_serialize_option(self):
|
||||||
# prepare test data
|
# prepare test data
|
||||||
@ -149,16 +148,15 @@ class Test_tcp(unittest.TestCase):
|
|||||||
option)
|
option)
|
||||||
buf = t.serialize(bytearray(), prev)
|
buf = t.serialize(bytearray(), prev)
|
||||||
r_option_buf = buf[tcp.tcp._MIN_LEN:tcp.tcp._MIN_LEN + len(option_buf)]
|
r_option_buf = buf[tcp.tcp._MIN_LEN:tcp.tcp._MIN_LEN + len(option_buf)]
|
||||||
eq_(option_buf, r_option_buf)
|
self.assertEqual(option_buf, r_option_buf)
|
||||||
|
|
||||||
# test parser
|
# test parser
|
||||||
(r_tcp, _, _) = tcp.tcp.parser(buf)
|
(r_tcp, _, _) = tcp.tcp.parser(buf)
|
||||||
eq_(str(option), str(r_tcp.option))
|
self.assertEqual(str(option), str(r_tcp.option))
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_tcp(self):
|
def test_malformed_tcp(self):
|
||||||
m_short_buf = self.buf[1:tcp.tcp._MIN_LEN]
|
m_short_buf = self.buf[1:tcp.tcp._MIN_LEN]
|
||||||
tcp.tcp.parser(m_short_buf)
|
self.assertRaises(Exception, tcp.tcp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
prev = ipv4(proto=inet.IPPROTO_TCP)
|
prev = ipv4(proto=inet.IPPROTO_TCP)
|
||||||
@ -166,49 +164,49 @@ class Test_tcp(unittest.TestCase):
|
|||||||
buf = t.serialize(bytearray(), prev)
|
buf = t.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(tcp.tcp._PACK_STR, buf)
|
res = struct.unpack(tcp.tcp._PACK_STR, buf)
|
||||||
|
|
||||||
eq_(res[0], 1)
|
self.assertEqual(res[0], 1)
|
||||||
eq_(res[1], 1)
|
self.assertEqual(res[1], 1)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], 0)
|
self.assertEqual(res[3], 0)
|
||||||
eq_(res[4], 5 << 4)
|
self.assertEqual(res[4], 5 << 4)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
eq_(res[6], 0)
|
self.assertEqual(res[6], 0)
|
||||||
eq_(res[8], 0)
|
self.assertEqual(res[8], 0)
|
||||||
|
|
||||||
# with option, without offset
|
# with option, without offset
|
||||||
t = tcp.tcp(option=[tcp.TCPOptionMaximumSegmentSize(1460)])
|
t = tcp.tcp(option=[tcp.TCPOptionMaximumSegmentSize(1460)])
|
||||||
buf = t.serialize(bytearray(), prev)
|
buf = t.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(tcp.tcp._PACK_STR + '4s', buf)
|
res = struct.unpack(tcp.tcp._PACK_STR + '4s', buf)
|
||||||
|
|
||||||
eq_(res[0], 1)
|
self.assertEqual(res[0], 1)
|
||||||
eq_(res[1], 1)
|
self.assertEqual(res[1], 1)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], 0)
|
self.assertEqual(res[3], 0)
|
||||||
eq_(res[4], 6 << 4)
|
self.assertEqual(res[4], 6 << 4)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
eq_(res[6], 0)
|
self.assertEqual(res[6], 0)
|
||||||
eq_(res[8], 0)
|
self.assertEqual(res[8], 0)
|
||||||
eq_(res[9], b'\x02\x04\x05\xb4')
|
self.assertEqual(res[9], b'\x02\x04\x05\xb4')
|
||||||
|
|
||||||
# with option, with long offset
|
# with option, with long offset
|
||||||
t = tcp.tcp(offset=7, option=[tcp.TCPOptionWindowScale(shift_cnt=9)])
|
t = tcp.tcp(offset=7, option=[tcp.TCPOptionWindowScale(shift_cnt=9)])
|
||||||
buf = t.serialize(bytearray(), prev)
|
buf = t.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(tcp.tcp._PACK_STR + '8s', buf)
|
res = struct.unpack(tcp.tcp._PACK_STR + '8s', buf)
|
||||||
|
|
||||||
eq_(res[0], 1)
|
self.assertEqual(res[0], 1)
|
||||||
eq_(res[1], 1)
|
self.assertEqual(res[1], 1)
|
||||||
eq_(res[2], 0)
|
self.assertEqual(res[2], 0)
|
||||||
eq_(res[3], 0)
|
self.assertEqual(res[3], 0)
|
||||||
eq_(res[4], 7 << 4)
|
self.assertEqual(res[4], 7 << 4)
|
||||||
eq_(res[5], 0)
|
self.assertEqual(res[5], 0)
|
||||||
eq_(res[6], 0)
|
self.assertEqual(res[6], 0)
|
||||||
eq_(res[8], 0)
|
self.assertEqual(res[8], 0)
|
||||||
eq_(res[9], b'\x03\x03\x09\x00\x00\x00\x00\x00')
|
self.assertEqual(res[9], b'\x03\x03\x09\x00\x00\x00\x00\x00')
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.t.to_jsondict()
|
jsondict = self.t.to_jsondict()
|
||||||
t = tcp.tcp.from_jsondict(jsondict['tcp'])
|
t = tcp.tcp.from_jsondict(jsondict['tcp'])
|
||||||
eq_(str(self.t), str(t))
|
self.assertEqual(str(self.t), str(t))
|
||||||
|
|
||||||
|
|
||||||
class Test_TCPOption(unittest.TestCase):
|
class Test_TCPOption(unittest.TestCase):
|
||||||
@ -250,7 +248,7 @@ class Test_TCPOption(unittest.TestCase):
|
|||||||
output_buf = bytearray()
|
output_buf = bytearray()
|
||||||
for option in self.input_options:
|
for option in self.input_options:
|
||||||
output_buf += option.serialize()
|
output_buf += option.serialize()
|
||||||
eq_(self.input_buf, output_buf)
|
self.assertEqual(self.input_buf, output_buf)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
buf = self.input_buf
|
buf = self.input_buf
|
||||||
@ -258,10 +256,10 @@ class Test_TCPOption(unittest.TestCase):
|
|||||||
while buf:
|
while buf:
|
||||||
opt, buf = tcp.TCPOption.parser(buf)
|
opt, buf = tcp.TCPOption.parser(buf)
|
||||||
output_options.append(opt)
|
output_options.append(opt)
|
||||||
eq_(str(self.input_options), str(output_options))
|
self.assertEqual(str(self.input_options), str(output_options))
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
for option in self.input_options:
|
for option in self.input_options:
|
||||||
json_dict = option.to_jsondict()[option.__class__.__name__]
|
json_dict = option.to_jsondict()[option.__class__.__name__]
|
||||||
output_option = option.__class__.from_jsondict(json_dict)
|
output_option = option.__class__.from_jsondict(json_dict)
|
||||||
eq_(str(option), str(output_option))
|
self.assertEqual(str(option), str(output_option))
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import ether, inet
|
from os_ken.ofproto import ether, inet
|
||||||
from os_ken.lib.packet.packet import Packet
|
from os_ken.lib.packet.packet import Packet
|
||||||
from os_ken.lib.packet.udp import udp
|
from os_ken.lib.packet.udp import udp
|
||||||
@ -48,19 +47,19 @@ class Test_udp(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.src_port, self.u.src_port)
|
self.assertEqual(self.src_port, self.u.src_port)
|
||||||
eq_(self.dst_port, self.u.dst_port)
|
self.assertEqual(self.dst_port, self.u.dst_port)
|
||||||
eq_(self.total_length, self.u.total_length)
|
self.assertEqual(self.total_length, self.u.total_length)
|
||||||
eq_(self.csum, self.u.csum)
|
self.assertEqual(self.csum, self.u.csum)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
r1, r2, _ = self.u.parser(self.buf)
|
r1, r2, _ = self.u.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.src_port, r1.src_port)
|
self.assertEqual(self.src_port, r1.src_port)
|
||||||
eq_(self.dst_port, r1.dst_port)
|
self.assertEqual(self.dst_port, r1.dst_port)
|
||||||
eq_(self.total_length, r1.total_length)
|
self.assertEqual(self.total_length, r1.total_length)
|
||||||
eq_(self.csum, r1.csum)
|
self.assertEqual(self.csum, r1.csum)
|
||||||
eq_(None, r2)
|
self.assertEqual(None, r2)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
src_port = 6431
|
src_port = 6431
|
||||||
@ -77,9 +76,9 @@ class Test_udp(unittest.TestCase):
|
|||||||
buf = u.serialize(bytearray(), prev)
|
buf = u.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(udp._PACK_STR, buf)
|
res = struct.unpack(udp._PACK_STR, buf)
|
||||||
|
|
||||||
eq_(res[0], src_port)
|
self.assertEqual(res[0], src_port)
|
||||||
eq_(res[1], dst_port)
|
self.assertEqual(res[1], dst_port)
|
||||||
eq_(res[2], struct.calcsize(udp._PACK_STR))
|
self.assertEqual(res[2], struct.calcsize(udp._PACK_STR))
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
ph = struct.pack('!4s4sBBH',
|
ph = struct.pack('!4s4sBBH',
|
||||||
@ -87,12 +86,11 @@ class Test_udp(unittest.TestCase):
|
|||||||
addrconv.ipv4.text_to_bin(dst_ip), 0, 17, res[2])
|
addrconv.ipv4.text_to_bin(dst_ip), 0, 17, res[2])
|
||||||
d = ph + buf + bytearray()
|
d = ph + buf + bytearray()
|
||||||
s = packet_utils.checksum(d)
|
s = packet_utils.checksum(d)
|
||||||
eq_(0, s)
|
self.assertEqual(0, s)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_udp(self):
|
def test_malformed_udp(self):
|
||||||
m_short_buf = self.buf[1:udp._MIN_LEN]
|
m_short_buf = self.buf[1:udp._MIN_LEN]
|
||||||
udp.parser(m_short_buf)
|
self.assertRaises(Exception, udp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
prev = ipv4(proto=inet.IPPROTO_UDP)
|
prev = ipv4(proto=inet.IPPROTO_UDP)
|
||||||
@ -100,11 +98,11 @@ class Test_udp(unittest.TestCase):
|
|||||||
buf = u.serialize(bytearray(), prev)
|
buf = u.serialize(bytearray(), prev)
|
||||||
res = struct.unpack(udp._PACK_STR, buf)
|
res = struct.unpack(udp._PACK_STR, buf)
|
||||||
|
|
||||||
eq_(res[0], 1)
|
self.assertEqual(res[0], 1)
|
||||||
eq_(res[1], 1)
|
self.assertEqual(res[1], 1)
|
||||||
eq_(res[2], udp._MIN_LEN)
|
self.assertEqual(res[2], udp._MIN_LEN)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.u.to_jsondict()
|
jsondict = self.u.to_jsondict()
|
||||||
u = udp.from_jsondict(jsondict['udp'])
|
u = udp.from_jsondict(jsondict['udp'])
|
||||||
eq_(str(self.u), str(u))
|
self.assertEqual(str(self.u), str(u))
|
||||||
|
@ -19,7 +19,6 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
from struct import *
|
from struct import *
|
||||||
from nose.tools import *
|
|
||||||
from os_ken.ofproto import ether, inet
|
from os_ken.ofproto import ether, inet
|
||||||
from os_ken.lib.packet.ethernet import ethernet
|
from os_ken.lib.packet.ethernet import ethernet
|
||||||
from os_ken.lib.packet.packet import Packet
|
from os_ken.lib.packet.packet import Packet
|
||||||
@ -57,19 +56,19 @@ class Test_vlan(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.pcp, self.v.pcp)
|
self.assertEqual(self.pcp, self.v.pcp)
|
||||||
eq_(self.cfi, self.v.cfi)
|
self.assertEqual(self.cfi, self.v.cfi)
|
||||||
eq_(self.vid, self.v.vid)
|
self.assertEqual(self.vid, self.v.vid)
|
||||||
eq_(self.ethertype, self.v.ethertype)
|
self.assertEqual(self.ethertype, self.v.ethertype)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
res, ptype, _ = self.v.parser(self.buf)
|
res, ptype, _ = self.v.parser(self.buf)
|
||||||
|
|
||||||
eq_(res.pcp, self.pcp)
|
self.assertEqual(res.pcp, self.pcp)
|
||||||
eq_(res.cfi, self.cfi)
|
self.assertEqual(res.cfi, self.cfi)
|
||||||
eq_(res.vid, self.vid)
|
self.assertEqual(res.vid, self.vid)
|
||||||
eq_(res.ethertype, self.ethertype)
|
self.assertEqual(res.ethertype, self.ethertype)
|
||||||
eq_(ptype, ipv4)
|
self.assertEqual(ptype, ipv4)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -79,8 +78,8 @@ class Test_vlan(unittest.TestCase):
|
|||||||
fmt = vlan._PACK_STR
|
fmt = vlan._PACK_STR
|
||||||
res = struct.unpack(fmt, buf)
|
res = struct.unpack(fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.tci)
|
self.assertEqual(res[0], self.tci)
|
||||||
eq_(res[1], self.ethertype)
|
self.assertEqual(res[1], self.ethertype)
|
||||||
|
|
||||||
def _build_vlan(self):
|
def _build_vlan(self):
|
||||||
src_mac = '00:07:0d:af:f4:54'
|
src_mac = '00:07:0d:af:f4:54'
|
||||||
@ -117,30 +116,29 @@ class Test_vlan(unittest.TestCase):
|
|||||||
p = self._build_vlan()
|
p = self._build_vlan()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_8021Q)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||||
|
|
||||||
v = self.find_protocol(p, "vlan")
|
v = self.find_protocol(p, "vlan")
|
||||||
ok_(v)
|
self.assertTrue(v)
|
||||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
ip = self.find_protocol(p, "ipv4")
|
ip = self.find_protocol(p, "ipv4")
|
||||||
ok_(ip)
|
self.assertTrue(ip)
|
||||||
|
|
||||||
eq_(v.pcp, self.pcp)
|
self.assertEqual(v.pcp, self.pcp)
|
||||||
eq_(v.cfi, self.cfi)
|
self.assertEqual(v.cfi, self.cfi)
|
||||||
eq_(v.vid, self.vid)
|
self.assertEqual(v.vid, self.vid)
|
||||||
eq_(v.ethertype, self.ethertype)
|
self.assertEqual(v.ethertype, self.ethertype)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_vlan(self):
|
def test_malformed_vlan(self):
|
||||||
m_short_buf = self.buf[1:vlan._MIN_LEN]
|
m_short_buf = self.buf[1:vlan._MIN_LEN]
|
||||||
vlan.parser(m_short_buf)
|
self.assertRaises(Exception, vlan.parser, m_short_buf)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.v.to_jsondict()
|
jsondict = self.v.to_jsondict()
|
||||||
v = vlan.from_jsondict(jsondict['vlan'])
|
v = vlan.from_jsondict(jsondict['vlan'])
|
||||||
eq_(str(self.v), str(v))
|
self.assertEqual(str(self.v), str(v))
|
||||||
|
|
||||||
|
|
||||||
class Test_svlan(unittest.TestCase):
|
class Test_svlan(unittest.TestCase):
|
||||||
@ -167,19 +165,19 @@ class Test_svlan(unittest.TestCase):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.pcp, self.sv.pcp)
|
self.assertEqual(self.pcp, self.sv.pcp)
|
||||||
eq_(self.cfi, self.sv.cfi)
|
self.assertEqual(self.cfi, self.sv.cfi)
|
||||||
eq_(self.vid, self.sv.vid)
|
self.assertEqual(self.vid, self.sv.vid)
|
||||||
eq_(self.ethertype, self.sv.ethertype)
|
self.assertEqual(self.ethertype, self.sv.ethertype)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
res, ptype, _ = self.sv.parser(self.buf)
|
res, ptype, _ = self.sv.parser(self.buf)
|
||||||
|
|
||||||
eq_(res.pcp, self.pcp)
|
self.assertEqual(res.pcp, self.pcp)
|
||||||
eq_(res.cfi, self.cfi)
|
self.assertEqual(res.cfi, self.cfi)
|
||||||
eq_(res.vid, self.vid)
|
self.assertEqual(res.vid, self.vid)
|
||||||
eq_(res.ethertype, self.ethertype)
|
self.assertEqual(res.ethertype, self.ethertype)
|
||||||
eq_(ptype, vlan)
|
self.assertEqual(ptype, vlan)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
@ -189,8 +187,8 @@ class Test_svlan(unittest.TestCase):
|
|||||||
fmt = svlan._PACK_STR
|
fmt = svlan._PACK_STR
|
||||||
res = struct.unpack(fmt, buf)
|
res = struct.unpack(fmt, buf)
|
||||||
|
|
||||||
eq_(res[0], self.tci)
|
self.assertEqual(res[0], self.tci)
|
||||||
eq_(res[1], self.ethertype)
|
self.assertEqual(res[1], self.ethertype)
|
||||||
|
|
||||||
def _build_svlan(self):
|
def _build_svlan(self):
|
||||||
src_mac = '00:07:0d:af:f4:54'
|
src_mac = '00:07:0d:af:f4:54'
|
||||||
@ -235,31 +233,30 @@ class Test_svlan(unittest.TestCase):
|
|||||||
p = self._build_svlan()
|
p = self._build_svlan()
|
||||||
|
|
||||||
e = self.find_protocol(p, "ethernet")
|
e = self.find_protocol(p, "ethernet")
|
||||||
ok_(e)
|
self.assertTrue(e)
|
||||||
eq_(e.ethertype, ether.ETH_TYPE_8021AD)
|
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021AD)
|
||||||
|
|
||||||
sv = self.find_protocol(p, "svlan")
|
sv = self.find_protocol(p, "svlan")
|
||||||
ok_(sv)
|
self.assertTrue(sv)
|
||||||
eq_(sv.ethertype, ether.ETH_TYPE_8021Q)
|
self.assertEqual(sv.ethertype, ether.ETH_TYPE_8021Q)
|
||||||
|
|
||||||
v = self.find_protocol(p, "vlan")
|
v = self.find_protocol(p, "vlan")
|
||||||
ok_(v)
|
self.assertTrue(v)
|
||||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||||
|
|
||||||
ip = self.find_protocol(p, "ipv4")
|
ip = self.find_protocol(p, "ipv4")
|
||||||
ok_(ip)
|
self.assertTrue(ip)
|
||||||
|
|
||||||
eq_(sv.pcp, self.pcp)
|
self.assertEqual(sv.pcp, self.pcp)
|
||||||
eq_(sv.cfi, self.cfi)
|
self.assertEqual(sv.cfi, self.cfi)
|
||||||
eq_(sv.vid, self.vid)
|
self.assertEqual(sv.vid, self.vid)
|
||||||
eq_(sv.ethertype, self.ethertype)
|
self.assertEqual(sv.ethertype, self.ethertype)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_svlan(self):
|
def test_malformed_svlan(self):
|
||||||
m_short_buf = self.buf[1:svlan._MIN_LEN]
|
m_short_buf = self.buf[1:svlan._MIN_LEN]
|
||||||
svlan.parser(m_short_buf)
|
self.assertRaises(Exception, vlan.parser, m_short_buf)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
jsondict = self.sv.to_jsondict()
|
jsondict = self.sv.to_jsondict()
|
||||||
sv = svlan.from_jsondict(jsondict['svlan'])
|
sv = svlan.from_jsondict(jsondict['svlan'])
|
||||||
eq_(str(self.sv), str(sv))
|
self.assertEqual(str(self.sv), str(sv))
|
||||||
|
@ -22,9 +22,6 @@ import six
|
|||||||
import struct
|
import struct
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from nose.tools import eq_, ok_
|
|
||||||
from nose.tools import raises
|
|
||||||
|
|
||||||
from os_ken.ofproto import inet
|
from os_ken.ofproto import inet
|
||||||
from os_ken.lib.packet import ipv4
|
from os_ken.lib.packet import ipv4
|
||||||
from os_ken.lib.packet import ipv6
|
from os_ken.lib.packet import ipv6
|
||||||
@ -66,30 +63,30 @@ class Test_vrrpv2(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.vrrpv2.type)
|
self.assertEqual(self.type_, self.vrrpv2.type)
|
||||||
eq_(self.vrid, self.vrrpv2.vrid)
|
self.assertEqual(self.vrid, self.vrrpv2.vrid)
|
||||||
eq_(self.priority, self.vrrpv2.priority)
|
self.assertEqual(self.priority, self.vrrpv2.priority)
|
||||||
eq_(self.count_ip, self.vrrpv2.count_ip)
|
self.assertEqual(self.count_ip, self.vrrpv2.count_ip)
|
||||||
eq_(self.auth_type, self.vrrpv2.auth_type)
|
self.assertEqual(self.auth_type, self.vrrpv2.auth_type)
|
||||||
eq_(1, len(self.vrrpv2.ip_addresses))
|
self.assertEqual(1, len(self.vrrpv2.ip_addresses))
|
||||||
eq_(self.ip_address, self.vrrpv2.ip_addresses[0])
|
self.assertEqual(self.ip_address, self.vrrpv2.ip_addresses[0])
|
||||||
eq_(self.auth_data, self.vrrpv2.auth_data)
|
self.assertEqual(self.auth_data, self.vrrpv2.auth_data)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
vrrpv2, _cls, _ = self.vrrpv2.parser(self.buf)
|
vrrpv2, _cls, _ = self.vrrpv2.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.version, vrrpv2.version)
|
self.assertEqual(self.version, vrrpv2.version)
|
||||||
eq_(self.type_, vrrpv2.type)
|
self.assertEqual(self.type_, vrrpv2.type)
|
||||||
eq_(self.vrid, vrrpv2.vrid)
|
self.assertEqual(self.vrid, vrrpv2.vrid)
|
||||||
eq_(self.priority, vrrpv2.priority)
|
self.assertEqual(self.priority, vrrpv2.priority)
|
||||||
eq_(self.count_ip, vrrpv2.count_ip)
|
self.assertEqual(self.count_ip, vrrpv2.count_ip)
|
||||||
eq_(self.auth_type, vrrpv2.auth_type)
|
self.assertEqual(self.auth_type, vrrpv2.auth_type)
|
||||||
eq_(self.max_adver_int, vrrpv2.max_adver_int)
|
self.assertEqual(self.max_adver_int, vrrpv2.max_adver_int)
|
||||||
eq_(self.checksum, vrrpv2.checksum)
|
self.assertEqual(self.checksum, vrrpv2.checksum)
|
||||||
eq_(1, len(vrrpv2.ip_addresses))
|
self.assertEqual(1, len(vrrpv2.ip_addresses))
|
||||||
eq_(str, type(vrrpv2.ip_addresses[0]))
|
self.assertEqual(str, type(vrrpv2.ip_addresses[0]))
|
||||||
eq_(self.ip_address, vrrpv2.ip_addresses[0])
|
self.assertEqual(self.ip_address, vrrpv2.ip_addresses[0])
|
||||||
eq_(self.auth_data, vrrpv2.auth_data)
|
self.assertEqual(self.auth_data, vrrpv2.auth_data)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
src_ip = '192.168.0.1'
|
src_ip = '192.168.0.1'
|
||||||
@ -111,26 +108,25 @@ class Test_vrrpv2(unittest.TestCase):
|
|||||||
pack_str = vrrp.vrrpv2._PACK_STR + '4sII'
|
pack_str = vrrp.vrrpv2._PACK_STR + '4sII'
|
||||||
pack_len = struct.calcsize(pack_str)
|
pack_len = struct.calcsize(pack_str)
|
||||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_))
|
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_))
|
||||||
eq_(res[1], vrid)
|
self.assertEqual(res[1], vrid)
|
||||||
eq_(res[2], priority)
|
self.assertEqual(res[2], priority)
|
||||||
eq_(res[3], len(ip_addresses))
|
self.assertEqual(res[3], len(ip_addresses))
|
||||||
eq_(res[4], vrrp.VRRP_AUTH_NO_AUTH)
|
self.assertEqual(res[4], vrrp.VRRP_AUTH_NO_AUTH)
|
||||||
eq_(res[5], max_adver_int)
|
self.assertEqual(res[5], max_adver_int)
|
||||||
# res[6] is checksum
|
# res[6] is checksum
|
||||||
eq_(res[7], addrconv.ipv4.text_to_bin(ip_address))
|
self.assertEqual(res[7], addrconv.ipv4.text_to_bin(ip_address))
|
||||||
eq_(res[8], 0)
|
self.assertEqual(res[8], 0)
|
||||||
eq_(res[9], 0)
|
self.assertEqual(res[9], 0)
|
||||||
eq_(len(buf), pack_len)
|
self.assertEqual(len(buf), pack_len)
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
s = packet_utils.checksum(buf)
|
s = packet_utils.checksum(buf)
|
||||||
eq_(0, s)
|
self.assertEqual(0, s)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_vrrpv2(self):
|
def test_malformed_vrrpv2(self):
|
||||||
m_short_buf = self.buf[1:vrrp.vrrpv2._MIN_LEN]
|
m_short_buf = self.buf[1:vrrp.vrrpv2._MIN_LEN]
|
||||||
vrrp.vrrp.parser(m_short_buf)
|
self.assertRaises(Exception, vrrp.vrrp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_create_packet(self):
|
def test_create_packet(self):
|
||||||
primary_ip = '192.168.0.2'
|
primary_ip = '192.168.0.2'
|
||||||
@ -138,7 +134,7 @@ class Test_vrrpv2(unittest.TestCase):
|
|||||||
p0.serialize()
|
p0.serialize()
|
||||||
p1 = packet.Packet(six.binary_type(p0.data))
|
p1 = packet.Packet(six.binary_type(p0.data))
|
||||||
p1.serialize()
|
p1.serialize()
|
||||||
eq_(p0.data, p1.data)
|
self.assertEqual(p0.data, p1.data)
|
||||||
|
|
||||||
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
||||||
max_adver_int=None):
|
max_adver_int=None):
|
||||||
@ -156,34 +152,34 @@ class Test_vrrpv2(unittest.TestCase):
|
|||||||
return vrrp_.is_valid()
|
return vrrp_.is_valid()
|
||||||
|
|
||||||
def test_is_valid_ok(self):
|
def test_is_valid_ok(self):
|
||||||
ok_(self._test_is_valid())
|
self.assertTrue(self._test_is_valid())
|
||||||
|
|
||||||
def test_is_valid_ng_type(self):
|
def test_is_valid_ng_type(self):
|
||||||
ok_(not self._test_is_valid(type_=15))
|
self.assertTrue(not self._test_is_valid(type_=15))
|
||||||
|
|
||||||
def test_is_valid_ng_vrid_min(self):
|
def test_is_valid_ng_vrid_min(self):
|
||||||
vrid = vrrp.VRRP_VRID_MIN - 1
|
vrid = vrrp.VRRP_VRID_MIN - 1
|
||||||
ok_(not self._test_is_valid(vrid=vrid))
|
self.assertTrue(not self._test_is_valid(vrid=vrid))
|
||||||
|
|
||||||
def test_is_valid_ng_vrid_max(self):
|
def test_is_valid_ng_vrid_max(self):
|
||||||
vrid = vrrp.VRRP_VRID_MAX + 1
|
vrid = vrrp.VRRP_VRID_MAX + 1
|
||||||
ok_(not self._test_is_valid(vrid=vrid))
|
self.assertTrue(not self._test_is_valid(vrid=vrid))
|
||||||
|
|
||||||
def test_is_valid_ng_priority_min(self):
|
def test_is_valid_ng_priority_min(self):
|
||||||
priority = vrrp.VRRP_PRIORITY_MIN - 1
|
priority = vrrp.VRRP_PRIORITY_MIN - 1
|
||||||
ok_(not self._test_is_valid(priority=priority))
|
self.assertTrue(not self._test_is_valid(priority=priority))
|
||||||
|
|
||||||
def test_is_valid_ng_priority_max(self):
|
def test_is_valid_ng_priority_max(self):
|
||||||
priority = vrrp.VRRP_PRIORITY_MAX + 1
|
priority = vrrp.VRRP_PRIORITY_MAX + 1
|
||||||
ok_(not self._test_is_valid(priority=priority))
|
self.assertTrue(not self._test_is_valid(priority=priority))
|
||||||
|
|
||||||
def test_is_valid_ng_adver_min(self):
|
def test_is_valid_ng_adver_min(self):
|
||||||
max_adver_int = vrrp.VRRP_V2_MAX_ADVER_INT_MIN - 1
|
max_adver_int = vrrp.VRRP_V2_MAX_ADVER_INT_MIN - 1
|
||||||
ok_(not self._test_is_valid(max_adver_int=max_adver_int))
|
self.assertTrue(not self._test_is_valid(max_adver_int=max_adver_int))
|
||||||
|
|
||||||
def test_is_valid_ng_adver_max(self):
|
def test_is_valid_ng_adver_max(self):
|
||||||
max_adver_int = vrrp.VRRP_V2_MAX_ADVER_INT_MAX + 1
|
max_adver_int = vrrp.VRRP_V2_MAX_ADVER_INT_MAX + 1
|
||||||
ok_(not self._test_is_valid(max_adver_int=max_adver_int))
|
self.assertTrue(not self._test_is_valid(max_adver_int=max_adver_int))
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
vrrpv2_values = {'version': self.version,
|
vrrpv2_values = {'version': self.version,
|
||||||
@ -202,8 +198,8 @@ class Test_vrrpv2(unittest.TestCase):
|
|||||||
if k in vrrpv2_values])
|
if k in vrrpv2_values])
|
||||||
vrrpv2_str = '%s(%s)' % (vrrp.vrrpv2.__name__, _vrrpv2_str)
|
vrrpv2_str = '%s(%s)' % (vrrp.vrrpv2.__name__, _vrrpv2_str)
|
||||||
|
|
||||||
eq_(str(self.vrrpv2), vrrpv2_str)
|
self.assertEqual(str(self.vrrpv2), vrrpv2_str)
|
||||||
eq_(repr(self.vrrpv2), vrrpv2_str)
|
self.assertEqual(repr(self.vrrpv2), vrrpv2_str)
|
||||||
|
|
||||||
|
|
||||||
class Test_vrrpv3_ipv4(unittest.TestCase):
|
class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||||
@ -232,26 +228,26 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.vrrpv3.type)
|
self.assertEqual(self.type_, self.vrrpv3.type)
|
||||||
eq_(self.vrid, self.vrrpv3.vrid)
|
self.assertEqual(self.vrid, self.vrrpv3.vrid)
|
||||||
eq_(self.priority, self.vrrpv3.priority)
|
self.assertEqual(self.priority, self.vrrpv3.priority)
|
||||||
eq_(self.count_ip, self.vrrpv3.count_ip)
|
self.assertEqual(self.count_ip, self.vrrpv3.count_ip)
|
||||||
eq_(1, len(self.vrrpv3.ip_addresses))
|
self.assertEqual(1, len(self.vrrpv3.ip_addresses))
|
||||||
eq_(self.ip_address, self.vrrpv3.ip_addresses[0])
|
self.assertEqual(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.version, vrrpv3.version)
|
self.assertEqual(self.version, vrrpv3.version)
|
||||||
eq_(self.type_, vrrpv3.type)
|
self.assertEqual(self.type_, vrrpv3.type)
|
||||||
eq_(self.vrid, vrrpv3.vrid)
|
self.assertEqual(self.vrid, vrrpv3.vrid)
|
||||||
eq_(self.priority, vrrpv3.priority)
|
self.assertEqual(self.priority, vrrpv3.priority)
|
||||||
eq_(self.count_ip, vrrpv3.count_ip)
|
self.assertEqual(self.count_ip, vrrpv3.count_ip)
|
||||||
eq_(self.max_adver_int, vrrpv3.max_adver_int)
|
self.assertEqual(self.max_adver_int, vrrpv3.max_adver_int)
|
||||||
eq_(self.checksum, vrrpv3.checksum)
|
self.assertEqual(self.checksum, vrrpv3.checksum)
|
||||||
eq_(1, len(vrrpv3.ip_addresses))
|
self.assertEqual(1, len(vrrpv3.ip_addresses))
|
||||||
eq_(str, type(vrrpv3.ip_addresses[0]))
|
self.assertEqual(str, type(vrrpv3.ip_addresses[0]))
|
||||||
eq_(self.ip_address, vrrpv3.ip_addresses[0])
|
self.assertEqual(self.ip_address, vrrpv3.ip_addresses[0])
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
src_ip = '192.168.0.1'
|
src_ip = '192.168.0.1'
|
||||||
@ -274,14 +270,14 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
pack_str = vrrp.vrrpv3._PACK_STR + '4s'
|
pack_str = vrrp.vrrpv3._PACK_STR + '4s'
|
||||||
pack_len = struct.calcsize(pack_str)
|
pack_len = struct.calcsize(pack_str)
|
||||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||||
eq_(res[1], vrid)
|
self.assertEqual(res[1], vrid)
|
||||||
eq_(res[2], priority)
|
self.assertEqual(res[2], priority)
|
||||||
eq_(res[3], len(ip_addresses))
|
self.assertEqual(res[3], len(ip_addresses))
|
||||||
eq_(res[4], max_adver_int)
|
self.assertEqual(res[4], max_adver_int)
|
||||||
# res[5] is checksum
|
# res[5] is checksum
|
||||||
eq_(res[6], addrconv.ipv4.text_to_bin(ip_address))
|
self.assertEqual(res[6], addrconv.ipv4.text_to_bin(ip_address))
|
||||||
eq_(len(buf), pack_len)
|
self.assertEqual(len(buf), pack_len)
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
@ -290,12 +286,11 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
addrconv.ipv4.text_to_bin(dst_ip),
|
addrconv.ipv4.text_to_bin(dst_ip),
|
||||||
inet.IPPROTO_VRRP, pack_len)
|
inet.IPPROTO_VRRP, pack_len)
|
||||||
s = packet_utils.checksum(ph + buf)
|
s = packet_utils.checksum(ph + buf)
|
||||||
eq_(0, s)
|
self.assertEqual(0, s)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_vrrpv3(self):
|
def test_malformed_vrrpv3(self):
|
||||||
m_short_buf = self.buf[1:vrrp.vrrpv3._MIN_LEN]
|
m_short_buf = self.buf[1:vrrp.vrrpv3._MIN_LEN]
|
||||||
vrrp.vrrp.parser(m_short_buf)
|
self.assertRaises(Exception, vrrp.vrrp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_create_packet(self):
|
def test_create_packet(self):
|
||||||
primary_ip = '192.168.0.2'
|
primary_ip = '192.168.0.2'
|
||||||
@ -303,7 +298,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
p0.serialize()
|
p0.serialize()
|
||||||
p1 = packet.Packet(six.binary_type(p0.data))
|
p1 = packet.Packet(six.binary_type(p0.data))
|
||||||
p1.serialize()
|
p1.serialize()
|
||||||
eq_(p0.data, p1.data)
|
self.assertEqual(p0.data, p1.data)
|
||||||
|
|
||||||
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
||||||
max_adver_int=None):
|
max_adver_int=None):
|
||||||
@ -321,34 +316,34 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
return vrrp_.is_valid()
|
return vrrp_.is_valid()
|
||||||
|
|
||||||
def test_is_valid_ok(self):
|
def test_is_valid_ok(self):
|
||||||
ok_(self._test_is_valid())
|
self.assertTrue(self._test_is_valid())
|
||||||
|
|
||||||
def test_is_valid_ng_type(self):
|
def test_is_valid_ng_type(self):
|
||||||
ok_(not self._test_is_valid(type_=15))
|
self.assertTrue(not self._test_is_valid(type_=15))
|
||||||
|
|
||||||
def test_is_valid_ng_vrid_min(self):
|
def test_is_valid_ng_vrid_min(self):
|
||||||
vrid = vrrp.VRRP_VRID_MIN - 1
|
vrid = vrrp.VRRP_VRID_MIN - 1
|
||||||
ok_(not self._test_is_valid(vrid=vrid))
|
self.assertTrue(not self._test_is_valid(vrid=vrid))
|
||||||
|
|
||||||
def test_is_valid_ng_vrid_max(self):
|
def test_is_valid_ng_vrid_max(self):
|
||||||
vrid = vrrp.VRRP_VRID_MAX + 1
|
vrid = vrrp.VRRP_VRID_MAX + 1
|
||||||
ok_(not self._test_is_valid(vrid=vrid))
|
self.assertTrue(not self._test_is_valid(vrid=vrid))
|
||||||
|
|
||||||
def test_is_valid_ng_priority_min(self):
|
def test_is_valid_ng_priority_min(self):
|
||||||
priority = vrrp.VRRP_PRIORITY_MIN - 1
|
priority = vrrp.VRRP_PRIORITY_MIN - 1
|
||||||
ok_(not self._test_is_valid(priority=priority))
|
self.assertTrue(not self._test_is_valid(priority=priority))
|
||||||
|
|
||||||
def test_is_valid_ng_priority_max(self):
|
def test_is_valid_ng_priority_max(self):
|
||||||
priority = vrrp.VRRP_PRIORITY_MAX + 1
|
priority = vrrp.VRRP_PRIORITY_MAX + 1
|
||||||
ok_(not self._test_is_valid(priority=priority))
|
self.assertTrue(not self._test_is_valid(priority=priority))
|
||||||
|
|
||||||
def test_is_valid_ng_adver_min(self):
|
def test_is_valid_ng_adver_min(self):
|
||||||
max_adver_int = vrrp.VRRP_V3_MAX_ADVER_INT_MIN - 1
|
max_adver_int = vrrp.VRRP_V3_MAX_ADVER_INT_MIN - 1
|
||||||
ok_(not self._test_is_valid(max_adver_int=max_adver_int))
|
self.assertTrue(not self._test_is_valid(max_adver_int=max_adver_int))
|
||||||
|
|
||||||
def test_is_valid_ng_adver_max(self):
|
def test_is_valid_ng_adver_max(self):
|
||||||
max_adver_int = vrrp.VRRP_V3_MAX_ADVER_INT_MAX + 1
|
max_adver_int = vrrp.VRRP_V3_MAX_ADVER_INT_MAX + 1
|
||||||
ok_(not self._test_is_valid(max_adver_int=max_adver_int))
|
self.assertTrue(not self._test_is_valid(max_adver_int=max_adver_int))
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
vrrpv3_values = {'version': self.version,
|
vrrpv3_values = {'version': self.version,
|
||||||
@ -367,8 +362,8 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
|||||||
if k in vrrpv3_values])
|
if k in vrrpv3_values])
|
||||||
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
||||||
|
|
||||||
eq_(str(self.vrrpv3), vrrpv3_str)
|
self.assertEqual(str(self.vrrpv3), vrrpv3_str)
|
||||||
eq_(repr(self.vrrpv3), vrrpv3_str)
|
self.assertEqual(repr(self.vrrpv3), vrrpv3_str)
|
||||||
|
|
||||||
|
|
||||||
class Test_vrrpv3_ipv6(unittest.TestCase):
|
class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||||
@ -397,26 +392,26 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.type_, self.vrrpv3.type)
|
self.assertEqual(self.type_, self.vrrpv3.type)
|
||||||
eq_(self.vrid, self.vrrpv3.vrid)
|
self.assertEqual(self.vrid, self.vrrpv3.vrid)
|
||||||
eq_(self.priority, self.vrrpv3.priority)
|
self.assertEqual(self.priority, self.vrrpv3.priority)
|
||||||
eq_(self.count_ip, self.vrrpv3.count_ip)
|
self.assertEqual(self.count_ip, self.vrrpv3.count_ip)
|
||||||
eq_(1, len(self.vrrpv3.ip_addresses))
|
self.assertEqual(1, len(self.vrrpv3.ip_addresses))
|
||||||
eq_(self.ip_address, self.vrrpv3.ip_addresses[0])
|
self.assertEqual(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
||||||
|
|
||||||
eq_(self.version, vrrpv3.version)
|
self.assertEqual(self.version, vrrpv3.version)
|
||||||
eq_(self.type_, vrrpv3.type)
|
self.assertEqual(self.type_, vrrpv3.type)
|
||||||
eq_(self.vrid, vrrpv3.vrid)
|
self.assertEqual(self.vrid, vrrpv3.vrid)
|
||||||
eq_(self.priority, vrrpv3.priority)
|
self.assertEqual(self.priority, vrrpv3.priority)
|
||||||
eq_(self.count_ip, vrrpv3.count_ip)
|
self.assertEqual(self.count_ip, vrrpv3.count_ip)
|
||||||
eq_(self.max_adver_int, vrrpv3.max_adver_int)
|
self.assertEqual(self.max_adver_int, vrrpv3.max_adver_int)
|
||||||
eq_(self.checksum, vrrpv3.checksum)
|
self.assertEqual(self.checksum, vrrpv3.checksum)
|
||||||
eq_(1, len(vrrpv3.ip_addresses))
|
self.assertEqual(1, len(vrrpv3.ip_addresses))
|
||||||
eq_(str, type(vrrpv3.ip_addresses[0]))
|
self.assertEqual(str, type(vrrpv3.ip_addresses[0]))
|
||||||
eq_(self.ip_address, vrrpv3.ip_addresses[0])
|
self.assertEqual(self.ip_address, vrrpv3.ip_addresses[0])
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
src_ip = '2001:db8:2000::1'
|
src_ip = '2001:db8:2000::1'
|
||||||
@ -439,14 +434,14 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
|||||||
pack_str = vrrp.vrrpv3._PACK_STR + '16s'
|
pack_str = vrrp.vrrpv3._PACK_STR + '16s'
|
||||||
pack_len = struct.calcsize(pack_str)
|
pack_len = struct.calcsize(pack_str)
|
||||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||||
eq_(res[1], vrid)
|
self.assertEqual(res[1], vrid)
|
||||||
eq_(res[2], priority)
|
self.assertEqual(res[2], priority)
|
||||||
eq_(res[3], len(ip_addresses))
|
self.assertEqual(res[3], len(ip_addresses))
|
||||||
eq_(res[4], max_adver_int)
|
self.assertEqual(res[4], max_adver_int)
|
||||||
# res[5] is checksum
|
# res[5] is checksum
|
||||||
eq_(res[6], addrconv.ipv6.text_to_bin(ip_address))
|
self.assertEqual(res[6], addrconv.ipv6.text_to_bin(ip_address))
|
||||||
eq_(len(buf), pack_len)
|
self.assertEqual(len(buf), pack_len)
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
# checksum
|
# checksum
|
||||||
@ -455,12 +450,11 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
|||||||
addrconv.ipv6.text_to_bin(dst_ip),
|
addrconv.ipv6.text_to_bin(dst_ip),
|
||||||
pack_len, inet.IPPROTO_VRRP)
|
pack_len, inet.IPPROTO_VRRP)
|
||||||
s = packet_utils.checksum(ph + buf)
|
s = packet_utils.checksum(ph + buf)
|
||||||
eq_(0, s)
|
self.assertEqual(0, s)
|
||||||
|
|
||||||
@raises(Exception)
|
|
||||||
def test_malformed_vrrpv3(self):
|
def test_malformed_vrrpv3(self):
|
||||||
m_short_buf = self.buf[1:vrrp.vrrpv3._MIN_LEN]
|
m_short_buf = self.buf[1:vrrp.vrrpv3._MIN_LEN]
|
||||||
vrrp.vrrp.parser(m_short_buf)
|
self.assertRaises(Exception, vrrp.vrrp.parser, m_short_buf)
|
||||||
|
|
||||||
def test_create_packet(self):
|
def test_create_packet(self):
|
||||||
primary_ip = '2001:db8:2000::3'
|
primary_ip = '2001:db8:2000::3'
|
||||||
@ -471,7 +465,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
|||||||
p1.serialize()
|
p1.serialize()
|
||||||
print(len(p0.data), p0.data)
|
print(len(p0.data), p0.data)
|
||||||
print(len(p1.data), p1.data)
|
print(len(p1.data), p1.data)
|
||||||
eq_(p0.data, p1.data)
|
self.assertEqual(p0.data, p1.data)
|
||||||
|
|
||||||
def test_to_string(self):
|
def test_to_string(self):
|
||||||
vrrpv3_values = {'version': self.version,
|
vrrpv3_values = {'version': self.version,
|
||||||
@ -490,5 +484,5 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
|||||||
if k in vrrpv3_values])
|
if k in vrrpv3_values])
|
||||||
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
||||||
|
|
||||||
eq_(str(self.vrrpv3), vrrpv3_str)
|
self.assertEqual(str(self.vrrpv3), vrrpv3_str)
|
||||||
eq_(repr(self.vrrpv3), vrrpv3_str)
|
self.assertEqual(repr(self.vrrpv3), vrrpv3_str)
|
||||||
|
@ -16,9 +16,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import raises
|
|
||||||
|
|
||||||
from os_ken.lib.packet import ethernet
|
from os_ken.lib.packet import ethernet
|
||||||
from os_ken.lib.packet import vxlan
|
from os_ken.lib.packet import vxlan
|
||||||
|
|
||||||
@ -45,38 +42,37 @@ class Test_vxlan(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
eq_(self.vni, self.pkt.vni)
|
self.assertEqual(self.vni, self.pkt.vni)
|
||||||
|
|
||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
parsed_pkt, next_proto_cls, rest_buf = vxlan.vxlan.parser(self.buf)
|
parsed_pkt, next_proto_cls, rest_buf = vxlan.vxlan.parser(self.buf)
|
||||||
eq_(self.vni, parsed_pkt.vni)
|
self.assertEqual(self.vni, parsed_pkt.vni)
|
||||||
eq_(ethernet.ethernet, next_proto_cls)
|
self.assertEqual(ethernet.ethernet, next_proto_cls)
|
||||||
eq_(b'test_payload', rest_buf)
|
self.assertEqual(b'test_payload', rest_buf)
|
||||||
|
|
||||||
@raises(AssertionError)
|
|
||||||
def test_invalid_flags(self):
|
def test_invalid_flags(self):
|
||||||
invalid_flags_bug = (
|
invalid_flags_bug = (
|
||||||
b'\x00\x00\x00\x00' # all bits are set to zero
|
b'\x00\x00\x00\x00' # all bits are set to zero
|
||||||
b'\x12\x34\x56\x00' # vni = 0x123456 (24 bits)
|
b'\x12\x34\x56\x00' # vni = 0x123456 (24 bits)
|
||||||
)
|
)
|
||||||
vxlan.vxlan.parser(invalid_flags_bug)
|
self.assertRaises(Exception, vxlan.vxlan.parser, invalid_flags_bug)
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
serialized_buf = self.pkt.serialize(payload=None, prev=None)
|
serialized_buf = self.pkt.serialize(payload=None, prev=None)
|
||||||
eq_(self.buf[:vxlan.vxlan._MIN_LEN], serialized_buf)
|
self.assertEqual(self.buf[:vxlan.vxlan._MIN_LEN], serialized_buf)
|
||||||
|
|
||||||
def test_from_jsondict(self):
|
def test_from_jsondict(self):
|
||||||
pkt_from_json = vxlan.vxlan.from_jsondict(
|
pkt_from_json = vxlan.vxlan.from_jsondict(
|
||||||
self.jsondict[vxlan.vxlan.__name__])
|
self.jsondict[vxlan.vxlan.__name__])
|
||||||
eq_(self.vni, pkt_from_json.vni)
|
self.assertEqual(self.vni, pkt_from_json.vni)
|
||||||
|
|
||||||
def test_to_jsondict(self):
|
def test_to_jsondict(self):
|
||||||
jsondict_from_pkt = self.pkt.to_jsondict()
|
jsondict_from_pkt = self.pkt.to_jsondict()
|
||||||
eq_(self.jsondict, jsondict_from_pkt)
|
self.assertEqual(self.jsondict, jsondict_from_pkt)
|
||||||
|
|
||||||
def test_vni_from_bin(self):
|
def test_vni_from_bin(self):
|
||||||
vni = vxlan.vni_from_bin(b'\x12\x34\x56')
|
vni = vxlan.vni_from_bin(b'\x12\x34\x56')
|
||||||
eq_(self.vni, vni)
|
self.assertEqual(self.vni, vni)
|
||||||
|
|
||||||
def test_vni_to_bin(self):
|
def test_vni_to_bin(self):
|
||||||
eq_(b'\x12\x34\x56', vxlan.vni_to_bin(self.vni))
|
self.assertEqual(b'\x12\x34\x56', vxlan.vni_to_bin(self.vni))
|
||||||
|
@ -19,9 +19,6 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
from nose.tools import ok_
|
|
||||||
from nose.tools import raises
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from os_ken.lib import pcaplib
|
from os_ken.lib import pcaplib
|
||||||
@ -45,8 +42,7 @@ class Test_zebra(unittest.TestCase):
|
|||||||
Test case for os_ken.lib.packet.zebra.
|
Test case for os_ken.lib.packet.zebra.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
def _test_pcap_single(self, f):
|
||||||
def _test_pcap_single(f):
|
|
||||||
zebra_pcap_file = os.path.join(PCAP_DATA_DIR, f + '.pcap')
|
zebra_pcap_file = os.path.join(PCAP_DATA_DIR, f + '.pcap')
|
||||||
# print('*** testing %s' % zebra_pcap_file)
|
# print('*** testing %s' % zebra_pcap_file)
|
||||||
|
|
||||||
@ -55,15 +51,15 @@ class Test_zebra(unittest.TestCase):
|
|||||||
pkt = packet.Packet(buf)
|
pkt = packet.Packet(buf)
|
||||||
zebra_pkts = pkt.get_protocols(zebra.ZebraMessage)
|
zebra_pkts = pkt.get_protocols(zebra.ZebraMessage)
|
||||||
for zebra_pkt in zebra_pkts:
|
for zebra_pkt in zebra_pkts:
|
||||||
ok_(isinstance(zebra_pkt, zebra.ZebraMessage),
|
self.assertTrue(isinstance(zebra_pkt, zebra.ZebraMessage),
|
||||||
'Failed to parse Zebra message: %s' % pkt)
|
'Failed to parse Zebra message: %s' % pkt)
|
||||||
ok_(not isinstance(pkt.protocols[-1],
|
self.assertTrue(not isinstance(pkt.protocols[-1],
|
||||||
(six.binary_type, bytearray)),
|
(six.binary_type, bytearray)),
|
||||||
'Some messages could not be parsed in %s: %s' % (f, pkt))
|
'Some messages could not be parsed in %s: %s' % (f, pkt))
|
||||||
|
|
||||||
# Checks if Zebra message can be serialized as expected.
|
# Checks if Zebra message can be serialized as expected.
|
||||||
pkt.serialize()
|
pkt.serialize()
|
||||||
eq_(binary_str(buf), binary_str(pkt.data))
|
self.assertEqual(binary_str(buf), binary_str(pkt.data))
|
||||||
|
|
||||||
def test_pcap_quagga(self):
|
def test_pcap_quagga(self):
|
||||||
files = [
|
files = [
|
||||||
@ -87,19 +83,17 @@ class Test_zebra(unittest.TestCase):
|
|||||||
class TestZebraMessage(unittest.TestCase):
|
class TestZebraMessage(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_header_size(self):
|
def test_get_header_size(self):
|
||||||
eq_(zebra.ZebraMessage.V0_HEADER_SIZE,
|
self.assertEqual(zebra.ZebraMessage.V0_HEADER_SIZE,
|
||||||
zebra.ZebraMessage.get_header_size(0))
|
zebra.ZebraMessage.get_header_size(0))
|
||||||
eq_(zebra.ZebraMessage.V1_HEADER_SIZE,
|
self.assertEqual(zebra.ZebraMessage.V1_HEADER_SIZE,
|
||||||
zebra.ZebraMessage.get_header_size(2))
|
zebra.ZebraMessage.get_header_size(2))
|
||||||
eq_(zebra.ZebraMessage.V3_HEADER_SIZE,
|
self.assertEqual(zebra.ZebraMessage.V3_HEADER_SIZE,
|
||||||
zebra.ZebraMessage.get_header_size(3))
|
zebra.ZebraMessage.get_header_size(3))
|
||||||
eq_(zebra.ZebraMessage.V3_HEADER_SIZE,
|
self.assertEqual(zebra.ZebraMessage.V3_HEADER_SIZE,
|
||||||
zebra.ZebraMessage.get_header_size(4))
|
zebra.ZebraMessage.get_header_size(4))
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_get_header_size_invalid_version(self):
|
def test_get_header_size_invalid_version(self):
|
||||||
eq_(zebra.ZebraMessage.V0_HEADER_SIZE,
|
self.assertRaises(ValueError, zebra.ZebraMessage.get_header_size, 0xff)
|
||||||
zebra.ZebraMessage.get_header_size(0xff))
|
|
||||||
|
|
||||||
|
|
||||||
class TestZebraRedistributeAdd(unittest.TestCase):
|
class TestZebraRedistributeAdd(unittest.TestCase):
|
||||||
@ -111,11 +105,11 @@ class TestZebraRedistributeAdd(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraRedistributeAdd.parse(self.buf, version=3)
|
body = zebra.ZebraRedistributeAdd.parse(self.buf, version=3)
|
||||||
|
|
||||||
eq_(self.route_type, body.route_type)
|
self.assertEqual(self.route_type, body.route_type)
|
||||||
|
|
||||||
buf = body.serialize(version=3)
|
buf = body.serialize(version=3)
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraIPv4ImportLookup(unittest.TestCase):
|
class TestZebraIPv4ImportLookup(unittest.TestCase):
|
||||||
@ -131,14 +125,14 @@ class TestZebraIPv4ImportLookup(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraIPv4ImportLookup.parse(self.buf)
|
body = zebra.ZebraIPv4ImportLookup.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
eq_(self.metric, body.metric)
|
self.assertEqual(self.metric, body.metric)
|
||||||
eq_(self.nexthop_num, len(body.nexthops))
|
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||||
eq_(self.from_zebra, body.from_zebra)
|
self.assertEqual(self.from_zebra, body.from_zebra)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraIPv4ImportLookupFromZebra(unittest.TestCase):
|
class TestZebraIPv4ImportLookupFromZebra(unittest.TestCase):
|
||||||
@ -159,16 +153,16 @@ class TestZebraIPv4ImportLookupFromZebra(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraIPv4ImportLookup.parse_from_zebra(self.buf)
|
body = zebra.ZebraIPv4ImportLookup.parse_from_zebra(self.buf)
|
||||||
|
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
eq_(self.metric, body.metric)
|
self.assertEqual(self.metric, body.metric)
|
||||||
eq_(self.nexthop_num, len(body.nexthops))
|
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||||
eq_(self.from_zebra, body.from_zebra)
|
self.assertEqual(self.from_zebra, body.from_zebra)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraIPv4NexthopLookupMRib(unittest.TestCase):
|
class TestZebraIPv4NexthopLookupMRib(unittest.TestCase):
|
||||||
@ -183,14 +177,14 @@ class TestZebraIPv4NexthopLookupMRib(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.addr, body.addr)
|
self.assertEqual(self.addr, body.addr)
|
||||||
eq_(self.distance, body.distance)
|
self.assertEqual(self.distance, body.distance)
|
||||||
eq_(self.metric, body.metric)
|
self.assertEqual(self.metric, body.metric)
|
||||||
eq_(self.nexthop_num, len(body.nexthops))
|
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraIPv4NexthopLookupMRibFromZebra(unittest.TestCase):
|
class TestZebraIPv4NexthopLookupMRibFromZebra(unittest.TestCase):
|
||||||
@ -212,16 +206,16 @@ class TestZebraIPv4NexthopLookupMRibFromZebra(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.addr, body.addr)
|
self.assertEqual(self.addr, body.addr)
|
||||||
eq_(self.distance, body.distance)
|
self.assertEqual(self.distance, body.distance)
|
||||||
eq_(self.metric, body.metric)
|
self.assertEqual(self.metric, body.metric)
|
||||||
eq_(self.nexthop_num, len(body.nexthops))
|
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraNexthopUpdateIPv6(unittest.TestCase):
|
class TestZebraNexthopUpdateIPv6(unittest.TestCase):
|
||||||
@ -246,16 +240,16 @@ class TestZebraNexthopUpdateIPv6(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraNexthopUpdate.parse(self.buf)
|
body = zebra.ZebraNexthopUpdate.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.family, body.family)
|
self.assertEqual(self.family, body.family)
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
eq_(self.metric, body.metric)
|
self.assertEqual(self.metric, body.metric)
|
||||||
eq_(self.nexthop_num, len(body.nexthops))
|
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraInterfaceNbrAddressAdd(unittest.TestCase):
|
class TestZebraInterfaceNbrAddressAdd(unittest.TestCase):
|
||||||
@ -273,13 +267,13 @@ class TestZebraInterfaceNbrAddressAdd(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraInterfaceNbrAddressAdd.parse(self.buf)
|
body = zebra.ZebraInterfaceNbrAddressAdd.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.ifindex, body.ifindex)
|
self.assertEqual(self.ifindex, body.ifindex)
|
||||||
eq_(self.family, body.family)
|
self.assertEqual(self.family, body.family)
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraInterfaceBfdDestinationUpdate(unittest.TestCase):
|
class TestZebraInterfaceBfdDestinationUpdate(unittest.TestCase):
|
||||||
@ -304,16 +298,16 @@ class TestZebraInterfaceBfdDestinationUpdate(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraInterfaceBfdDestinationUpdate.parse(self.buf)
|
body = zebra.ZebraInterfaceBfdDestinationUpdate.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.ifindex, body.ifindex)
|
self.assertEqual(self.ifindex, body.ifindex)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.status, body.status)
|
self.assertEqual(self.status, body.status)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationRegisterMultiHopEnabled(unittest.TestCase):
|
class TestZebraBfdDestinationRegisterMultiHopEnabled(unittest.TestCase):
|
||||||
@ -345,21 +339,21 @@ class TestZebraBfdDestinationRegisterMultiHopEnabled(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||||
eq_(self.detect_mult, body.detect_mult)
|
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationRegisterMultiHopDisabled(unittest.TestCase):
|
class TestZebraBfdDestinationRegisterMultiHopDisabled(unittest.TestCase):
|
||||||
@ -392,21 +386,21 @@ class TestZebraBfdDestinationRegisterMultiHopDisabled(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||||
eq_(self.detect_mult, body.detect_mult)
|
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationRegisterMultiHopEnabledIPv6(unittest.TestCase):
|
class TestZebraBfdDestinationRegisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||||
@ -444,21 +438,21 @@ class TestZebraBfdDestinationRegisterMultiHopEnabledIPv6(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||||
eq_(self.detect_mult, body.detect_mult)
|
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationDeregisterMultiHopEnabled(unittest.TestCase):
|
class TestZebraBfdDestinationDeregisterMultiHopEnabled(unittest.TestCase):
|
||||||
@ -484,18 +478,18 @@ class TestZebraBfdDestinationDeregisterMultiHopEnabled(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationDeregisterMultiHopDisabled(unittest.TestCase):
|
class TestZebraBfdDestinationDeregisterMultiHopDisabled(unittest.TestCase):
|
||||||
@ -522,18 +516,18 @@ class TestZebraBfdDestinationDeregisterMultiHopDisabled(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraBfdDestinationDeregisterMultiHopEnabledIPv6(unittest.TestCase):
|
class TestZebraBfdDestinationDeregisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||||
@ -565,18 +559,18 @@ class TestZebraBfdDestinationDeregisterMultiHopEnabledIPv6(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.pid, body.pid)
|
self.assertEqual(self.pid, body.pid)
|
||||||
eq_(self.dst_family, body.dst_family)
|
self.assertEqual(self.dst_family, body.dst_family)
|
||||||
eq_(self.dst_prefix, body.dst_prefix)
|
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||||
eq_(self.multi_hop, body.multi_hop)
|
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||||
eq_(self.src_family, body.src_family)
|
self.assertEqual(self.src_family, body.src_family)
|
||||||
eq_(self.src_prefix, body.src_prefix)
|
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||||
eq_(self.ifname, body.ifname)
|
self.assertEqual(self.ifname, body.ifname)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraVrfAdd(unittest.TestCase):
|
class TestZebraVrfAdd(unittest.TestCase):
|
||||||
@ -597,11 +591,11 @@ class TestZebraVrfAdd(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraVrfAdd.parse(self.buf)
|
body = zebra.ZebraVrfAdd.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.vrf_name, body.vrf_name)
|
self.assertEqual(self.vrf_name, body.vrf_name)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraInterfaceVrfUpdate(unittest.TestCase):
|
class TestZebraInterfaceVrfUpdate(unittest.TestCase):
|
||||||
@ -616,12 +610,12 @@ class TestZebraInterfaceVrfUpdate(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraInterfaceVrfUpdate.parse(self.buf)
|
body = zebra.ZebraInterfaceVrfUpdate.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.ifindex, body.ifindex)
|
self.assertEqual(self.ifindex, body.ifindex)
|
||||||
eq_(self.vrf_id, body.vrf_id)
|
self.assertEqual(self.vrf_id, body.vrf_id)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraInterfaceEnableRadv(unittest.TestCase):
|
class TestZebraInterfaceEnableRadv(unittest.TestCase):
|
||||||
@ -636,12 +630,12 @@ class TestZebraInterfaceEnableRadv(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraInterfaceEnableRadv.parse(self.buf)
|
body = zebra.ZebraInterfaceEnableRadv.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.ifindex, body.ifindex)
|
self.assertEqual(self.ifindex, body.ifindex)
|
||||||
eq_(self.interval, body.interval)
|
self.assertEqual(self.interval, body.interval)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraMplsLabelsAddIPv4(unittest.TestCase):
|
class TestZebraMplsLabelsAddIPv4(unittest.TestCase):
|
||||||
@ -667,17 +661,17 @@ class TestZebraMplsLabelsAddIPv4(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.route_type, body.route_type)
|
self.assertEqual(self.route_type, body.route_type)
|
||||||
eq_(self.family, body.family)
|
self.assertEqual(self.family, body.family)
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
eq_(self.gate_addr, body.gate_addr)
|
self.assertEqual(self.gate_addr, body.gate_addr)
|
||||||
eq_(self.distance, body.distance)
|
self.assertEqual(self.distance, body.distance)
|
||||||
eq_(self.in_label, body.in_label)
|
self.assertEqual(self.in_label, body.in_label)
|
||||||
eq_(self.out_label, body.out_label)
|
self.assertEqual(self.out_label, body.out_label)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
|
||||||
|
|
||||||
class TestZebraMplsLabelsAddIPv6(unittest.TestCase):
|
class TestZebraMplsLabelsAddIPv6(unittest.TestCase):
|
||||||
@ -709,14 +703,14 @@ class TestZebraMplsLabelsAddIPv6(unittest.TestCase):
|
|||||||
def test_parser(self):
|
def test_parser(self):
|
||||||
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
||||||
|
|
||||||
eq_(self.route_type, body.route_type)
|
self.assertEqual(self.route_type, body.route_type)
|
||||||
eq_(self.family, body.family)
|
self.assertEqual(self.family, body.family)
|
||||||
eq_(self.prefix, body.prefix)
|
self.assertEqual(self.prefix, body.prefix)
|
||||||
eq_(self.gate_addr, body.gate_addr)
|
self.assertEqual(self.gate_addr, body.gate_addr)
|
||||||
eq_(self.distance, body.distance)
|
self.assertEqual(self.distance, body.distance)
|
||||||
eq_(self.in_label, body.in_label)
|
self.assertEqual(self.in_label, body.in_label)
|
||||||
eq_(self.out_label, body.out_label)
|
self.assertEqual(self.out_label, body.out_label)
|
||||||
|
|
||||||
buf = body.serialize()
|
buf = body.serialize()
|
||||||
|
|
||||||
eq_(binary_str(self.buf), binary_str(buf))
|
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from nose.tools import ok_, eq_
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('os_ken.tests.test_sample1')
|
|
||||||
|
|
||||||
|
|
||||||
class TestSample1(unittest.TestCase):
|
|
||||||
|
|
||||||
def testS1Func1(self):
|
|
||||||
LOG.debug('testS1Func1 - START')
|
|
||||||
ok_(True)
|
|
||||||
|
|
||||||
def testS1Func2(self):
|
|
||||||
ok_(True)
|
|
@ -1,13 +0,0 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from nose.tools import ok_, eq_
|
|
||||||
|
|
||||||
|
|
||||||
class TestSample2(unittest.TestCase):
|
|
||||||
|
|
||||||
def testS2Func1(self):
|
|
||||||
ok_(True)
|
|
||||||
|
|
||||||
def testS2Func2(self):
|
|
||||||
ok_(True)
|
|
@ -18,14 +18,11 @@ import logging
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import ok_, eq_, raises
|
|
||||||
|
|
||||||
from os_ken.lib.packet.bgp import BGPPathAttributeOrigin
|
from os_ken.lib.packet.bgp import BGPPathAttributeOrigin
|
||||||
from os_ken.lib.packet.bgp import BGPPathAttributeAsPath
|
from os_ken.lib.packet.bgp import BGPPathAttributeAsPath
|
||||||
from os_ken.lib.packet.bgp import BGP_ATTR_ORIGIN_IGP
|
from os_ken.lib.packet.bgp import BGP_ATTR_ORIGIN_IGP
|
||||||
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
|
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
|
||||||
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
|
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
|
||||||
from os_ken.lib.packet.bgp import BGP_ATTR_TYPE_EXTENDED_COMMUNITIES
|
|
||||||
from os_ken.lib.packet.bgp import IPAddrPrefix
|
from os_ken.lib.packet.bgp import IPAddrPrefix
|
||||||
from os_ken.lib.packet.bgp import IP6AddrPrefix
|
from os_ken.lib.packet.bgp import IP6AddrPrefix
|
||||||
from os_ken.lib.packet.bgp import EvpnArbitraryEsi
|
from os_ken.lib.packet.bgp import EvpnArbitraryEsi
|
||||||
@ -33,21 +30,13 @@ from os_ken.lib.packet.bgp import EvpnLACPEsi
|
|||||||
from os_ken.lib.packet.bgp import EvpnEthernetAutoDiscoveryNLRI
|
from os_ken.lib.packet.bgp import EvpnEthernetAutoDiscoveryNLRI
|
||||||
from os_ken.lib.packet.bgp import EvpnMacIPAdvertisementNLRI
|
from os_ken.lib.packet.bgp import EvpnMacIPAdvertisementNLRI
|
||||||
from os_ken.lib.packet.bgp import EvpnInclusiveMulticastEthernetTagNLRI
|
from os_ken.lib.packet.bgp import EvpnInclusiveMulticastEthernetTagNLRI
|
||||||
from os_ken.lib.packet.bgp import FlowSpecIPv4NLRI
|
|
||||||
from os_ken.lib.packet.bgp import BGPPathAttributeExtendedCommunities
|
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import EVPN_MAX_ET
|
from os_ken.services.protocols.bgp.bgpspeaker import EVPN_MAX_ET
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import ESI_TYPE_LACP
|
from os_ken.services.protocols.bgp.bgpspeaker import ESI_TYPE_LACP
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import FLOWSPEC_FAMILY_IPV4
|
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import FLOWSPEC_FAMILY_VPNV4
|
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import FLOWSPEC_TA_SAMPLE
|
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import FLOWSPEC_TA_TERMINAL
|
|
||||||
from os_ken.services.protocols.bgp.core import BgpCoreError
|
from os_ken.services.protocols.bgp.core import BgpCoreError
|
||||||
from os_ken.services.protocols.bgp.core_managers import table_manager
|
from os_ken.services.protocols.bgp.core_managers import table_manager
|
||||||
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV4
|
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV4
|
||||||
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV6
|
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV6
|
||||||
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_L2_EVPN
|
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_L2_EVPN
|
||||||
from os_ken.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV4_FLOWSPEC
|
|
||||||
from os_ken.services.protocols.bgp.utils.bgp import create_v4flowspec_actions
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -81,17 +70,17 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
|
|
||||||
# Check
|
# Check
|
||||||
call_args_list = vrf_table_mock.insert_vrf_path.call_args_list
|
call_args_list = vrf_table_mock.insert_vrf_path.call_args_list
|
||||||
ok_(len(call_args_list) == 1) # insert_vrf_path should be called once
|
self.assertTrue(len(call_args_list) == 1) # insert_vrf_path should be called once
|
||||||
args, kwargs = call_args_list[0]
|
args, kwargs = call_args_list[0]
|
||||||
ok_(len(args) == 0) # no positional argument
|
self.assertTrue(len(args) == 0) # no positional argument
|
||||||
eq_(str(prefix_inst), str(kwargs['nlri']))
|
self.assertEqual(str(prefix_inst), str(kwargs['nlri']))
|
||||||
eq_(is_withdraw, kwargs['is_withdraw'])
|
self.assertEqual(is_withdraw, kwargs['is_withdraw'])
|
||||||
if is_withdraw:
|
if is_withdraw:
|
||||||
eq_(None, kwargs['next_hop'])
|
self.assertEqual(None, kwargs['next_hop'])
|
||||||
eq_(False, kwargs['gen_lbl'])
|
self.assertEqual(False, kwargs['gen_lbl'])
|
||||||
else:
|
else:
|
||||||
eq_(next_hop, kwargs['next_hop'])
|
self.assertEqual(next_hop, kwargs['next_hop'])
|
||||||
eq_(True, kwargs['gen_lbl'])
|
self.assertEqual(True, kwargs['gen_lbl'])
|
||||||
|
|
||||||
def test_update_vrf_table_ipv4(self):
|
def test_update_vrf_table_ipv4(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
@ -233,13 +222,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
|
|
||||||
# Check
|
# Check
|
||||||
call_args_list = vrf_table_mock.insert_vrf_path.call_args_list
|
call_args_list = vrf_table_mock.insert_vrf_path.call_args_list
|
||||||
ok_(len(call_args_list) == 1) # insert_vrf_path should be called once
|
self.assertTrue(
|
||||||
|
len(call_args_list) == 1) # insert_vrf_path should be called once
|
||||||
args, kwargs = call_args_list[0]
|
args, kwargs = call_args_list[0]
|
||||||
ok_(len(args) == 0) # no positional argument
|
self.assertTrue(len(args) == 0) # no positional argument
|
||||||
eq_(str(prefix_inst), str(kwargs['nlri']))
|
self.assertEqual(str(prefix_inst), str(kwargs['nlri']))
|
||||||
eq_(next_hop, kwargs['next_hop'])
|
self.assertEqual(next_hop, kwargs['next_hop'])
|
||||||
eq_(False, kwargs['gen_lbl']) # should not generate MPLS labels
|
self.assertEqual(
|
||||||
eq_(tunnel_type, kwargs['tunnel_type'])
|
False, kwargs['gen_lbl']) # should not generate MPLS labels
|
||||||
|
self.assertEqual(tunnel_type, kwargs['tunnel_type'])
|
||||||
|
|
||||||
def test_update_vrf_table_ipv4_withdraw(self):
|
def test_update_vrf_table_ipv4_withdraw(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
@ -257,7 +248,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
next_hop, route_family, route_type,
|
next_hop, route_family, route_type,
|
||||||
is_withdraw=True, **kwargs)
|
is_withdraw=True, **kwargs)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||||
mock.MagicMock(return_value=None))
|
mock.MagicMock(return_value=None))
|
||||||
@ -277,15 +267,11 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
tbl_mng._tables = {} # no table
|
tbl_mng._tables = {} # no table
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
tbl_mng.update_vrf_table(
|
self.assertRaises(BgpCoreError, tbl_mng.update_vrf_table,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist, prefix=prefix_str,
|
||||||
prefix=prefix_str,
|
next_hop=next_hop, route_family=route_family,
|
||||||
next_hop=next_hop,
|
route_type=route_type, **kwargs)
|
||||||
route_family=route_family,
|
|
||||||
route_type=route_type,
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_vrf_table_invalid_next_hop(self):
|
def test_update_vrf_table_invalid_next_hop(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
route_dist = '65000:100'
|
route_dist = '65000:100'
|
||||||
@ -298,11 +284,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
route_type = None # should be ignored
|
route_type = None # should be ignored
|
||||||
kwargs = {} # should be ignored
|
kwargs = {} # should be ignored
|
||||||
|
|
||||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||||
next_hop, route_family, route_type,
|
prefix_inst, route_dist, prefix_str, next_hop,
|
||||||
**kwargs)
|
route_family, route_type, **kwargs)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_vrf_table_invalid_ipv4_prefix(self):
|
def test_update_vrf_table_invalid_ipv4_prefix(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
route_dist = '65000:100'
|
route_dist = '65000:100'
|
||||||
@ -315,11 +300,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
route_type = None # should be ignored
|
route_type = None # should be ignored
|
||||||
kwargs = {} # should be ignored
|
kwargs = {} # should be ignored
|
||||||
|
|
||||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||||
next_hop, route_family, route_type,
|
prefix_inst, route_dist, prefix_str,
|
||||||
**kwargs)
|
next_hop, route_family, route_type, **kwargs)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_vrf_table_invalid_ipv6_prefix(self):
|
def test_update_vrf_table_invalid_ipv6_prefix(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
route_dist = '65000:100'
|
route_dist = '65000:100'
|
||||||
@ -332,11 +316,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
route_type = None # should be ignored
|
route_type = None # should be ignored
|
||||||
kwargs = {} # should be ignored
|
kwargs = {} # should be ignored
|
||||||
|
|
||||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||||
next_hop, route_family, route_type,
|
prefix_inst, route_dist, prefix_str, next_hop,
|
||||||
**kwargs)
|
route_family, route_type, **kwargs)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_vrf_table_invalid_route_family(self):
|
def test_update_vrf_table_invalid_route_family(self):
|
||||||
# Prepare test data
|
# Prepare test data
|
||||||
route_dist = '65000:100'
|
route_dist = '65000:100'
|
||||||
@ -349,9 +332,9 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
route_type = None # should be ignored
|
route_type = None # should be ignored
|
||||||
kwargs = {} # should be ignored
|
kwargs = {} # should be ignored
|
||||||
|
|
||||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||||
next_hop, route_family, route_type,
|
prefix_inst, route_dist, prefix_str, next_hop,
|
||||||
**kwargs)
|
route_family, route_type, **kwargs)
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||||
@ -380,15 +363,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
|
|
||||||
# Check
|
# Check
|
||||||
call_args_list = learn_path_mock.call_args_list
|
call_args_list = learn_path_mock.call_args_list
|
||||||
ok_(len(call_args_list) == 1) # learn_path should be called once
|
self.assertTrue(len(call_args_list) == 1) # learn_path should be called once
|
||||||
args, kwargs = call_args_list[0]
|
args, kwargs = call_args_list[0]
|
||||||
ok_(len(kwargs) == 0) # no keyword argument
|
self.assertTrue(len(kwargs) == 0) # no keyword argument
|
||||||
output_path = args[0]
|
output_path = args[0]
|
||||||
eq_(None, output_path.source)
|
self.assertEqual(None, output_path.source)
|
||||||
eq_(prefix, output_path.nlri.prefix)
|
self.assertEqual(prefix, output_path.nlri.prefix)
|
||||||
eq_(pathattrs, str(output_path.pathattr_map))
|
self.assertEqual(pathattrs, str(output_path.pathattr_map))
|
||||||
eq_(expected_next_hop, output_path.nexthop)
|
self.assertEqual(expected_next_hop, output_path.nexthop)
|
||||||
eq_(is_withdraw, output_path.is_withdraw)
|
self.assertEqual(is_withdraw, output_path.is_withdraw)
|
||||||
|
|
||||||
def test_update_global_table_ipv4(self):
|
def test_update_global_table_ipv4(self):
|
||||||
self._test_update_global_table(
|
self._test_update_global_table(
|
||||||
@ -460,12 +443,12 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
|
|
||||||
# Check
|
# Check
|
||||||
call_args_list = vrf_table_mock.insert_vrffs_path.call_args_list
|
call_args_list = vrf_table_mock.insert_vrffs_path.call_args_list
|
||||||
ok_(len(
|
self.assertTrue(len(
|
||||||
call_args_list) == 1) # insert_vrffs_path should be called once
|
call_args_list) == 1) # insert_vrffs_path should be called once
|
||||||
args, kwargs = call_args_list[0]
|
args, kwargs = call_args_list[0]
|
||||||
ok_(len(args) == 0) # no positional argument
|
self.assertTrue(len(args) == 0) # no positional argument
|
||||||
eq_(prefix, kwargs['nlri'].prefix)
|
self.assertEqual(prefix, kwargs['nlri'].prefix)
|
||||||
eq_(is_withdraw, kwargs['is_withdraw'])
|
self.assertEqual(is_withdraw, kwargs['is_withdraw'])
|
||||||
|
|
||||||
def test_update_flowspec_vrf_table_vpnv4(self):
|
def test_update_flowspec_vrf_table_vpnv4(self):
|
||||||
flowspec_family = 'vpnv4fs'
|
flowspec_family = 'vpnv4fs'
|
||||||
@ -510,7 +493,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_vpnv4_invalid_actions(self):
|
def test_update_flowspec_vrf_table_vpnv4_invalid_actions(self):
|
||||||
flowspec_family = 'vpnv4fs'
|
flowspec_family = 'vpnv4fs'
|
||||||
route_family = 'ipv4fs'
|
route_family = 'ipv4fs'
|
||||||
@ -525,17 +507,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_vpnv4_invalid_flowspec_family(self):
|
def test_update_flowspec_vrf_table_vpnv4_invalid_flowspec_family(self):
|
||||||
flowspec_family = 'invalid'
|
flowspec_family = 'invalid'
|
||||||
route_family = 'ipv4fs'
|
route_family = 'ipv4fs'
|
||||||
@ -545,16 +525,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_vpnv4_invalid_route_family(self):
|
def test_update_flowspec_vrf_table_vpnv4_invalid_route_family(self):
|
||||||
flowspec_family = 'vpnv4fs'
|
flowspec_family = 'vpnv4fs'
|
||||||
route_family = 'invalid'
|
route_family = 'invalid'
|
||||||
@ -564,14 +542,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False)
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||||
@ -594,14 +571,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
|
|
||||||
# Check
|
# Check
|
||||||
call_args_list = learn_path_mock.call_args_list
|
call_args_list = learn_path_mock.call_args_list
|
||||||
ok_(len(call_args_list) == 1) # learn_path should be called once
|
self.assertTrue(len(call_args_list) == 1) # learn_path should be called once
|
||||||
args, kwargs = call_args_list[0]
|
args, kwargs = call_args_list[0]
|
||||||
ok_(len(kwargs) == 0) # no keyword argument
|
self.assertTrue(len(kwargs) == 0) # no keyword argument
|
||||||
output_path = args[0]
|
output_path = args[0]
|
||||||
eq_(None, output_path.source)
|
self.assertEqual(None, output_path.source)
|
||||||
eq_(prefix, output_path.nlri.prefix)
|
self.assertEqual(prefix, output_path.nlri.prefix)
|
||||||
eq_(None, output_path.nexthop)
|
self.assertEqual(None, output_path.nexthop)
|
||||||
eq_(is_withdraw, output_path.is_withdraw)
|
self.assertEqual(is_withdraw, output_path.is_withdraw)
|
||||||
|
|
||||||
def test_update_flowspec_global_table_ipv4(self):
|
def test_update_flowspec_global_table_ipv4(self):
|
||||||
flowspec_family = 'ipv4fs'
|
flowspec_family = 'ipv4fs'
|
||||||
@ -638,7 +615,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_global_table_ipv4_invalid_actions(self):
|
def test_update_flowspec_global_table_ipv4_invalid_actions(self):
|
||||||
flowspec_family = 'ipv4fs'
|
flowspec_family = 'ipv4fs'
|
||||||
rules = {
|
rules = {
|
||||||
@ -651,15 +627,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
||||||
|
|
||||||
self._test_update_flowspec_global_table(
|
self.assertRaises(BgpCoreError,
|
||||||
|
self._test_update_flowspec_global_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_global_table_ipv4_invalid_flowspec_family(self):
|
def test_update_flowspec_global_table_ipv4_invalid_flowspec_family(self):
|
||||||
flowspec_family = 'invalid'
|
flowspec_family = 'invalid'
|
||||||
rules = {
|
rules = {
|
||||||
@ -673,13 +648,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
||||||
|
|
||||||
self._test_update_flowspec_global_table(
|
self.assertRaises(BgpCoreError,
|
||||||
|
self._test_update_flowspec_global_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
def test_update_flowspec_global_table_ipv6(self):
|
def test_update_flowspec_global_table_ipv6(self):
|
||||||
flowspec_family = 'ipv6fs'
|
flowspec_family = 'ipv6fs'
|
||||||
@ -716,7 +691,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_global_table_ipv6_invalid_actions(self):
|
def test_update_flowspec_global_table_ipv6_invalid_actions(self):
|
||||||
flowspec_family = 'ipv6fs'
|
flowspec_family = 'ipv6fs'
|
||||||
rules = {
|
rules = {
|
||||||
@ -729,15 +703,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||||
|
|
||||||
self._test_update_flowspec_global_table(
|
self.assertRaises(BgpCoreError,
|
||||||
|
self._test_update_flowspec_global_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_global_table_ipv6_invalid_flowspec_family(self):
|
def test_update_flowspec_global_table_ipv6_invalid_flowspec_family(self):
|
||||||
flowspec_family = 'invalid'
|
flowspec_family = 'invalid'
|
||||||
rules = {
|
rules = {
|
||||||
@ -751,13 +724,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||||
|
|
||||||
self._test_update_flowspec_global_table(
|
self.assertRaises(BgpCoreError,
|
||||||
|
self._test_update_flowspec_global_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
def test_update_flowspec_vrf_table_vpnv6(self):
|
def test_update_flowspec_vrf_table_vpnv6(self):
|
||||||
flowspec_family = 'vpnv6fs'
|
flowspec_family = 'vpnv6fs'
|
||||||
@ -802,7 +775,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_vpnv6_invalid_actions(self):
|
def test_update_flowspec_vrf_table_vpnv6_invalid_actions(self):
|
||||||
flowspec_family = 'vpnv6fs'
|
flowspec_family = 'vpnv6fs'
|
||||||
route_family = 'ipv6fs'
|
route_family = 'ipv6fs'
|
||||||
@ -817,17 +789,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv6fs(dst_prefix:2001::3/128/32)'
|
prefix = 'ipv6fs(dst_prefix:2001::3/128/32)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_vpnv6_invalid_route_family(self):
|
def test_update_flowspec_vrf_table_vpnv6_invalid_route_family(self):
|
||||||
flowspec_family = 'vpnv6fs'
|
flowspec_family = 'vpnv6fs'
|
||||||
route_family = 'invalid'
|
route_family = 'invalid'
|
||||||
@ -837,14 +807,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False)
|
||||||
)
|
|
||||||
|
|
||||||
def test_update_flowspec_vrf_table_l2vpn(self):
|
def test_update_flowspec_vrf_table_l2vpn(self):
|
||||||
flowspec_family = 'l2vpnfs'
|
flowspec_family = 'l2vpnfs'
|
||||||
@ -889,7 +858,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_l2vpn_invalid_actions(self):
|
def test_update_flowspec_vrf_table_l2vpn_invalid_actions(self):
|
||||||
flowspec_family = 'l2vpnfs'
|
flowspec_family = 'l2vpnfs'
|
||||||
route_family = 'l2vpnfs'
|
route_family = 'l2vpnfs'
|
||||||
@ -904,17 +872,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False,
|
||||||
actions=actions,
|
actions=actions)
|
||||||
)
|
|
||||||
|
|
||||||
@raises(BgpCoreError)
|
|
||||||
def test_update_flowspec_vrf_table_l2vpn_invalid_route_family(self):
|
def test_update_flowspec_vrf_table_l2vpn_invalid_route_family(self):
|
||||||
flowspec_family = 'l2vpnfs'
|
flowspec_family = 'l2vpnfs'
|
||||||
route_family = 'invalid'
|
route_family = 'invalid'
|
||||||
@ -924,11 +890,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
||||||
|
|
||||||
self._test_update_flowspec_vrf_table(
|
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||||
flowspec_family=flowspec_family,
|
flowspec_family=flowspec_family,
|
||||||
route_family=route_family,
|
route_family=route_family,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
rules=rules,
|
rules=rules,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
is_withdraw=False,
|
is_withdraw=False)
|
||||||
)
|
|
||||||
|
@ -17,8 +17,6 @@ import logging
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import raises
|
|
||||||
|
|
||||||
from os_ken.services.protocols.bgp import bgpspeaker
|
from os_ken.services.protocols.bgp import bgpspeaker
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import EVPN_MAX_ET
|
from os_ken.services.protocols.bgp.bgpspeaker import EVPN_MAX_ET
|
||||||
from os_ken.services.protocols.bgp.bgpspeaker import ESI_TYPE_LACP
|
from os_ken.services.protocols.bgp.bgpspeaker import ESI_TYPE_LACP
|
||||||
@ -392,7 +390,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
mock_call.assert_called_with(
|
mock_call.assert_called_with(
|
||||||
'evpn_prefix.add_local', **expected_kwargs)
|
'evpn_prefix.add_local', **expected_kwargs)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
mock.MagicMock(return_value=None))
|
mock.MagicMock(return_value=None))
|
||||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
||||||
@ -408,19 +405,14 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
|
|
||||||
# Test
|
# Test
|
||||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||||
speaker.evpn_prefix_add(
|
self.assertRaises(ValueError, speaker.evpn_prefix_add,
|
||||||
route_type=route_type,
|
route_type=route_type,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
esi=esi,
|
esi=esi,
|
||||||
ethernet_tag_id=ethernet_tag_id,
|
ethernet_tag_id=ethernet_tag_id,
|
||||||
mac_addr=mac_addr,
|
mac_addr=mac_addr,
|
||||||
ip_addr=ip_addr,
|
ip_addr=ip_addr,
|
||||||
next_hop=next_hop,
|
next_hop=next_hop)
|
||||||
)
|
|
||||||
|
|
||||||
# Check
|
|
||||||
mock_call.assert_called_with(
|
|
||||||
'evpn_prefix.add_local', 'Invalid arguments detected')
|
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
@ -523,7 +515,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
mock_call.assert_called_with(
|
mock_call.assert_called_with(
|
||||||
'evpn_prefix.delete_local', **expected_kwargs)
|
'evpn_prefix.delete_local', **expected_kwargs)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
mock.MagicMock(return_value=None))
|
mock.MagicMock(return_value=None))
|
||||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
||||||
@ -538,18 +529,13 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
|
|
||||||
# Test
|
# Test
|
||||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||||
speaker.evpn_prefix_del(
|
self.assertRaises(ValueError, speaker.evpn_prefix_del,
|
||||||
route_type=route_type,
|
route_type=route_type,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
esi=esi,
|
esi=esi,
|
||||||
ethernet_tag_id=ethernet_tag_id,
|
ethernet_tag_id=ethernet_tag_id,
|
||||||
mac_addr=mac_addr,
|
mac_addr=mac_addr,
|
||||||
ip_addr=ip_addr,
|
ip_addr=ip_addr)
|
||||||
)
|
|
||||||
|
|
||||||
# Check
|
|
||||||
mock_call.assert_called_with(
|
|
||||||
'evpn_prefix.delete_local', 'Invalid arguments detected')
|
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
@ -684,7 +670,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
mock_call.assert_called_with(
|
mock_call.assert_called_with(
|
||||||
'evpn_prefix.add_local', **expected_kwargs)
|
'evpn_prefix.add_local', **expected_kwargs)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
mock.MagicMock(return_value=None))
|
mock.MagicMock(return_value=None))
|
||||||
@ -700,17 +685,12 @@ class Test_BGPSpeaker(unittest.TestCase):
|
|||||||
|
|
||||||
# Test
|
# Test
|
||||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||||
speaker.evpn_prefix_add(
|
self.assertRaises(ValueError, speaker.evpn_prefix_add,
|
||||||
route_type=route_type,
|
route_type=route_type,
|
||||||
route_dist=route_dist,
|
route_dist=route_dist,
|
||||||
ethernet_tag_id=ethernet_tag_id,
|
ethernet_tag_id=ethernet_tag_id,
|
||||||
ip_addr=ip_addr,
|
ip_addr=ip_addr,
|
||||||
pmsi_tunnel_type=pmsi_tunnel_type,
|
pmsi_tunnel_type=pmsi_tunnel_type)
|
||||||
)
|
|
||||||
|
|
||||||
# Check
|
|
||||||
mock_call.assert_called_with(
|
|
||||||
'evpn_prefix.add_local', 'Invalid arguments detected')
|
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||||
|
@ -17,8 +17,6 @@ import logging
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from nose.tools import eq_
|
|
||||||
|
|
||||||
from os_ken.lib.packet import bgp
|
from os_ken.lib.packet import bgp
|
||||||
from os_ken.services.protocols.bgp import peer
|
from os_ken.services.protocols.bgp import peer
|
||||||
|
|
||||||
@ -44,8 +42,8 @@ class Test_Peer(unittest.TestCase):
|
|||||||
output_as_path_attr = _peer._construct_as_path_attr(
|
output_as_path_attr = _peer._construct_as_path_attr(
|
||||||
input_as_path_attr, input_as4_path_attr)
|
input_as_path_attr, input_as4_path_attr)
|
||||||
|
|
||||||
eq_(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
self.assertEqual(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||||
eq_(expected_as_path, output_as_path_attr.path_seg_list)
|
self.assertEqual(expected_as_path, output_as_path_attr.path_seg_list)
|
||||||
|
|
||||||
def test_construct_as_path_attr_sequence_only(self):
|
def test_construct_as_path_attr_sequence_only(self):
|
||||||
# Test Data
|
# Test Data
|
||||||
@ -154,8 +152,8 @@ class Test_Peer(unittest.TestCase):
|
|||||||
output_as_path_attr = _peer._construct_as_path_attr(
|
output_as_path_attr = _peer._construct_as_path_attr(
|
||||||
input_as_path_attr, input_as4_path_attr)
|
input_as_path_attr, input_as4_path_attr)
|
||||||
|
|
||||||
eq_(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
self.assertEqual(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||||
eq_(expected_as_path, output_as_path_attr.path_seg_list)
|
self.assertEqual(expected_as_path, output_as_path_attr.path_seg_list)
|
||||||
|
|
||||||
@mock.patch.object(
|
@mock.patch.object(
|
||||||
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
||||||
@ -167,8 +165,8 @@ class Test_Peer(unittest.TestCase):
|
|||||||
# TEST
|
# TEST
|
||||||
output_as_path, output_as4_path = _peer._trans_as_path(input_as_path)
|
output_as_path, output_as4_path = _peer._trans_as_path(input_as_path)
|
||||||
|
|
||||||
eq_(expected_as_path, output_as_path)
|
self.assertEqual(expected_as_path, output_as_path)
|
||||||
eq_(expected_as4_path, output_as4_path)
|
self.assertEqual(expected_as4_path, output_as4_path)
|
||||||
|
|
||||||
@mock.patch.object(
|
@mock.patch.object(
|
||||||
peer.Peer, 'is_four_octet_as_number_cap_valid',
|
peer.Peer, 'is_four_octet_as_number_cap_valid',
|
||||||
@ -234,11 +232,11 @@ class Test_Peer(unittest.TestCase):
|
|||||||
as4_aggregator_attr = umsg_pattrs.get(
|
as4_aggregator_attr = umsg_pattrs.get(
|
||||||
bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR, None)
|
bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR, None)
|
||||||
|
|
||||||
eq_(ex_as_path_value, as_path_attr.value)
|
self.assertEqual(ex_as_path_value, as_path_attr.value)
|
||||||
eq_(None, as4_path_attr)
|
self.assertEqual(None, as4_path_attr)
|
||||||
eq_(ex_aggregator_as_number, aggregator_attr.as_number)
|
self.assertEqual(ex_aggregator_as_number, aggregator_attr.as_number)
|
||||||
eq_(ex_aggregator_addr, aggregator_attr.addr)
|
self.assertEqual(ex_aggregator_addr, aggregator_attr.addr)
|
||||||
eq_(None, as4_aggregator_attr)
|
self.assertEqual(None, as4_aggregator_attr)
|
||||||
|
|
||||||
@mock.patch.object(
|
@mock.patch.object(
|
||||||
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_, raises
|
|
||||||
|
|
||||||
from os_ken.lib.packet.bgp import (
|
from os_ken.lib.packet.bgp import (
|
||||||
BGPFlowSpecTrafficRateCommunity,
|
BGPFlowSpecTrafficRateCommunity,
|
||||||
BGPFlowSpecTrafficActionCommunity,
|
BGPFlowSpecTrafficActionCommunity,
|
||||||
@ -28,7 +26,6 @@ from os_ken.lib.packet.bgp import (
|
|||||||
BGPFlowSpecTPIDActionCommunity,
|
BGPFlowSpecTPIDActionCommunity,
|
||||||
)
|
)
|
||||||
|
|
||||||
from os_ken.services.protocols.bgp.core import BgpCoreError
|
|
||||||
from os_ken.services.protocols.bgp.utils.bgp import create_v4flowspec_actions
|
from os_ken.services.protocols.bgp.utils.bgp import create_v4flowspec_actions
|
||||||
from os_ken.services.protocols.bgp.utils.bgp import create_v6flowspec_actions
|
from os_ken.services.protocols.bgp.utils.bgp import create_v6flowspec_actions
|
||||||
from os_ken.services.protocols.bgp.utils.bgp import create_l2vpnflowspec_actions
|
from os_ken.services.protocols.bgp.utils.bgp import create_l2vpnflowspec_actions
|
||||||
@ -46,7 +43,7 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
communities = create_v4flowspec_actions(actions)
|
communities = create_v4flowspec_actions(actions)
|
||||||
expected_communities.sort(key=lambda x: x.subtype)
|
expected_communities.sort(key=lambda x: x.subtype)
|
||||||
communities.sort(key=lambda x: x.subtype)
|
communities.sort(key=lambda x: x.subtype)
|
||||||
eq_(str(expected_communities), str(communities))
|
self.assertEqual(str(expected_communities), str(communities))
|
||||||
|
|
||||||
def test_create_v4flowspec_actions_all_actions(self):
|
def test_create_v4flowspec_actions_all_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
@ -78,7 +75,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_v4flowspec_actions(actions, expected_communities)
|
self._test_create_v4flowspec_actions(actions, expected_communities)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_create_v4flowspec_actions_not_exist_actions(self):
|
def test_create_v4flowspec_actions_not_exist_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
'traffic_test': {
|
'traffic_test': {
|
||||||
@ -86,13 +82,14 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_v4flowspec_actions(actions, expected_communities)
|
self.assertRaises(ValueError, self._test_create_v4flowspec_actions,
|
||||||
|
actions, expected_communities)
|
||||||
|
|
||||||
def _test_create_v6flowspec_actions(self, actions, expected_communities):
|
def _test_create_v6flowspec_actions(self, actions, expected_communities):
|
||||||
communities = create_v6flowspec_actions(actions)
|
communities = create_v6flowspec_actions(actions)
|
||||||
expected_communities.sort(key=lambda x: x.subtype)
|
expected_communities.sort(key=lambda x: x.subtype)
|
||||||
communities.sort(key=lambda x: x.subtype)
|
communities.sort(key=lambda x: x.subtype)
|
||||||
eq_(str(expected_communities), str(communities))
|
self.assertEqual(str(expected_communities), str(communities))
|
||||||
|
|
||||||
def test_create_v6flowspec_actions_all_actions(self):
|
def test_create_v6flowspec_actions_all_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
@ -124,7 +121,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_v6flowspec_actions(actions, expected_communities)
|
self._test_create_v6flowspec_actions(actions, expected_communities)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_create_v6flowspec_actions_not_exist_actions(self):
|
def test_create_v6flowspec_actions_not_exist_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
'traffic_test': {
|
'traffic_test': {
|
||||||
@ -132,13 +128,14 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_v6flowspec_actions(actions, expected_communities)
|
self.assertRaises(ValueError, self._test_create_v6flowspec_actions,
|
||||||
|
actions, expected_communities)
|
||||||
|
|
||||||
def _test_create_l2vpnflowspec_actions(self, actions, expected_communities):
|
def _test_create_l2vpnflowspec_actions(self, actions, expected_communities):
|
||||||
communities = create_l2vpnflowspec_actions(actions)
|
communities = create_l2vpnflowspec_actions(actions)
|
||||||
expected_communities.sort(key=lambda x: x.subtype)
|
expected_communities.sort(key=lambda x: x.subtype)
|
||||||
communities.sort(key=lambda x: x.subtype)
|
communities.sort(key=lambda x: x.subtype)
|
||||||
eq_(str(expected_communities), str(communities))
|
self.assertEqual(str(expected_communities), str(communities))
|
||||||
|
|
||||||
def test_create_l2vpnflowspec_actions_all_actions(self):
|
def test_create_l2vpnflowspec_actions_all_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
@ -200,7 +197,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_l2vpnflowspec_actions(actions, expected_communities)
|
self._test_create_l2vpnflowspec_actions(actions, expected_communities)
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_create_l2vpnflowspec_actions_not_exist_actions(self):
|
def test_create_l2vpnflowspec_actions_not_exist_actions(self):
|
||||||
actions = {
|
actions = {
|
||||||
'traffic_test': {
|
'traffic_test': {
|
||||||
@ -208,4 +204,5 @@ class Test_Utils_BGP(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected_communities = []
|
expected_communities = []
|
||||||
self._test_create_l2vpnflowspec_actions(actions, expected_communities)
|
self.assertRaises(ValueError, self._test_create_l2vpnflowspec_actions,
|
||||||
|
actions, expected_communities)
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from nose.tools import eq_, ok_
|
|
||||||
|
|
||||||
from os_ken.services.protocols.bgp.utils import validation
|
from os_ken.services.protocols.bgp.utils import validation
|
||||||
|
|
||||||
|
|
||||||
@ -30,186 +28,199 @@ class Test_Utils_Validation(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def test_is_valid_mac(self):
|
def test_is_valid_mac(self):
|
||||||
ok_(validation.is_valid_mac('aa:bb:cc:dd:ee:ff'))
|
self.assertTrue(validation.is_valid_mac('aa:bb:cc:dd:ee:ff'))
|
||||||
|
|
||||||
def test_is_valid_mac_hyphenation(self):
|
def test_is_valid_mac_hyphenation(self):
|
||||||
ok_(validation.is_valid_mac('aa-bb-cc-dd-ee-ff'))
|
self.assertTrue(validation.is_valid_mac('aa-bb-cc-dd-ee-ff'))
|
||||||
|
|
||||||
def test_is_valid_mac_short(self):
|
def test_is_valid_mac_short(self):
|
||||||
eq_(False, validation.is_valid_mac('aa:bb:cc:dd:ee'))
|
self.assertEqual(False, validation.is_valid_mac('aa:bb:cc:dd:ee'))
|
||||||
|
|
||||||
def test_is_valid_ip_prefix(self):
|
def test_is_valid_ip_prefix(self):
|
||||||
ok_(validation.is_valid_ip_prefix(24, 32))
|
self.assertTrue(validation.is_valid_ip_prefix(24, 32))
|
||||||
|
|
||||||
def test_is_valid_ip_prefix_str(self):
|
def test_is_valid_ip_prefix_str(self):
|
||||||
ok_(validation.is_valid_ip_prefix('24', 32))
|
self.assertTrue(validation.is_valid_ip_prefix('24', 32))
|
||||||
|
|
||||||
def test_is_valid_ip_prefix_not_digit(self):
|
def test_is_valid_ip_prefix_not_digit(self):
|
||||||
eq_(False, validation.is_valid_ip_prefix('foo', 32))
|
self.assertEqual(False, validation.is_valid_ip_prefix('foo', 32))
|
||||||
|
|
||||||
def test_is_valid_ip_prefix_over(self):
|
def test_is_valid_ip_prefix_over(self):
|
||||||
eq_(False, validation.is_valid_ip_prefix(100, 32))
|
self.assertEqual(False, validation.is_valid_ip_prefix(100, 32))
|
||||||
|
|
||||||
def test_is_valid_ipv4(self):
|
def test_is_valid_ipv4(self):
|
||||||
ok_(validation.is_valid_ipv4('10.0.0.1'))
|
self.assertTrue(validation.is_valid_ipv4('10.0.0.1'))
|
||||||
|
|
||||||
def test_is_valid_ipv4_not_dot(self):
|
def test_is_valid_ipv4_not_dot(self):
|
||||||
eq_(False, validation.is_valid_ipv4('192:168:0:1'))
|
self.assertEqual(False, validation.is_valid_ipv4('192:168:0:1'))
|
||||||
|
|
||||||
def test_is_valid_ipv4_prefix(self):
|
def test_is_valid_ipv4_prefix(self):
|
||||||
ok_(validation.is_valid_ipv4_prefix('10.0.0.1/24'))
|
self.assertTrue(validation.is_valid_ipv4_prefix('10.0.0.1/24'))
|
||||||
|
|
||||||
def test_is_valid_ipv4_prefix_not_str(self):
|
def test_is_valid_ipv4_prefix_not_str(self):
|
||||||
eq_(False, validation.is_valid_ipv4_prefix(1234))
|
self.assertEqual(False, validation.is_valid_ipv4_prefix(1234))
|
||||||
|
|
||||||
def test_is_valid_ipv4_prefix_without_prefix(self):
|
def test_is_valid_ipv4_prefix_without_prefix(self):
|
||||||
eq_(False, validation.is_valid_ipv4_prefix('10.0.0.1'))
|
self.assertEqual(False, validation.is_valid_ipv4_prefix('10.0.0.1'))
|
||||||
|
|
||||||
def test_is_valid_ipv4_prefix_invalid_addr(self):
|
def test_is_valid_ipv4_prefix_invalid_addr(self):
|
||||||
eq_(False, validation.is_valid_ipv4_prefix('xxx.xxx.xxx.xxx/24'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_ipv4_prefix('xxx.xxx.xxx.xxx/24'))
|
||||||
|
|
||||||
def test_is_valid_ipv6(self):
|
def test_is_valid_ipv6(self):
|
||||||
ok_(validation.is_valid_ipv6('fe80::0011:aabb:ccdd:eeff'))
|
self.assertTrue(validation.is_valid_ipv6('fe80::0011:aabb:ccdd:eeff'))
|
||||||
|
|
||||||
def test_is_valid_ipv6_not_colon(self):
|
def test_is_valid_ipv6_not_colon(self):
|
||||||
eq_(False, validation.is_valid_ipv6('fe80--0011-aabb-ccdd-eeff'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_ipv6('fe80--0011-aabb-ccdd-eeff'))
|
||||||
|
|
||||||
def test_is_valid_ipv6_prefix(self):
|
def test_is_valid_ipv6_prefix(self):
|
||||||
ok_(validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff/64'))
|
self.assertTrue(
|
||||||
|
validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff/64'))
|
||||||
|
|
||||||
def test_is_valid_ipv6_prefix_not_str(self):
|
def test_is_valid_ipv6_prefix_not_str(self):
|
||||||
eq_(False, validation.is_valid_ipv6_prefix(1234))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_ipv6_prefix(1234))
|
||||||
|
|
||||||
def test_is_valid_ipv6_prefix_without_prefix(self):
|
def test_is_valid_ipv6_prefix_without_prefix(self):
|
||||||
eq_(False,
|
self.assertEqual(
|
||||||
|
False,
|
||||||
validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff'))
|
validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff'))
|
||||||
|
|
||||||
def test_is_valid_ipv6_prefix_invalid_addr(self):
|
def test_is_valid_ipv6_prefix_invalid_addr(self):
|
||||||
eq_(False, validation.is_valid_ipv6_prefix('xxxx::xxxx/64'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_ipv6_prefix('xxxx::xxxx/64'))
|
||||||
|
|
||||||
def test_is_valid_old_asn(self):
|
def test_is_valid_old_asn(self):
|
||||||
ok_(validation.is_valid_old_asn(65000))
|
self.assertTrue(validation.is_valid_old_asn(65000))
|
||||||
|
|
||||||
def test_is_valid_old_asn_negative(self):
|
def test_is_valid_old_asn_negative(self):
|
||||||
eq_(False, validation.is_valid_old_asn(-1))
|
self.assertEqual(False, validation.is_valid_old_asn(-1))
|
||||||
|
|
||||||
def test_is_valid_old_asn_over(self):
|
def test_is_valid_old_asn_over(self):
|
||||||
eq_(False, validation.is_valid_old_asn(0xffff + 1))
|
self.assertEqual(False, validation.is_valid_old_asn(0xffff + 1))
|
||||||
|
|
||||||
def test_is_valid_asn(self):
|
def test_is_valid_asn(self):
|
||||||
ok_(validation.is_valid_asn(6553800))
|
self.assertTrue(validation.is_valid_asn(6553800))
|
||||||
|
|
||||||
def test_is_valid_asn_old(self):
|
def test_is_valid_asn_old(self):
|
||||||
ok_(validation.is_valid_asn(65000))
|
self.assertTrue(validation.is_valid_asn(65000))
|
||||||
|
|
||||||
def test_is_valid_asn_negative(self):
|
def test_is_valid_asn_negative(self):
|
||||||
eq_(False, validation.is_valid_asn(-1))
|
self.assertEqual(False, validation.is_valid_asn(-1))
|
||||||
|
|
||||||
def test_is_valid_asn_over(self):
|
def test_is_valid_asn_over(self):
|
||||||
eq_(False, validation.is_valid_asn(0xffffffff + 1))
|
self.assertEqual(False, validation.is_valid_asn(0xffffffff + 1))
|
||||||
|
|
||||||
def test_is_valid_vpnv4_prefix(self):
|
def test_is_valid_vpnv4_prefix(self):
|
||||||
ok_(validation.is_valid_vpnv4_prefix('100:200:10.0.0.1/24'))
|
self.assertTrue(
|
||||||
|
validation.is_valid_vpnv4_prefix('100:200:10.0.0.1/24'))
|
||||||
|
|
||||||
def test_is_valid_vpnv4_prefix_not_str(self):
|
def test_is_valid_vpnv4_prefix_not_str(self):
|
||||||
eq_(False, validation.is_valid_vpnv4_prefix(1234))
|
self.assertEqual(False, validation.is_valid_vpnv4_prefix(1234))
|
||||||
|
|
||||||
def test_is_valid_vpnv4_prefix_short_rd(self):
|
def test_is_valid_vpnv4_prefix_short_rd(self):
|
||||||
eq_(False, validation.is_valid_vpnv4_prefix('100:10.0.0.1/24'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_vpnv4_prefix('100:10.0.0.1/24'))
|
||||||
|
|
||||||
def test_is_valid_vpnv4_prefix_invalid_rd(self):
|
def test_is_valid_vpnv4_prefix_invalid_rd(self):
|
||||||
eq_(False, validation.is_valid_vpnv4_prefix('foo:bar:10.0.0.1/24'))
|
self.assertEqual(
|
||||||
|
False, validation.is_valid_vpnv4_prefix('foo:bar:10.0.0.1/24'))
|
||||||
|
|
||||||
def test_is_valid_vpnv6_prefix(self):
|
def test_is_valid_vpnv6_prefix(self):
|
||||||
ok_(validation.is_valid_vpnv6_prefix(
|
self.assertTrue(validation.is_valid_vpnv6_prefix(
|
||||||
'100:200:fe80::0011:aabb:ccdd:eeff/64'))
|
'100:200:fe80::0011:aabb:ccdd:eeff/64'))
|
||||||
|
|
||||||
def test_is_valid_vpnv6_prefix_not_str(self):
|
def test_is_valid_vpnv6_prefix_not_str(self):
|
||||||
eq_(False, validation.is_valid_vpnv6_prefix(1234))
|
self.assertEqual(False, validation.is_valid_vpnv6_prefix(1234))
|
||||||
|
|
||||||
def test_is_valid_vpnv6_prefix_short_rd(self):
|
def test_is_valid_vpnv6_prefix_short_rd(self):
|
||||||
eq_(False, validation.is_valid_vpnv6_prefix('100:eeff/64'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_vpnv6_prefix('100:eeff/64'))
|
||||||
|
|
||||||
def test_is_valid_vpnv6_prefix_invalid_rd(self):
|
def test_is_valid_vpnv6_prefix_invalid_rd(self):
|
||||||
eq_(False, validation.is_valid_vpnv6_prefix('foo:bar:10.0.0.1/24'))
|
self.assertEqual(
|
||||||
|
False, validation.is_valid_vpnv6_prefix('foo:bar:10.0.0.1/24'))
|
||||||
|
|
||||||
def test_is_valid_med(self):
|
def test_is_valid_med(self):
|
||||||
ok_(validation.is_valid_med(100))
|
self.assertTrue(validation.is_valid_med(100))
|
||||||
|
|
||||||
def test_is_valid_med_not_num(self):
|
def test_is_valid_med_not_num(self):
|
||||||
eq_(False, validation.is_valid_med('foo'))
|
self.assertEqual(False, validation.is_valid_med('foo'))
|
||||||
|
|
||||||
def test_is_valid_med_negative(self):
|
def test_is_valid_med_negative(self):
|
||||||
eq_(False, validation.is_valid_med(-1))
|
self.assertEqual(False, validation.is_valid_med(-1))
|
||||||
|
|
||||||
def test_is_valid_med_over(self):
|
def test_is_valid_med_over(self):
|
||||||
eq_(False, validation.is_valid_med(0xffffffff + 1))
|
self.assertEqual(False, validation.is_valid_med(0xffffffff + 1))
|
||||||
|
|
||||||
def test_is_valid_mpls_label(self):
|
def test_is_valid_mpls_label(self):
|
||||||
ok_(validation.is_valid_mpls_label(100))
|
self.assertTrue(validation.is_valid_mpls_label(100))
|
||||||
|
|
||||||
def test_is_valid_mpls_label_reserved(self):
|
def test_is_valid_mpls_label_reserved(self):
|
||||||
eq_(False, validation.is_valid_mpls_label(4))
|
self.assertEqual(False, validation.is_valid_mpls_label(4))
|
||||||
|
|
||||||
def test_is_valid_mpls_label_not_num(self):
|
def test_is_valid_mpls_label_not_num(self):
|
||||||
eq_(False, validation.is_valid_mpls_label('foo'))
|
self.assertEqual(False, validation.is_valid_mpls_label('foo'))
|
||||||
|
|
||||||
def test_is_valid_mpls_label_negative(self):
|
def test_is_valid_mpls_label_negative(self):
|
||||||
eq_(False, validation.is_valid_mpls_label(-1))
|
self.assertEqual(False, validation.is_valid_mpls_label(-1))
|
||||||
|
|
||||||
def test_is_valid_mpls_label_over(self):
|
def test_is_valid_mpls_label_over(self):
|
||||||
eq_(False, validation.is_valid_mpls_label(0x100000 + 1))
|
self.assertEqual(False, validation.is_valid_mpls_label(0x100000 + 1))
|
||||||
|
|
||||||
def test_is_valid_mpls_labels(self):
|
def test_is_valid_mpls_labels(self):
|
||||||
ok_(validation.is_valid_mpls_labels([100, 200]))
|
self.assertTrue(validation.is_valid_mpls_labels([100, 200]))
|
||||||
|
|
||||||
def test_is_valid_mpls_labels_not_list(self):
|
def test_is_valid_mpls_labels_not_list(self):
|
||||||
eq_(False, validation.is_valid_mpls_labels(100))
|
self.assertEqual(False, validation.is_valid_mpls_labels(100))
|
||||||
|
|
||||||
def test_is_valid_mpls_labels_with_invalid_label(self):
|
def test_is_valid_mpls_labels_with_invalid_label(self):
|
||||||
eq_(False, validation.is_valid_mpls_labels(['foo', 200]))
|
self.assertEqual(False, validation.is_valid_mpls_labels(['foo', 200]))
|
||||||
|
|
||||||
def test_is_valid_route_dist(self):
|
def test_is_valid_route_dist(self):
|
||||||
ok_(validation.is_valid_route_dist('65000:222'))
|
self.assertTrue(validation.is_valid_route_dist('65000:222'))
|
||||||
|
|
||||||
def test_is_valid_route_dist_ipv4_based(self):
|
def test_is_valid_route_dist_ipv4_based(self):
|
||||||
ok_(validation.is_valid_route_dist('10.0.0.1:333'))
|
self.assertTrue(validation.is_valid_route_dist('10.0.0.1:333'))
|
||||||
|
|
||||||
def test_is_valid_route_not_str(self):
|
def test_is_valid_route_not_str(self):
|
||||||
eq_(False, validation.is_valid_route_dist(65000))
|
self.assertEqual(False, validation.is_valid_route_dist(65000))
|
||||||
|
|
||||||
def test_is_valid_route_dist_short(self):
|
def test_is_valid_route_dist_short(self):
|
||||||
eq_(False, validation.is_valid_route_dist('65000'))
|
self.assertEqual(False, validation.is_valid_route_dist('65000'))
|
||||||
|
|
||||||
def test_is_valid_route_dist_invalid_ipv4_addr(self):
|
def test_is_valid_route_dist_invalid_ipv4_addr(self):
|
||||||
eq_(False, validation.is_valid_route_dist('xxx.xxx.xxx.xxx:333'))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_route_dist('xxx.xxx.xxx.xxx:333'))
|
||||||
|
|
||||||
def test_is_valid_esi(self):
|
def test_is_valid_esi(self):
|
||||||
ok_(validation.is_valid_esi(100))
|
self.assertTrue(validation.is_valid_esi(100))
|
||||||
|
|
||||||
def test_is_valid_esi_not_int(self):
|
def test_is_valid_esi_not_int(self):
|
||||||
eq_(False, validation.is_valid_esi('foo'))
|
self.assertEqual(False, validation.is_valid_esi('foo'))
|
||||||
|
|
||||||
def test_is_valid_ethernet_tag_id(self):
|
def test_is_valid_ethernet_tag_id(self):
|
||||||
ok_(validation.is_valid_ethernet_tag_id(100))
|
self.assertTrue(validation.is_valid_ethernet_tag_id(100))
|
||||||
|
|
||||||
def test_is_valid_ethernet_tag_id_not_int(self):
|
def test_is_valid_ethernet_tag_id_not_int(self):
|
||||||
eq_(False, validation.is_valid_ethernet_tag_id('foo'))
|
self.assertEqual(False, validation.is_valid_ethernet_tag_id('foo'))
|
||||||
|
|
||||||
def test_is_valid_ethernet_tag_id_negative(self):
|
def test_is_valid_ethernet_tag_id_negative(self):
|
||||||
eq_(False, validation.is_valid_ethernet_tag_id(-1))
|
self.assertEqual(False, validation.is_valid_ethernet_tag_id(-1))
|
||||||
|
|
||||||
def test_is_valid_ethernet_tag_id_over(self):
|
def test_is_valid_ethernet_tag_id_over(self):
|
||||||
eq_(False, validation.is_valid_ethernet_tag_id(0xffffffff + 1))
|
self.assertEqual(False,
|
||||||
|
validation.is_valid_ethernet_tag_id(0xffffffff + 1))
|
||||||
|
|
||||||
def test_is_valid_vni(self):
|
def test_is_valid_vni(self):
|
||||||
ok_(validation.is_valid_vni(100))
|
self.assertTrue(validation.is_valid_vni(100))
|
||||||
|
|
||||||
def test_is_valid_vni_not_int(self):
|
def test_is_valid_vni_not_int(self):
|
||||||
eq_(False, validation.is_valid_vni('foo'))
|
self.assertEqual(False, validation.is_valid_vni('foo'))
|
||||||
|
|
||||||
def test_is_valid_vni_negative(self):
|
def test_is_valid_vni_negative(self):
|
||||||
eq_(False, validation.is_valid_vni(-1))
|
self.assertEqual(False, validation.is_valid_vni(-1))
|
||||||
|
|
||||||
def test_is_valid_vni_over(self):
|
def test_is_valid_vni_over(self):
|
||||||
eq_(False, validation.is_valid_vni(0xffffff + 1))
|
self.assertEqual(False, validation.is_valid_vni(0xffffff + 1))
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
# implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import logging
|
|
||||||
import six
|
|
||||||
from nose.tools import eq_
|
|
||||||
|
|
||||||
from os_ken import utils
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class Test_utils(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_hex_array_string(self):
|
|
||||||
"""
|
|
||||||
Test hex_array() with str type.
|
|
||||||
"""
|
|
||||||
expected_result = '0x01 0x02 0x03 0x04'
|
|
||||||
data = b'\x01\x02\x03\x04'
|
|
||||||
eq_(expected_result, utils.hex_array(data))
|
|
||||||
|
|
||||||
def test_hex_array_bytearray(self):
|
|
||||||
"""
|
|
||||||
Test hex_array() with bytearray type.
|
|
||||||
"""
|
|
||||||
expected_result = '0x01 0x02 0x03 0x04'
|
|
||||||
data = bytearray(b'\x01\x02\x03\x04')
|
|
||||||
eq_(expected_result, utils.hex_array(data))
|
|
||||||
|
|
||||||
def test_hex_array_bytes(self):
|
|
||||||
"""
|
|
||||||
Test hex_array() with bytes type. (Python3 only)
|
|
||||||
"""
|
|
||||||
if six.PY2:
|
|
||||||
return
|
|
||||||
expected_result = '0x01 0x02 0x03 0x04'
|
|
||||||
data = bytes(b'\x01\x02\x03\x04')
|
|
||||||
eq_(expected_result, utils.hex_array(data))
|
|
||||||
|
|
||||||
def test_binary_str_string(self):
|
|
||||||
"""
|
|
||||||
Test binary_str() with str type.
|
|
||||||
"""
|
|
||||||
expected_result = '\\x01\\x02\\x03\\x04'
|
|
||||||
data = b'\x01\x02\x03\x04'
|
|
||||||
eq_(expected_result, utils.binary_str(data))
|
|
||||||
|
|
||||||
def test_binary_str_bytearray(self):
|
|
||||||
"""
|
|
||||||
Test binary_str() with bytearray type.
|
|
||||||
"""
|
|
||||||
expected_result = '\\x01\\x02\\x03\\x04'
|
|
||||||
data = bytearray(b'\x01\x02\x03\x04')
|
|
||||||
eq_(expected_result, utils.binary_str(data))
|
|
||||||
|
|
||||||
def test_binary_str_bytes(self):
|
|
||||||
"""
|
|
||||||
Test binary_str() with bytes type. (Python3 only)
|
|
||||||
"""
|
|
||||||
if six.PY2:
|
|
||||||
return
|
|
||||||
expected_result = '\\x01\\x02\\x03\\x04'
|
|
||||||
data = bytes(b'\x01\x02\x03\x04')
|
|
||||||
eq_(expected_result, utils.binary_str(data))
|
|
@ -9,6 +9,7 @@
|
|||||||
pbr>=2.0.0 # Apache-2.0
|
pbr>=2.0.0 # Apache-2.0
|
||||||
eventlet>=0.26.1 # MIT
|
eventlet>=0.26.1 # MIT
|
||||||
msgpack>=1.0.0 # RPC library, BGP speaker(net_cntl)
|
msgpack>=1.0.0 # RPC library, BGP speaker(net_cntl)
|
||||||
|
ncclient>=0.6.13 # Apache-2.0
|
||||||
netaddr>=0.7.18 # BSD
|
netaddr>=0.7.18 # BSD
|
||||||
oslo.config>=5.1.0
|
oslo.config>=5.1.0
|
||||||
ovs>=2.8.0 # OVSDB
|
ovs>=2.8.0 # OVSDB
|
||||||
|
196
run_tests.sh
196
run_tests.sh
@ -1,196 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -z "${PYTHON}" ]; then
|
|
||||||
PYTHON=python3
|
|
||||||
fi
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Usage: $0 [OPTION]..."
|
|
||||||
echo "Run OSKen's test suite(s)"
|
|
||||||
echo ""
|
|
||||||
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
|
|
||||||
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
|
|
||||||
echo " -c, --coverage Generate coverage report"
|
|
||||||
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
|
|
||||||
echo " -p, --pycodestyle, --pep8 Just run pycodestyle(pep8)"
|
|
||||||
echo " -P, --no-pycodestyle, --no-pep8 Don't run pycodestyle(pep8)"
|
|
||||||
echo " -l, --pylint Just run pylint"
|
|
||||||
echo " -i, --integrated Run integrated test"
|
|
||||||
echo " -v, --verbose Run verbose pylint analysis"
|
|
||||||
echo " -h, --help Print this usage message"
|
|
||||||
echo ""
|
|
||||||
echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
|
|
||||||
echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
|
|
||||||
echo " prefer to run tests NOT in a virtual environment, simply pass the -N option."
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
process_option() {
|
|
||||||
case "$1" in
|
|
||||||
-h|--help) usage;;
|
|
||||||
-V|--virtual-env) always_venv=1; never_venv=0;;
|
|
||||||
-N|--no-virtual-env) always_venv=0; never_venv=1;;
|
|
||||||
-f|--force) force=1;;
|
|
||||||
-p|--pycodestyle|--pep8) just_pycodestyle=1; never_venv=1; always_venv=0;;
|
|
||||||
-P|--no-pycodestyle|--no-pep8) no_pycodestyle=1;;
|
|
||||||
-l|--pylint) just_pylint=1;;
|
|
||||||
-i|--integrated) integrated=1;;
|
|
||||||
-c|--coverage) coverage=1;;
|
|
||||||
-v|--verbose) verbose=1;;
|
|
||||||
-*) noseopts="$noseopts $1";;
|
|
||||||
*) noseargs="$noseargs $1"
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
venv=.venv
|
|
||||||
with_venv=tools/with_venv.sh
|
|
||||||
always_venv=0
|
|
||||||
never_venv=0
|
|
||||||
just_pycodestyle=0
|
|
||||||
no_pycodestyle=0
|
|
||||||
just_pylint=0
|
|
||||||
integrated=0
|
|
||||||
force=0
|
|
||||||
noseargs=
|
|
||||||
wrapper=""
|
|
||||||
coverage=0
|
|
||||||
verbose=0
|
|
||||||
|
|
||||||
for arg in "$@"; do
|
|
||||||
process_option $arg
|
|
||||||
done
|
|
||||||
|
|
||||||
# If enabled, tell nose to collect coverage data
|
|
||||||
if [ $coverage -eq 1 ]; then
|
|
||||||
noseopts="$noseopts --with-coverage --cover-package=os_ken"
|
|
||||||
fi
|
|
||||||
|
|
||||||
run_tests() {
|
|
||||||
# Just run the test suites in current environment
|
|
||||||
${wrapper} rm -f ./$PLUGIN_DIR/tests.sqlite
|
|
||||||
|
|
||||||
if [ $verbose -eq 1 ]; then
|
|
||||||
${wrapper} $NOSETESTS
|
|
||||||
else
|
|
||||||
${wrapper} $NOSETESTS 2> run_tests.log
|
|
||||||
fi
|
|
||||||
# If we get some short import error right away, print the error log directly
|
|
||||||
RESULT=$?
|
|
||||||
if [ "$RESULT" -ne "0" ];
|
|
||||||
then
|
|
||||||
ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
|
|
||||||
if [ $verbose -eq 0 -a "$ERRSIZE" -lt "40" ];
|
|
||||||
then
|
|
||||||
cat run_tests.log
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
return $RESULT
|
|
||||||
}
|
|
||||||
|
|
||||||
run_pylint() {
|
|
||||||
echo "Running pylint ..."
|
|
||||||
PYLINT_OPTIONS="--rcfile=.pylintrc --output-format=parseable"
|
|
||||||
PYLINT_INCLUDE="os_ken os_ken/tests/bin/osken-client"
|
|
||||||
export PYTHONPATH=$PYTHONPATH:.os_ken
|
|
||||||
PYLINT_LOG=pylint.log
|
|
||||||
|
|
||||||
${wrapper} pylint $PYLINT_OPTIONS $PYLINT_INCLUDE > $PYLINT_LOG
|
|
||||||
#BASE_CMD="pylint $PYLINT_OPTIONS $PYLINT_INCLUDE > $PYLINT_LOG"
|
|
||||||
#[ $verbose -eq 1 ] && $BASE_CMD || msg_count=`$BASE_CMD | grep 'os_ken/' | wc -l`
|
|
||||||
#if [ $verbose -eq 0 ]; then
|
|
||||||
# echo "Pylint messages count: " $msg_count
|
|
||||||
#fi
|
|
||||||
export PYTHONPATH=$OLD_PYTHONPATH
|
|
||||||
}
|
|
||||||
|
|
||||||
run_pycodestyle() {
|
|
||||||
PYCODESTYLE=$(which pycodestyle || which pep8)
|
|
||||||
if [ -z "${PYCODESTYLE}" ]
|
|
||||||
then
|
|
||||||
echo "Please install pycodestyle or pep8"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo "Running $(basename ${PYCODESTYLE}) ..."
|
|
||||||
|
|
||||||
PYCODESTYLE_OPTIONS="--repeat --show-source"
|
|
||||||
PYCODESTYLE_INCLUDE="os_ken setup*.py"
|
|
||||||
PYCODESTYLE_LOG=pycodestyle.log
|
|
||||||
${wrapper} ${PYCODESTYLE} $PYCODESTYLE_OPTIONS $PYCODESTYLE_INCLUDE | tee $PYCODESTYLE_LOG
|
|
||||||
}
|
|
||||||
|
|
||||||
run_integrated() {
|
|
||||||
echo "Running integrated test ..."
|
|
||||||
|
|
||||||
INTEGRATED_TEST_RUNNER="./os_ken/tests/integrated/run_tests_with_ovs12.py"
|
|
||||||
sudo PYTHONPATH=. nosetests -s $INTEGRATED_TEST_RUNNER
|
|
||||||
}
|
|
||||||
#NOSETESTS="nosetests $noseopts $noseargs"
|
|
||||||
NOSETESTS="${PYTHON} ./os_ken/tests/run_tests.py $noseopts $noseargs"
|
|
||||||
|
|
||||||
#if [ -n "$PLUGIN_DIR" ]
|
|
||||||
#then
|
|
||||||
# if ! [ -f ./$PLUGIN_DIR/run_tests.py ]
|
|
||||||
# then
|
|
||||||
# echo "Could not find run_tests.py in plugin directory $PLUGIN_DIR"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
#fi
|
|
||||||
|
|
||||||
if [ $never_venv -eq 0 ]
|
|
||||||
then
|
|
||||||
# Remove the virtual environment if --force used
|
|
||||||
if [ $force -eq 1 ]; then
|
|
||||||
echo "Cleaning virtualenv..."
|
|
||||||
rm -rf ${venv}
|
|
||||||
fi
|
|
||||||
if [ -e ${venv} ]; then
|
|
||||||
wrapper="${with_venv}"
|
|
||||||
else
|
|
||||||
if [ $always_venv -eq 1 ]; then
|
|
||||||
# Automatically install the virtualenv
|
|
||||||
${PYTHON} tools/install_venv.py
|
|
||||||
wrapper="${with_venv}"
|
|
||||||
else
|
|
||||||
echo -e "No virtual environment found...create one? (Y/n) \c"
|
|
||||||
read use_ve
|
|
||||||
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
|
|
||||||
# Install the virtualenv and run the test suite in it
|
|
||||||
${PYTHON} tools/install_venv.py
|
|
||||||
wrapper=${with_venv}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Delete old coverage data from previous runs
|
|
||||||
if [ $coverage -eq 1 ]; then
|
|
||||||
${wrapper} coverage erase
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $just_pycodestyle -eq 1 ]; then
|
|
||||||
run_pycodestyle
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
if [ $just_pylint -eq 1 ]; then
|
|
||||||
run_pylint
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $integrated -eq 1 ]; then
|
|
||||||
run_integrated
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
run_tests
|
|
||||||
RV=$?
|
|
||||||
if [ $no_pycodestyle -eq 0 ]; then
|
|
||||||
run_pycodestyle
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $coverage -eq 1 ]; then
|
|
||||||
echo "Generating coverage report in coverage.xml and covhtml/"
|
|
||||||
${wrapper} coverage xml -i
|
|
||||||
${wrapper} coverage html -d covhtml -i
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit $RV
|
|
@ -9,6 +9,6 @@ python-subunit>=1.0.0 # Apache-2.0/BSD
|
|||||||
oslotest>=3.2.0 # Apache-2.0
|
oslotest>=3.2.0 # Apache-2.0
|
||||||
stestr>=1.0.0 # Apache-2.0
|
stestr>=1.0.0 # Apache-2.0
|
||||||
testtools>=2.2.0 # MIT
|
testtools>=2.2.0 # MIT
|
||||||
nose>=1.3.7 # LGPL
|
|
||||||
pycodestyle>=2.0.0 # MIT
|
pycodestyle>=2.0.0 # MIT
|
||||||
pylint==1.9.2 # GPLv2
|
pylint==1.9.2 # GPLv2
|
||||||
|
testscenarios>=0.4 # Apache-2.0/BSD
|
||||||
|
@ -1,139 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
||||||
|
|
||||||
# Copyright 2010 United States Government as represented by the
|
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# Copyright 2010 OpenStack LLC.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
"""
|
|
||||||
Installation script for Quantum's development virtualenv
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
||||||
VENV = os.path.join(ROOT, '.venv')
|
|
||||||
PIP_REQUIRES = os.path.join(ROOT, 'tools', 'pip-requires')
|
|
||||||
OPTIONAL_REQUIRES = os.path.join(ROOT, 'tools', 'optional-requires')
|
|
||||||
TEST_REQUIRES = os.path.join(ROOT, 'tools', 'test-requires')
|
|
||||||
PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
|
|
||||||
|
|
||||||
VENV_EXISTS = bool(os.path.exists(VENV))
|
|
||||||
|
|
||||||
def die(message, *args):
|
|
||||||
print >> sys.stderr, message % args
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def run_command(cmd, redirect_output=True, check_exit_code=True):
|
|
||||||
"""
|
|
||||||
Runs a command in an out-of-process shell, returning the
|
|
||||||
output of that command. Working directory is ROOT.
|
|
||||||
"""
|
|
||||||
if redirect_output:
|
|
||||||
stdout = subprocess.PIPE
|
|
||||||
else:
|
|
||||||
stdout = None
|
|
||||||
proc = subprocess.Popen(cmd, cwd=ROOT, stdout=stdout)
|
|
||||||
output = proc.communicate()[0]
|
|
||||||
if check_exit_code and proc.returncode != 0:
|
|
||||||
raise Exception('Command "%s" failed.\n%s' % (' '.join(cmd), output))
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'],
|
|
||||||
check_exit_code=False).strip())
|
|
||||||
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'],
|
|
||||||
check_exit_code=False).strip())
|
|
||||||
|
|
||||||
|
|
||||||
def check_dependencies():
|
|
||||||
"""Make sure virtualenv is in the path."""
|
|
||||||
|
|
||||||
if not HAS_VIRTUALENV:
|
|
||||||
raise Exception('Virtualenv not found. ' + \
|
|
||||||
'Try installing python-virtualenv')
|
|
||||||
print 'done.'
|
|
||||||
|
|
||||||
|
|
||||||
def create_virtualenv(venv=VENV, install_pip=False):
|
|
||||||
"""Creates the virtual environment and installs PIP only into the
|
|
||||||
virtual environment
|
|
||||||
"""
|
|
||||||
print 'Creating venv...',
|
|
||||||
|
|
||||||
install = ['virtualenv', '-q', venv]
|
|
||||||
run_command(install)
|
|
||||||
|
|
||||||
print 'done.'
|
|
||||||
print 'Installing pip in virtualenv...',
|
|
||||||
if install_pip and \
|
|
||||||
not run_command(['tools/with_venv.sh', 'easy_install',
|
|
||||||
'pip>1.0']):
|
|
||||||
die("Failed to install pip.")
|
|
||||||
print 'done.'
|
|
||||||
|
|
||||||
|
|
||||||
def install_dependencies(venv=VENV):
|
|
||||||
print 'Installing dependencies with pip (this can take a while)...'
|
|
||||||
run_command(['tools/with_venv.sh', 'pip', 'install', '-r',
|
|
||||||
PIP_REQUIRES], redirect_output=False)
|
|
||||||
run_command(['tools/with_venv.sh', 'pip', 'install', '-r',
|
|
||||||
OPTIONAL_REQUIRES], redirect_output=False)
|
|
||||||
run_command(['tools/with_venv.sh', 'pip', 'install', '-r',
|
|
||||||
TEST_REQUIRES], redirect_output=False)
|
|
||||||
|
|
||||||
# Tell the virtual env how to "import quantum"
|
|
||||||
pthfile = os.path.join(venv, "lib", PY_VERSION, "site-packages",
|
|
||||||
"quantum.pth")
|
|
||||||
f = open(pthfile, 'w')
|
|
||||||
f.write("%s\n" % ROOT)
|
|
||||||
|
|
||||||
|
|
||||||
def print_help():
|
|
||||||
help = """
|
|
||||||
Quantum development environment setup is complete.
|
|
||||||
|
|
||||||
Quantum development uses virtualenv to track and manage Python dependencies
|
|
||||||
while in development and testing.
|
|
||||||
|
|
||||||
To activate the Quantum virtualenv for the extent of your current shell
|
|
||||||
session you can run:
|
|
||||||
|
|
||||||
$ source .venv/bin/activate
|
|
||||||
|
|
||||||
Or, if you prefer, you can run commands in the virtualenv on a case by case
|
|
||||||
basis by running:
|
|
||||||
|
|
||||||
$ tools/with_venv.sh <your command>
|
|
||||||
|
|
||||||
Also, make test will automatically use the virtualenv.
|
|
||||||
"""
|
|
||||||
print help
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
check_dependencies()
|
|
||||||
create_virtualenv()
|
|
||||||
install_dependencies()
|
|
||||||
print_help()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main(sys.argv)
|
|
@ -1,4 +0,0 @@
|
|||||||
coverage>=4.0,!=4.4
|
|
||||||
nose>=1.3.7
|
|
||||||
pycodestyle>=2.0.0
|
|
||||||
pylint==1.9.2
|
|
11
tox.ini
11
tox.ini
@ -5,7 +5,7 @@ skipsdist = True
|
|||||||
ignore_basepython_conflict = True
|
ignore_basepython_conflict = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
basepython = python3
|
basepython = {env:TOX_PYTHON:python3}
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
setenv =
|
setenv =
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
@ -17,10 +17,8 @@ deps =
|
|||||||
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
# TODO(hongbin): this is the way Ryu runs unit tests and we inherit
|
commands =
|
||||||
# this approach as a start. In the future, we should migrate to stestr
|
stestr run {posargs}
|
||||||
# for consistency with other OpenStack projects.
|
|
||||||
commands = python ./os_ken/tests/run_tests.py {posargs}
|
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands = flake8 {posargs}
|
commands = flake8 {posargs}
|
||||||
@ -87,6 +85,7 @@ show-source = True
|
|||||||
# H104: Files with no code shouldn't contain any license header nor comments
|
# H104: Files with no code shouldn't contain any license header nor comments
|
||||||
# H105: Don't use author tags. We use version control instead.
|
# H105: Don't use author tags. We use version control instead.
|
||||||
# H201: Do not write ``except:``, use ``except Exception:`` at the very least.
|
# H201: Do not write ``except:``, use ``except Exception:`` at the very least.
|
||||||
|
# H202: assertRaises Exception too broad
|
||||||
# H301: Do not import more than one module per line (*)
|
# H301: Do not import more than one module per line (*)
|
||||||
# H306: Alphabetically order your imports by the full module path
|
# H306: Alphabetically order your imports by the full module path
|
||||||
# H401: Docstrings should not start with a space.
|
# H401: Docstrings should not start with a space.
|
||||||
@ -95,6 +94,6 @@ show-source = True
|
|||||||
# H405: Multi line docstrings should start with a one line summary followed by an empty line.
|
# H405: Multi line docstrings should start with a one line summary followed by an empty line.
|
||||||
# H501: Do not use ``locals()`` or ``self.__dict__`` for formatting strings
|
# H501: Do not use ``locals()`` or ``self.__dict__`` for formatting strings
|
||||||
# W504 line break after binary operator
|
# W504 line break after binary operator
|
||||||
ignore = E113,E123,E125,W503,E116,E128,E402,E501,E704,E722,E731,E741,F401,F403,F405,F811,F812,F821,F841,H101,H102,H104,H105,H201,H301,H306,H401,H403,H404,H405,H501,W504
|
ignore = E113,E123,E125,W503,E116,E128,E402,E501,E704,E722,E731,E741,F401,F403,F405,F811,F812,F821,F841,H101,H102,H104,H105,H201,H202,H301,H306,H401,H403,H404,H405,H501,W504
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,os_ken/contrib
|
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,os_ken/contrib
|
||||||
|
Loading…
Reference in New Issue
Block a user