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*
|
||||
!.coveragerc
|
||||
.tox
|
||||
nosetests.xml
|
||||
.testrepository
|
||||
.stestr
|
||||
.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 = []
|
||||
checktime = 120
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.brdc1 = ctn_base.Bridge(name='brdc1',
|
||||
subnet='192.168.10.0/24')
|
||||
cls.bridges.append(cls.brdc1)
|
||||
def setUp(self):
|
||||
self.skipTest('These tests require to have "docker" configured in the '
|
||||
'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')
|
||||
self.bridges.append(self.brdc1)
|
||||
|
||||
cls.dockerimg = ctn_base.DockerImage()
|
||||
self.dockerimg = ctn_base.DockerImage()
|
||||
image = 'python:%d.%d' % (
|
||||
sys.version_info.major, sys.version_info.minor)
|
||||
cls.r_img = cls.dockerimg.create_os_ken(image=image, check_exist=True)
|
||||
cls.images.append(cls.r_img)
|
||||
cls.q_img = 'osrg/quagga'
|
||||
cls.images.append(cls.q_img)
|
||||
self.r_img = self.dockerimg.create_os_ken(image=image,
|
||||
check_exist=True)
|
||||
self.images.append(self.r_img)
|
||||
self.q_img = 'osrg/quagga'
|
||||
self.images.append(self.q_img)
|
||||
|
||||
cls.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||
router_id='192.168.0.1',
|
||||
ctn_image_name=cls.r_img)
|
||||
cls.containers.append(cls.r1)
|
||||
cls.r1.add_route('10.10.0.0/28')
|
||||
cls.r1.run(wait=True)
|
||||
cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
|
||||
cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
|
||||
self.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||
router_id='192.168.0.1',
|
||||
ctn_image_name=self.r_img)
|
||||
self.containers.append(self.r1)
|
||||
self.r1.add_route('10.10.0.0/28')
|
||||
self.r1.run(wait=True)
|
||||
self.r1_ip_cidr = self.brdc1.addif(self.r1)
|
||||
self.r1_ip = self.r1_ip_cidr.split('/')[0]
|
||||
|
||||
cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||
router_id='192.168.0.2',
|
||||
ctn_image_name=cls.q_img)
|
||||
cls.containers.append(cls.q1)
|
||||
cls.q1.add_route('192.168.160.0/24')
|
||||
cls.q1.run(wait=True)
|
||||
cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
|
||||
cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
|
||||
self.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||
router_id='192.168.0.2',
|
||||
ctn_image_name=self.q_img)
|
||||
self.containers.append(self.q1)
|
||||
self.q1.add_route('192.168.160.0/24')
|
||||
self.q1.run(wait=True)
|
||||
self.q1_ip_cidr = self.brdc1.addif(self.q1)
|
||||
self.q1_ip = self.q1_ip_cidr.split('/')[0]
|
||||
|
||||
cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name)
|
||||
cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name)
|
||||
self.r1.add_peer(self.q1, bridge=self.brdc1.name)
|
||||
self.q1.add_peer(self.r1, bridge=self.brdc1.name)
|
||||
|
||||
super(BgpSpeakerTestBase, cls).setUpClass()
|
||||
super().setUp()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -32,42 +32,44 @@ class BgpSpeakerTestBase(unittest.TestCase):
|
||||
bridges = []
|
||||
checktime = 120
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.brdc1 = ctn_base.Bridge(name='brip6dc1',
|
||||
subnet='2001:10::/32')
|
||||
cls.bridges.append(cls.brdc1)
|
||||
def setUp(self):
|
||||
self.skipTest('These tests require to have "docker" configured in the '
|
||||
'system. Regardless of if we move them to functional or '
|
||||
'fix them, now we need to disable them.')
|
||||
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' % (
|
||||
sys.version_info.major, sys.version_info.minor)
|
||||
cls.r_img = cls.dockerimg.create_os_ken(image=image, check_exist=True)
|
||||
cls.images.append(cls.r_img)
|
||||
cls.q_img = 'osrg/quagga'
|
||||
cls.images.append(cls.q_img)
|
||||
self.r_img = self.dockerimg.create_os_ken(image=image,
|
||||
check_exist=True)
|
||||
self.images.append(self.r_img)
|
||||
self.q_img = 'osrg/quagga'
|
||||
self.images.append(self.q_img)
|
||||
|
||||
cls.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||
router_id='192.168.0.1',
|
||||
ctn_image_name=cls.r_img)
|
||||
cls.containers.append(cls.r1)
|
||||
cls.r1.add_route('fc00:10::/64', route_info={'rf': 'ipv6'})
|
||||
cls.r1.run(wait=True)
|
||||
cls.r1_ip_cidr = cls.brdc1.addif(cls.r1)
|
||||
cls.r1_ip = cls.r1_ip_cidr.split('/')[0]
|
||||
self.r1 = oskenbgp.OSKenBGPContainer(name='r1', asn=64512,
|
||||
router_id='192.168.0.1',
|
||||
ctn_image_name=self.r_img)
|
||||
self.containers.append(self.r1)
|
||||
self.r1.add_route('fc00:10::/64', route_info={'rf': 'ipv6'})
|
||||
self.r1.run(wait=True)
|
||||
self.r1_ip_cidr = self.brdc1.addif(self.r1)
|
||||
self.r1_ip = self.r1_ip_cidr.split('/')[0]
|
||||
|
||||
cls.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||
router_id='192.168.0.2',
|
||||
ctn_image_name=cls.q_img)
|
||||
cls.containers.append(cls.q1)
|
||||
cls.q1.add_route('fc00:100::/64', route_info={'rf': 'ipv6'})
|
||||
cls.q1.run(wait=True)
|
||||
cls.q1_ip_cidr = cls.brdc1.addif(cls.q1)
|
||||
cls.q1_ip = cls.q1_ip_cidr.split('/')[0]
|
||||
self.q1 = quagga.QuaggaBGPContainer(name='q1', asn=64522,
|
||||
router_id='192.168.0.2',
|
||||
ctn_image_name=self.q_img)
|
||||
self.containers.append(self.q1)
|
||||
self.q1.add_route('fc00:100::/64', route_info={'rf': 'ipv6'})
|
||||
self.q1.run(wait=True)
|
||||
self.q1_ip_cidr = self.brdc1.addif(self.q1)
|
||||
self.q1_ip = self.q1_ip_cidr.split('/')[0]
|
||||
|
||||
cls.r1.add_peer(cls.q1, bridge=cls.brdc1.name, v6=True)
|
||||
cls.q1.add_peer(cls.r1, bridge=cls.brdc1.name, v6=True)
|
||||
self.r1.add_peer(self.q1, bridge=self.brdc1.name, v6=True)
|
||||
self.q1.add_peer(self.r1, bridge=self.brdc1.name, v6=True)
|
||||
|
||||
super(BgpSpeakerTestBase, cls).setUpClass()
|
||||
super().setUp()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -22,7 +22,7 @@ from . import base
|
||||
|
||||
class BgpSpeakerBasicTest(base.BgpSpeakerTestBase):
|
||||
def setUp(self):
|
||||
super(BgpSpeakerBasicTest, self).setUp()
|
||||
super().setUp()
|
||||
self.r1.stop_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):
|
||||
def setUp(self):
|
||||
super(BgpSpeakerBasicTest, self).setUp()
|
||||
super().setUp()
|
||||
self.r1.stop_os_kenbgp(retry=True)
|
||||
self.r1.start_os_kenbgp(retry=True)
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from nose.tools import ok_, eq_, timed, nottest
|
||||
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
import time
|
||||
@ -59,30 +58,24 @@ class TestWithOVS12(unittest.TestCase):
|
||||
def tearDownClass(cls):
|
||||
cls.mn.stop()
|
||||
|
||||
@timed(TIMEOUT)
|
||||
def test_add_flow_v10(self):
|
||||
app = 'os_ken/tests/integrated/test_add_flow_v10.py'
|
||||
self._run_os_ken_manager_and_check_output(app)
|
||||
|
||||
@timed(TIMEOUT)
|
||||
def test_request_reply_v12(self):
|
||||
app = 'os_ken/tests/integrated/test_request_reply_v12.py'
|
||||
self._run_os_ken_manager_and_check_output(app)
|
||||
|
||||
@timed(TIMEOUT)
|
||||
def test_add_flow_v12_actions(self):
|
||||
app = 'os_ken/tests/integrated/test_add_flow_v12_actions.py'
|
||||
self._run_os_ken_manager_and_check_output(app)
|
||||
|
||||
@timed(TIMEOUT)
|
||||
def test_add_flow_v12_matches(self):
|
||||
app = 'os_ken/tests/integrated/test_add_flow_v12_matches.py'
|
||||
self._run_os_ken_manager_and_check_output(app)
|
||||
|
||||
@nottest
|
||||
def test_of_config(self):
|
||||
# OVS 1.10 does not support of_config
|
||||
pass
|
||||
self.skipTest('OVS 1.10 does not support of_config')
|
||||
|
||||
def _run_os_ken_manager_and_check_output(self, app):
|
||||
cmd = [PYTHON_BIN, OSKEN_MGR, app]
|
||||
@ -99,11 +92,7 @@ class TestWithOVS12(unittest.TestCase):
|
||||
|
||||
print("osken-manager: %s" % line)
|
||||
if line.find('TEST_FINISHED') != -1:
|
||||
ok_(line.find('Completed=[True]') != -1)
|
||||
self.assertTrue(line.find('Completed=[True]') != -1)
|
||||
p.terminate()
|
||||
p.communicate() # wait for subprocess is terminated
|
||||
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
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from nose.tools import eq_, raises
|
||||
|
||||
try:
|
||||
# Python 3
|
||||
from imp import reload
|
||||
except ImportError:
|
||||
# Python 2
|
||||
pass
|
||||
from imp import reload
|
||||
|
||||
from os_ken.cmd.manager import main
|
||||
|
||||
@ -43,15 +35,13 @@ class Test_Manager(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@raises(SystemExit)
|
||||
@mock.patch('sys.argv', new=['osken-manager', '--version'])
|
||||
def test_version(self):
|
||||
main()
|
||||
self.assertRaises(SystemExit, main)
|
||||
|
||||
@raises(SystemExit)
|
||||
@mock.patch('sys.argv', new=['osken-manager', '--help'])
|
||||
def test_help(self):
|
||||
main()
|
||||
self.assertRaises(SystemExit, main)
|
||||
|
||||
@staticmethod
|
||||
def _reset_globals():
|
||||
|
@ -22,11 +22,10 @@ import sys
|
||||
import warnings
|
||||
import logging
|
||||
import random
|
||||
import testtools
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from nose.tools import eq_, raises
|
||||
|
||||
from os_ken.base import app_manager # To suppress cyclic import
|
||||
from os_ken.controller import controller
|
||||
from os_ken.controller import handler
|
||||
@ -40,36 +39,35 @@ hub.patch()
|
||||
LOG = logging.getLogger('test_controller')
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
class TestUtils(testtools.TestCase):
|
||||
"""
|
||||
Test cases for utilities defined in controller module.
|
||||
"""
|
||||
|
||||
def test_split_addr_with_ipv4(self):
|
||||
addr, port = controller._split_addr('127.0.0.1:6653')
|
||||
eq_('127.0.0.1', addr)
|
||||
eq_(6653, port)
|
||||
self.assertEqual('127.0.0.1', addr)
|
||||
self.assertEqual(6653, port)
|
||||
|
||||
def test_split_addr_with_ipv6(self):
|
||||
addr, port = controller._split_addr('[::1]:6653')
|
||||
eq_('::1', addr)
|
||||
eq_(6653, port)
|
||||
self.assertEqual('::1', addr)
|
||||
self.assertEqual(6653, port)
|
||||
|
||||
@raises(ValueError)
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
controller._split_addr('::1:6653')
|
||||
self.assertRaises(ValueError, controller._split_addr,
|
||||
'::1:6653')
|
||||
|
||||
|
||||
class Test_Datapath(unittest.TestCase):
|
||||
@ -176,53 +174,3 @@ class Test_Datapath(unittest.TestCase):
|
||||
self.assertEqual(state, handler.MAIN_DISPATCHER)
|
||||
self.assertEqual(kwargs, {})
|
||||
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.
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
import platform
|
||||
import sys
|
||||
from nose.tools import eq_
|
||||
|
||||
from os_ken.lib import sockaddr
|
||||
|
||||
|
||||
system = platform.system()
|
||||
|
||||
|
||||
@ -38,7 +37,7 @@ class Test_sockaddr(unittest.TestCase):
|
||||
addr = '127.0.0.1'
|
||||
expected_result = (b'\x02\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):
|
||||
if system != 'Linux' or sys.byteorder != 'little':
|
||||
@ -47,9 +46,9 @@ class Test_sockaddr(unittest.TestCase):
|
||||
addr = 'dead:beef::1'
|
||||
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')
|
||||
eq_(expected_result, sockaddr.sa_in6(addr))
|
||||
self.assertEqual(expected_result, sockaddr.sa_in6(addr))
|
||||
|
||||
def test_sockaddr_sa_to_ss(self):
|
||||
addr = b'\x01'
|
||||
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 logging
|
||||
from nose.tools import eq_
|
||||
from os_ken.ofproto.ether import *
|
||||
|
||||
|
||||
@ -29,9 +28,9 @@ class TestInet(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def test_ether_type(self):
|
||||
eq_(ETH_TYPE_IP, 0x0800)
|
||||
eq_(ETH_TYPE_ARP, 0x0806)
|
||||
eq_(ETH_TYPE_8021Q, 0x8100)
|
||||
eq_(ETH_TYPE_IPV6, 0x86dd)
|
||||
eq_(ETH_TYPE_MPLS, 0x8847)
|
||||
eq_(ETH_TYPE_SLOW, 0x8809)
|
||||
self.assertEqual(ETH_TYPE_IP, 0x0800)
|
||||
self.assertEqual(ETH_TYPE_ARP, 0x0806)
|
||||
self.assertEqual(ETH_TYPE_8021Q, 0x8100)
|
||||
self.assertEqual(ETH_TYPE_IPV6, 0x86dd)
|
||||
self.assertEqual(ETH_TYPE_MPLS, 0x8847)
|
||||
self.assertEqual(ETH_TYPE_SLOW, 0x8809)
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
from nose.tools import eq_
|
||||
from os_ken.ofproto.inet import *
|
||||
|
||||
|
||||
@ -29,15 +28,15 @@ class TestInet(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def test_ip_proto(self):
|
||||
eq_(IPPROTO_IP, 0)
|
||||
eq_(IPPROTO_HOPOPTS, 0)
|
||||
eq_(IPPROTO_ICMP, 1)
|
||||
eq_(IPPROTO_TCP, 6)
|
||||
eq_(IPPROTO_UDP, 17)
|
||||
eq_(IPPROTO_ROUTING, 43)
|
||||
eq_(IPPROTO_FRAGMENT, 44)
|
||||
eq_(IPPROTO_AH, 51)
|
||||
eq_(IPPROTO_ICMPV6, 58)
|
||||
eq_(IPPROTO_NONE, 59)
|
||||
eq_(IPPROTO_DSTOPTS, 60)
|
||||
eq_(IPPROTO_SCTP, 132)
|
||||
self.assertEqual(IPPROTO_IP, 0)
|
||||
self.assertEqual(IPPROTO_HOPOPTS, 0)
|
||||
self.assertEqual(IPPROTO_ICMP, 1)
|
||||
self.assertEqual(IPPROTO_TCP, 6)
|
||||
self.assertEqual(IPPROTO_UDP, 17)
|
||||
self.assertEqual(IPPROTO_ROUTING, 43)
|
||||
self.assertEqual(IPPROTO_FRAGMENT, 44)
|
||||
self.assertEqual(IPPROTO_AH, 51)
|
||||
self.assertEqual(IPPROTO_ICMPV6, 58)
|
||||
self.assertEqual(IPPROTO_NONE, 59)
|
||||
self.assertEqual(IPPROTO_DSTOPTS, 60)
|
||||
self.assertEqual(IPPROTO_SCTP, 132)
|
||||
|
@ -16,16 +16,10 @@
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
try:
|
||||
# Python 3
|
||||
from imp import reload
|
||||
except ImportError:
|
||||
# Python 2
|
||||
pass
|
||||
from imp import reload
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
from nose.tools import eq_
|
||||
|
||||
|
||||
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_4
|
||||
import os_ken.ofproto.ofproto_v1_5
|
||||
eq_(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_3.OFP_VERSION,
|
||||
os_ken.ofproto.ofproto_v1_4.OFP_VERSION,
|
||||
os_ken.ofproto.ofproto_v1_5.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_3.OFP_VERSION,
|
||||
os_ken.ofproto.ofproto_v1_4.OFP_VERSION,
|
||||
os_ken.ofproto.ofproto_v1_5.OFP_VERSION,
|
||||
]))
|
||||
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_3,
|
||||
os_ken.ofproto.ofproto_v1_4,
|
||||
os_ken.ofproto.ofproto_v1_5,
|
||||
]))
|
||||
])
|
||||
)
|
||||
|
||||
parser_mods = set([ofp_mod[1] for ofp_mod in ofp_modules.values()])
|
||||
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_4_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_3_parser,
|
||||
os_ken.ofproto.ofproto_v1_4_parser,
|
||||
os_ken.ofproto.ofproto_v1_5_parser,
|
||||
]))
|
||||
])
|
||||
)
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
from nose.tools import eq_
|
||||
from os_ken.ofproto.ofproto_common import *
|
||||
|
||||
|
||||
@ -29,9 +28,9 @@ class TestOfprotCommon(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def test_struct_ofp_header(self):
|
||||
eq_(OFP_HEADER_PACK_STR, '!BBHI')
|
||||
eq_(OFP_HEADER_SIZE, 8)
|
||||
self.assertEqual(OFP_HEADER_PACK_STR, '!BBHI')
|
||||
self.assertEqual(OFP_HEADER_SIZE, 8)
|
||||
|
||||
def test_define_constants(self):
|
||||
eq_(OFP_TCP_PORT, 6653)
|
||||
eq_(OFP_SSL_PORT, 6653)
|
||||
self.assertEqual(OFP_TCP_PORT, 6653)
|
||||
self.assertEqual(OFP_SSL_PORT, 6653)
|
||||
|
@ -19,7 +19,6 @@ import six
|
||||
|
||||
import binascii
|
||||
import unittest
|
||||
from nose.tools import *
|
||||
import struct
|
||||
from os_ken import exception
|
||||
|
||||
@ -68,10 +67,10 @@ class TestOfproto_Parser(unittest.TestCase):
|
||||
msg_type,
|
||||
msg_len,
|
||||
xid) = ofproto_parser.header(self.bufHello)
|
||||
eq_(version, 1)
|
||||
eq_(msg_type, 0)
|
||||
eq_(msg_len, 8)
|
||||
eq_(xid, 1)
|
||||
self.assertEqual(version, 1)
|
||||
self.assertEqual(msg_type, 0)
|
||||
self.assertEqual(msg_len, 8)
|
||||
self.assertEqual(xid, 1)
|
||||
|
||||
def testFeaturesReply(self):
|
||||
(version,
|
||||
@ -87,11 +86,11 @@ class TestOfproto_Parser(unittest.TestCase):
|
||||
self.bufFeaturesReply)
|
||||
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])
|
||||
ok_(isinstance(msg.ports[1], ofproto_v1_0_parser.OFPPhyPort))
|
||||
ok_(isinstance(msg.ports[2], ofproto_v1_0_parser.OFPPhyPort))
|
||||
ok_(isinstance(msg.ports[65534], ofproto_v1_0_parser.OFPPhyPort))
|
||||
self.assertTrue(isinstance(msg.ports[1], ofproto_v1_0_parser.OFPPhyPort))
|
||||
self.assertTrue(isinstance(msg.ports[2], ofproto_v1_0_parser.OFPPhyPort))
|
||||
self.assertTrue(isinstance(msg.ports[65534], ofproto_v1_0_parser.OFPPhyPort))
|
||||
|
||||
def testPacketIn(self):
|
||||
(version,
|
||||
@ -106,9 +105,8 @@ class TestOfproto_Parser(unittest.TestCase):
|
||||
xid,
|
||||
self.bufPacketIn)
|
||||
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):
|
||||
(version,
|
||||
msg_type,
|
||||
@ -116,14 +114,9 @@ class TestOfproto_Parser(unittest.TestCase):
|
||||
xid) = ofproto_parser.header(self.bufPacketIn)
|
||||
|
||||
msg_len = len(self.bufPacketIn) + 1
|
||||
ofproto_parser.msg(self,
|
||||
version,
|
||||
msg_type,
|
||||
msg_len,
|
||||
xid,
|
||||
self.bufPacketIn)
|
||||
self.assertRaises(AssertionError, ofproto_parser.msg, self, version,
|
||||
msg_type, msg_len, xid, self.bufPacketIn)
|
||||
|
||||
@raises(exception.OFPUnknownVersion)
|
||||
def test_check_msg_parser(self):
|
||||
(version,
|
||||
msg_type,
|
||||
@ -131,12 +124,9 @@ class TestOfproto_Parser(unittest.TestCase):
|
||||
xid) = ofproto_parser.header(self.bufPacketIn)
|
||||
|
||||
version = 0xff
|
||||
ofproto_parser.msg(self,
|
||||
version,
|
||||
msg_type,
|
||||
msg_len,
|
||||
xid,
|
||||
self.bufPacketIn)
|
||||
self.assertRaises(exception.OFPUnknownVersion, ofproto_parser.msg,
|
||||
self, version, msg_type, msg_len, xid,
|
||||
self.bufPacketIn)
|
||||
|
||||
|
||||
class TestMsgBase(unittest.TestCase):
|
||||
@ -156,14 +146,13 @@ class TestMsgBase(unittest.TestCase):
|
||||
xid = 3841413783
|
||||
c = ofproto_parser.MsgBase(object)
|
||||
c.set_xid(xid)
|
||||
eq_(xid, c.xid)
|
||||
self.assertEqual(xid, c.xid)
|
||||
|
||||
@raises(AssertionError)
|
||||
def test_set_xid_check_xid(self):
|
||||
xid = 2160492514
|
||||
c = ofproto_parser.MsgBase(object)
|
||||
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):
|
||||
version = ofproto_v1_0.OFP_VERSION
|
||||
@ -178,11 +167,11 @@ class TestMsgBase(unittest.TestCase):
|
||||
res = ofproto_v1_0_parser.OFPHello.parser(
|
||||
object, version, msg_type, msg_len, xid, bytearray(buf))
|
||||
|
||||
eq_(version, res.version)
|
||||
eq_(msg_type, res.msg_type)
|
||||
eq_(msg_len, res.msg_len)
|
||||
eq_(xid, res.xid)
|
||||
eq_(buffer(buf), res.buf)
|
||||
self.assertEqual(version, res.version)
|
||||
self.assertEqual(msg_type, res.msg_type)
|
||||
self.assertEqual(msg_len, res.msg_len)
|
||||
self.assertEqual(xid, res.xid)
|
||||
self.assertEqual(buffer(buf), res.buf)
|
||||
|
||||
# test __str__()
|
||||
list_ = ('version', 'msg_type', 'msg_len', 'xid')
|
||||
@ -193,19 +182,19 @@ class TestMsgBase(unittest.TestCase):
|
||||
if k in list_:
|
||||
check[k] = v
|
||||
|
||||
eq_(hex(ofproto_v1_0.OFP_VERSION), check['version'])
|
||||
eq_(hex(ofproto_v1_0.OFPT_HELLO), check['msg_type'])
|
||||
eq_(hex(msg_len), check['msg_len'])
|
||||
eq_(hex(xid), check['xid'])
|
||||
self.assertEqual(hex(ofproto_v1_0.OFP_VERSION), check['version'])
|
||||
self.assertEqual(hex(ofproto_v1_0.OFPT_HELLO), check['msg_type'])
|
||||
self.assertEqual(hex(msg_len), check['msg_len'])
|
||||
self.assertEqual(hex(xid), check['xid'])
|
||||
|
||||
return True
|
||||
|
||||
def test_parser(self):
|
||||
ok_(self._test_parser())
|
||||
self.assertTrue(self._test_parser())
|
||||
|
||||
@raises(AssertionError)
|
||||
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):
|
||||
|
||||
@ -216,14 +205,14 @@ class TestMsgBase(unittest.TestCase):
|
||||
c = ofproto_v1_0_parser.OFPHello(Datapath)
|
||||
|
||||
c.serialize()
|
||||
eq_(ofproto_v1_0.OFP_VERSION, c.version)
|
||||
eq_(ofproto_v1_0.OFPT_HELLO, c.msg_type)
|
||||
eq_(0, c.xid)
|
||||
self.assertEqual(ofproto_v1_0.OFP_VERSION, c.version)
|
||||
self.assertEqual(ofproto_v1_0.OFPT_HELLO, c.msg_type)
|
||||
self.assertEqual(0, c.xid)
|
||||
|
||||
return True
|
||||
|
||||
def test_serialize(self):
|
||||
ok_(self._test_serialize())
|
||||
self.assertTrue(self._test_serialize())
|
||||
|
||||
|
||||
class TestMsgStrAttr(unittest.TestCase):
|
||||
@ -240,5 +229,5 @@ class TestMsgStrAttr(unittest.TestCase):
|
||||
res = ofproto_parser.msg_str_attr(c, buf, ('check',))
|
||||
str_ = str(res)
|
||||
str_ = str_.rsplit()
|
||||
eq_('check', str_[0])
|
||||
eq_('msg_str_attr_test', str_[1])
|
||||
self.assertEqual('check', str_[0])
|
||||
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
|
||||
# limitations under the License.
|
||||
|
||||
import os.path
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
import testscenarios
|
||||
|
||||
from os_ken.ofproto import ofproto_parser
|
||||
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_4
|
||||
from os_ken.ofproto import ofproto_v1_5
|
||||
from os_ken.tests import test_lib
|
||||
from os_ken import exception
|
||||
import json
|
||||
|
||||
@ -153,13 +153,53 @@ implemented = {
|
||||
}
|
||||
|
||||
|
||||
class Test_Parser(unittest.TestCase):
|
||||
""" Test case for os_ken.ofproto, especially json representation
|
||||
"""
|
||||
def _list_test_cases():
|
||||
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)
|
||||
super(Test_Parser, self).__init__(methodName)
|
||||
|
||||
class Test_Parser(testscenarios.WithScenarios, unittest.TestCase):
|
||||
"""Test case for os_ken.ofproto, especially json representation"""
|
||||
|
||||
scenarios = [(case['name'], case) for case in _list_test_cases()]
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
@ -175,6 +215,10 @@ class Test_Parser(unittest.TestCase):
|
||||
def _jsondict_to_msg(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 bytes_eq(buf1, buf2):
|
||||
if buf1 != buf2:
|
||||
@ -206,8 +250,9 @@ class Test_Parser(unittest.TestCase):
|
||||
json_dict2 = {'OFPTruncatedMessage':
|
||||
self._msg_to_jsondict(e.ofpmsg)}
|
||||
# XXXdebug code
|
||||
open(('/tmp/%s.json' % name), 'w').write(json.dumps(json_dict2))
|
||||
eq_(json_dict, json_dict2)
|
||||
with open(('/tmp/%s.json' % name), 'w') as _file:
|
||||
_file.write(json.dumps(json_dict2))
|
||||
self.assertEqual(json_dict, json_dict2)
|
||||
if 'OFPTruncatedMessage' in json_dict2:
|
||||
return
|
||||
|
||||
@ -217,7 +262,7 @@ class Test_Parser(unittest.TestCase):
|
||||
msg2.set_xid(xid)
|
||||
if has_serializer:
|
||||
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)
|
||||
|
||||
# check if "len" "length" fields can be omitted
|
||||
@ -243,67 +288,3 @@ class Test_Parser(unittest.TestCase):
|
||||
|
||||
msg2.serialize()
|
||||
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.
|
||||
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
import testscenarios
|
||||
|
||||
from os_ken.ofproto import ofproto_v1_2
|
||||
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.lib import addrconv
|
||||
from os_ken.tests import test_lib
|
||||
from struct import unpack
|
||||
|
||||
|
||||
class Test_Parser_Compat(unittest.TestCase):
|
||||
def __init__(self, methodName):
|
||||
print('init %s' % methodName)
|
||||
super(Test_Parser_Compat, self).__init__(methodName)
|
||||
def _list_test_cases():
|
||||
ofpps = [ofproto_v1_2_parser, ofproto_v1_3_parser]
|
||||
cases = []
|
||||
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):
|
||||
pass
|
||||
@ -41,6 +47,9 @@ class Test_Parser_Compat(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_parser(self):
|
||||
self._test(name=self.name, ofpp=self.ofpp)
|
||||
|
||||
def _test(self, name, ofpp):
|
||||
ofp = {
|
||||
ofproto_v1_2_parser: ofproto_v1_2,
|
||||
@ -70,17 +79,17 @@ class Test_Parser_Compat(unittest.TestCase):
|
||||
return f
|
||||
get_value = lambda m, t: get_field(m, t).value
|
||||
|
||||
eq_(get_value(o, ofpp.MTInPort), old_in_port)
|
||||
eq_(get_value(o, ofpp.MTEthSrc), old_eth_src)
|
||||
eq_(get_value(o, ofpp.MTIPV4Src), old_ipv4_src)
|
||||
eq_(get_value(o, ofpp.MTIPv6Src), old_ipv6_src)
|
||||
self.assertEqual(get_value(o, ofpp.MTInPort), old_in_port)
|
||||
self.assertEqual(get_value(o, ofpp.MTEthSrc), old_eth_src)
|
||||
self.assertEqual(get_value(o, ofpp.MTIPV4Src), old_ipv4_src)
|
||||
self.assertEqual(get_value(o, ofpp.MTIPv6Src), old_ipv6_src)
|
||||
|
||||
def check_new(o):
|
||||
# new api
|
||||
eq_(o['in_port'], in_port)
|
||||
eq_(o['eth_src'], eth_src)
|
||||
eq_(o['ipv4_src'], ipv4_src)
|
||||
eq_(o['ipv6_src'], ipv6_src)
|
||||
self.assertEqual(o['in_port'], in_port)
|
||||
self.assertEqual(o['eth_src'], eth_src)
|
||||
self.assertEqual(o['ipv4_src'], ipv4_src)
|
||||
self.assertEqual(o['ipv6_src'], ipv6_src)
|
||||
|
||||
# ensure that old and new api produces the same thing
|
||||
|
||||
@ -117,43 +126,19 @@ class Test_Parser_Compat(unittest.TestCase):
|
||||
|
||||
new_buf = bytearray()
|
||||
new.serialize(new_buf, 0)
|
||||
eq_(new_buf, old_buf)
|
||||
eq_(new_buf, old2_buf)
|
||||
self.assertEqual(new_buf, old_buf)
|
||||
self.assertEqual(new_buf, old2_buf)
|
||||
|
||||
old_jsondict = old.to_jsondict()
|
||||
old2_jsondict = old2.to_jsondict()
|
||||
new_jsondict = new.to_jsondict()
|
||||
eq_(new_jsondict, old_jsondict)
|
||||
eq_(new_jsondict, old2_jsondict)
|
||||
self.assertEqual(new_jsondict, old_jsondict)
|
||||
self.assertEqual(new_jsondict, old2_jsondict)
|
||||
|
||||
eq_(str(new), str(old))
|
||||
eq_(str(new), str(old2))
|
||||
self.assertEqual(str(new), str(old))
|
||||
self.assertEqual(str(new), str(old2))
|
||||
|
||||
# a parsed object can be inspected by old and new api
|
||||
|
||||
check(ofpp.OFPMatch.parser(six.binary_type(new_buf), 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
|
||||
# limitations under the License.
|
||||
|
||||
try:
|
||||
# Python 3
|
||||
from functools import reduce
|
||||
except ImportError:
|
||||
# Python 2
|
||||
pass
|
||||
|
||||
import functools
|
||||
import itertools
|
||||
import six
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
import testscenarios
|
||||
|
||||
from os_ken.ofproto import ofproto_v1_2
|
||||
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_4_parser
|
||||
from os_ken.ofproto import ofproto_v1_5_parser
|
||||
from os_ken.tests import test_lib
|
||||
|
||||
|
||||
class Test_Parser_OFPMatch(unittest.TestCase):
|
||||
_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
|
||||
def _list_test_cases():
|
||||
|
||||
class Field(object):
|
||||
@classmethod
|
||||
@ -238,8 +191,9 @@ def _add_tests():
|
||||
return l + flatten(i)
|
||||
else:
|
||||
return l + [i]
|
||||
flatten = lambda l: reduce(flatten_one, l, [])
|
||||
flatten = lambda l: functools.reduce(flatten_one, l, [])
|
||||
|
||||
cases = []
|
||||
for ofpp in ofpps:
|
||||
for n in range(1, 3):
|
||||
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(' ', '_')
|
||||
|
||||
def _run(self, name, ofpp, d, domask):
|
||||
print('processing %s ...' % name)
|
||||
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)
|
||||
cases.append({'name': method_name, 'ofpp': ofpp,
|
||||
'd': d, 'domask': domask})
|
||||
return cases
|
||||
|
||||
|
||||
_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
|
||||
# limitations under the License.
|
||||
|
||||
try:
|
||||
# Python 3
|
||||
from functools import reduce
|
||||
except ImportError:
|
||||
# Python 2
|
||||
pass
|
||||
from functools import reduce
|
||||
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
import testscenarios
|
||||
|
||||
from os_ken.ofproto import ofproto_v1_5
|
||||
from os_ken.ofproto import ofproto_v1_5_parser
|
||||
from os_ken.tests import test_lib
|
||||
|
||||
|
||||
class Test_Parser_OFPStats(unittest.TestCase):
|
||||
_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():
|
||||
def _list_test_cases():
|
||||
import functools
|
||||
import itertools
|
||||
|
||||
@ -159,6 +120,7 @@ def _add_tests():
|
||||
return l + [i]
|
||||
flatten = lambda l: reduce(flatten_one, l, [])
|
||||
|
||||
cases = []
|
||||
for ofpp in ofpps:
|
||||
for n in range(1, 3):
|
||||
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(' ', '_')
|
||||
|
||||
def _run(self, name, ofpp, d):
|
||||
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)
|
||||
cases.append({'name': method_name, 'ofpp': ofpp, 'd': d})
|
||||
return cases
|
||||
|
||||
|
||||
_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 socket
|
||||
from struct import *
|
||||
from nose.tools 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_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')
|
||||
|
||||
@ -45,10 +39,10 @@ class TestOFPMatch(unittest.TestCase):
|
||||
res = OFPMatch()
|
||||
|
||||
# wc check
|
||||
eq_(res._wc.vlan_vid_mask, 0)
|
||||
self.assertEqual(res._wc.vlan_vid_mask, 0)
|
||||
|
||||
# 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):
|
||||
cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
|
||||
@ -58,34 +52,34 @@ class TestOFPMatch(unittest.TestCase):
|
||||
# serialize
|
||||
buf = bytearray()
|
||||
length = match.serialize(buf, 0)
|
||||
eq_(length, len(buf))
|
||||
self.assertEqual(length, len(buf))
|
||||
if mask and len(buf) > calcsize(fmt):
|
||||
fmt += pack_str
|
||||
|
||||
res = list(unpack_from(fmt, six.binary_type(buf), 0)[3:])
|
||||
if type(value) is list:
|
||||
res_value = res[:calcsize(pack_str) // 2]
|
||||
eq_(res_value, value)
|
||||
self.assertEqual(res_value, value)
|
||||
if mask:
|
||||
res_mask = res[calcsize(pack_str) // 2:]
|
||||
eq_(res_mask, mask)
|
||||
self.assertEqual(res_mask, mask)
|
||||
else:
|
||||
res_value = res.pop(0)
|
||||
if cls_.__name__ == 'MTVlanVid':
|
||||
eq_(res_value, value | ofproto.OFPVID_PRESENT)
|
||||
self.assertEqual(res_value, value | ofproto.OFPVID_PRESENT)
|
||||
else:
|
||||
eq_(res_value, value)
|
||||
self.assertEqual(res_value, value)
|
||||
if mask and res and res[0]:
|
||||
res_mask = res[0]
|
||||
eq_(res_mask, mask)
|
||||
self.assertEqual(res_mask, mask)
|
||||
|
||||
# parser
|
||||
res = match.parser(six.binary_type(buf), 0)
|
||||
eq_(res.type, ofproto.OFPMT_OXM)
|
||||
eq_(res.fields[0].header, header)
|
||||
eq_(res.fields[0].value, value)
|
||||
self.assertEqual(res.type, ofproto.OFPMT_OXM)
|
||||
self.assertEqual(res.fields[0].header, header)
|
||||
self.assertEqual(res.fields[0].value, value)
|
||||
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
|
||||
jsondict = match.to_jsondict()
|
||||
@ -94,8 +88,8 @@ class TestOFPMatch(unittest.TestCase):
|
||||
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
||||
buf2 = bytearray()
|
||||
match2.serialize(buf2, 0)
|
||||
eq_(str(match), str(match2))
|
||||
eq_(buf, buf2)
|
||||
self.assertEqual(str(match), str(match2))
|
||||
self.assertEqual(buf, buf2)
|
||||
|
||||
# set_vlan_vid
|
||||
def _test_set_vlan_vid(self, vid, mask=None):
|
||||
@ -120,17 +114,17 @@ class TestOFPMatch(unittest.TestCase):
|
||||
# serialize
|
||||
buf = bytearray()
|
||||
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_value = res.pop(0)
|
||||
eq_(res_value, value)
|
||||
self.assertEqual(res_value, value)
|
||||
|
||||
# parser
|
||||
res = match.parser(six.binary_type(buf), 0)
|
||||
eq_(res.type, ofproto.OFPMT_OXM)
|
||||
eq_(res.fields[0].header, header)
|
||||
eq_(res.fields[0].value, value)
|
||||
self.assertEqual(res.type, ofproto.OFPMT_OXM)
|
||||
self.assertEqual(res.fields[0].header, header)
|
||||
self.assertEqual(res.fields[0].value, value)
|
||||
|
||||
# to_jsondict
|
||||
jsondict = match.to_jsondict()
|
||||
@ -139,8 +133,8 @@ class TestOFPMatch(unittest.TestCase):
|
||||
match2 = match.from_jsondict(jsondict["OFPMatch"])
|
||||
buf2 = bytearray()
|
||||
match2.serialize(buf2, 0)
|
||||
eq_(str(match), str(match2))
|
||||
eq_(buf, buf2)
|
||||
self.assertEqual(str(match), str(match2))
|
||||
self.assertEqual(buf, buf2)
|
||||
|
||||
def test_set_vlan_vid_mid(self):
|
||||
self._test_set_vlan_vid(2047)
|
||||
|
@ -19,7 +19,6 @@ import unittest
|
||||
import logging
|
||||
import struct
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import ether
|
||||
from os_ken.lib.packet.ethernet import ethernet
|
||||
from os_ken.lib.packet.packet import Packet
|
||||
@ -67,15 +66,15 @@ class Test_arp(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.hwtype, self.a.hwtype)
|
||||
eq_(self.proto, self.a.proto)
|
||||
eq_(self.hlen, self.a.hlen)
|
||||
eq_(self.plen, self.a.plen)
|
||||
eq_(self.opcode, self.a.opcode)
|
||||
eq_(self.src_mac, self.a.src_mac)
|
||||
eq_(self.src_ip, self.a.src_ip)
|
||||
eq_(self.dst_mac, self.a.dst_mac)
|
||||
eq_(self.dst_ip, self.a.dst_ip)
|
||||
self.assertEqual(self.hwtype, self.a.hwtype)
|
||||
self.assertEqual(self.proto, self.a.proto)
|
||||
self.assertEqual(self.hlen, self.a.hlen)
|
||||
self.assertEqual(self.plen, self.a.plen)
|
||||
self.assertEqual(self.opcode, self.a.opcode)
|
||||
self.assertEqual(self.src_mac, self.a.src_mac)
|
||||
self.assertEqual(self.src_ip, self.a.src_ip)
|
||||
self.assertEqual(self.dst_mac, self.a.dst_mac)
|
||||
self.assertEqual(self.dst_ip, self.a.dst_ip)
|
||||
|
||||
def test_parser(self):
|
||||
_res = self.a.parser(self.buf)
|
||||
@ -84,15 +83,15 @@ class Test_arp(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(res.hwtype, self.hwtype)
|
||||
eq_(res.proto, self.proto)
|
||||
eq_(res.hlen, self.hlen)
|
||||
eq_(res.plen, self.plen)
|
||||
eq_(res.opcode, self.opcode)
|
||||
eq_(res.src_mac, self.src_mac)
|
||||
eq_(res.src_ip, self.src_ip)
|
||||
eq_(res.dst_mac, self.dst_mac)
|
||||
eq_(res.dst_ip, self.dst_ip)
|
||||
self.assertEqual(res.hwtype, self.hwtype)
|
||||
self.assertEqual(res.proto, self.proto)
|
||||
self.assertEqual(res.hlen, self.hlen)
|
||||
self.assertEqual(res.plen, self.plen)
|
||||
self.assertEqual(res.opcode, self.opcode)
|
||||
self.assertEqual(res.src_mac, self.src_mac)
|
||||
self.assertEqual(res.src_ip, self.src_ip)
|
||||
self.assertEqual(res.dst_mac, self.dst_mac)
|
||||
self.assertEqual(res.dst_ip, self.dst_ip)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -102,15 +101,15 @@ class Test_arp(unittest.TestCase):
|
||||
fmt = arp._PACK_STR
|
||||
res = struct.unpack(fmt, buf)
|
||||
|
||||
eq_(res[0], self.hwtype)
|
||||
eq_(res[1], self.proto)
|
||||
eq_(res[2], self.hlen)
|
||||
eq_(res[3], self.plen)
|
||||
eq_(res[4], self.opcode)
|
||||
eq_(res[5], addrconv.mac.text_to_bin(self.src_mac))
|
||||
eq_(res[6], addrconv.ipv4.text_to_bin(self.src_ip))
|
||||
eq_(res[7], addrconv.mac.text_to_bin(self.dst_mac))
|
||||
eq_(res[8], addrconv.ipv4.text_to_bin(self.dst_ip))
|
||||
self.assertEqual(res[0], self.hwtype)
|
||||
self.assertEqual(res[1], self.proto)
|
||||
self.assertEqual(res[2], self.hlen)
|
||||
self.assertEqual(res[3], self.plen)
|
||||
self.assertEqual(res[4], self.opcode)
|
||||
self.assertEqual(res[5], addrconv.mac.text_to_bin(self.src_mac))
|
||||
self.assertEqual(res[6], addrconv.ipv4.text_to_bin(self.src_ip))
|
||||
self.assertEqual(res[7], addrconv.mac.text_to_bin(self.dst_mac))
|
||||
self.assertEqual(res[8], addrconv.ipv4.text_to_bin(self.dst_ip))
|
||||
|
||||
def _build_arp(self, vlan_enabled):
|
||||
if vlan_enabled is True:
|
||||
@ -132,52 +131,51 @@ class Test_arp(unittest.TestCase):
|
||||
p = self._build_arp(True)
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||
|
||||
v = self.find_protocol(p, "vlan")
|
||||
ok_(v)
|
||||
eq_(v.ethertype, ether.ETH_TYPE_ARP)
|
||||
self.assertTrue(v)
|
||||
self.assertEqual(v.ethertype, ether.ETH_TYPE_ARP)
|
||||
|
||||
a = self.find_protocol(p, "arp")
|
||||
ok_(a)
|
||||
self.assertTrue(a)
|
||||
|
||||
eq_(a.hwtype, self.hwtype)
|
||||
eq_(a.proto, self.proto)
|
||||
eq_(a.hlen, self.hlen)
|
||||
eq_(a.plen, self.plen)
|
||||
eq_(a.opcode, self.opcode)
|
||||
eq_(a.src_mac, self.src_mac)
|
||||
eq_(a.src_ip, self.src_ip)
|
||||
eq_(a.dst_mac, self.dst_mac)
|
||||
eq_(a.dst_ip, self.dst_ip)
|
||||
self.assertEqual(a.hwtype, self.hwtype)
|
||||
self.assertEqual(a.proto, self.proto)
|
||||
self.assertEqual(a.hlen, self.hlen)
|
||||
self.assertEqual(a.plen, self.plen)
|
||||
self.assertEqual(a.opcode, self.opcode)
|
||||
self.assertEqual(a.src_mac, self.src_mac)
|
||||
self.assertEqual(a.src_ip, self.src_ip)
|
||||
self.assertEqual(a.dst_mac, self.dst_mac)
|
||||
self.assertEqual(a.dst_ip, self.dst_ip)
|
||||
|
||||
def test_build_arp_novlan(self):
|
||||
p = self._build_arp(False)
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_ARP)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_ARP)
|
||||
|
||||
a = self.find_protocol(p, "arp")
|
||||
ok_(a)
|
||||
self.assertTrue(a)
|
||||
|
||||
eq_(a.hwtype, self.hwtype)
|
||||
eq_(a.proto, self.proto)
|
||||
eq_(a.hlen, self.hlen)
|
||||
eq_(a.plen, self.plen)
|
||||
eq_(a.opcode, self.opcode)
|
||||
eq_(a.src_mac, self.src_mac)
|
||||
eq_(a.src_ip, self.src_ip)
|
||||
eq_(a.dst_mac, self.dst_mac)
|
||||
eq_(a.dst_ip, self.dst_ip)
|
||||
self.assertEqual(a.hwtype, self.hwtype)
|
||||
self.assertEqual(a.proto, self.proto)
|
||||
self.assertEqual(a.hlen, self.hlen)
|
||||
self.assertEqual(a.plen, self.plen)
|
||||
self.assertEqual(a.opcode, self.opcode)
|
||||
self.assertEqual(a.src_mac, self.src_mac)
|
||||
self.assertEqual(a.src_ip, self.src_ip)
|
||||
self.assertEqual(a.dst_mac, self.dst_mac)
|
||||
self.assertEqual(a.dst_ip, self.dst_ip)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_arp(self):
|
||||
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):
|
||||
jsondict = self.a.to_jsondict()
|
||||
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 struct
|
||||
import inspect
|
||||
from nose.tools import ok_, eq_, nottest
|
||||
|
||||
from os_ken.ofproto import ether
|
||||
from os_ken.ofproto import inet
|
||||
@ -95,52 +94,52 @@ class TestBFD(unittest.TestCase):
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
eq_(type(next(i)), ipv4.ipv4)
|
||||
eq_(type(next(i)), udp.udp)
|
||||
eq_(type(bfd.bfd.parser(next(i))[0]), bfd.bfd)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||
self.assertEqual(type(next(i)), udp.udp)
|
||||
self.assertEqual(type(bfd.bfd.parser(next(i))[0]), bfd.bfd)
|
||||
|
||||
def test_parse_with_auth_simple(self):
|
||||
buf = self.data_auth_simple
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
eq_(type(next(i)), ipv4.ipv4)
|
||||
eq_(type(next(i)), udp.udp)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||
self.assertEqual(type(next(i)), udp.udp)
|
||||
|
||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||
eq_(type(bfd_obj), bfd.bfd)
|
||||
eq_(type(bfd_obj.auth_cls), bfd.SimplePassword)
|
||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
||||
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||
self.assertEqual(type(bfd_obj.auth_cls), bfd.SimplePassword)
|
||||
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||
|
||||
def test_parse_with_auth_md5(self):
|
||||
buf = self.data_auth_md5
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
eq_(type(next(i)), ipv4.ipv4)
|
||||
eq_(type(next(i)), udp.udp)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||
self.assertEqual(type(next(i)), udp.udp)
|
||||
|
||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||
eq_(type(bfd_obj), bfd.bfd)
|
||||
eq_(type(bfd_obj.auth_cls), bfd.KeyedMD5)
|
||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
||||
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||
self.assertEqual(type(bfd_obj.auth_cls), bfd.KeyedMD5)
|
||||
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||
|
||||
def test_parse_with_auth_sha1(self):
|
||||
buf = self.data_auth_sha1
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
eq_(type(next(i)), ipv4.ipv4)
|
||||
eq_(type(next(i)), udp.udp)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), ipv4.ipv4)
|
||||
self.assertEqual(type(next(i)), udp.udp)
|
||||
|
||||
bfd_obj = bfd.bfd.parser(next(i))[0]
|
||||
eq_(type(bfd_obj), bfd.bfd)
|
||||
eq_(type(bfd_obj.auth_cls), bfd.KeyedSHA1)
|
||||
ok_(bfd_obj.authenticate(self.auth_keys))
|
||||
self.assertEqual(type(bfd_obj), bfd.bfd)
|
||||
self.assertEqual(type(bfd_obj.auth_cls), bfd.KeyedSHA1)
|
||||
self.assertTrue(bfd_obj.authenticate(self.auth_keys))
|
||||
|
||||
def test_serialize(self):
|
||||
pkt = packet.Packet()
|
||||
@ -162,10 +161,10 @@ class TestBFD(unittest.TestCase):
|
||||
required_min_echo_rx_interval=0)
|
||||
pkt.add_protocol(bfd_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 4)
|
||||
self.assertEqual(len(pkt.protocols), 4)
|
||||
|
||||
pkt.serialize()
|
||||
eq_(pkt.data, self.data)
|
||||
self.assertEqual(pkt.data, self.data)
|
||||
|
||||
def test_serialize_with_auth_simple(self):
|
||||
pkt = packet.Packet()
|
||||
@ -193,10 +192,10 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
pkt.add_protocol(bfd_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 4)
|
||||
self.assertEqual(len(pkt.protocols), 4)
|
||||
|
||||
pkt.serialize()
|
||||
eq_(pkt.data, self.data_auth_simple)
|
||||
self.assertEqual(pkt.data, self.data_auth_simple)
|
||||
|
||||
def test_serialize_with_auth_md5(self):
|
||||
pkt = packet.Packet()
|
||||
@ -224,10 +223,10 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
pkt.add_protocol(bfd_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 4)
|
||||
self.assertEqual(len(pkt.protocols), 4)
|
||||
|
||||
pkt.serialize()
|
||||
eq_(pkt.data, self.data_auth_md5)
|
||||
self.assertEqual(pkt.data, self.data_auth_md5)
|
||||
|
||||
def test_serialize_with_auth_sha1(self):
|
||||
pkt = packet.Packet()
|
||||
@ -255,10 +254,10 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
pkt.add_protocol(bfd_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 4)
|
||||
self.assertEqual(len(pkt.protocols), 4)
|
||||
|
||||
pkt.serialize()
|
||||
eq_(pkt.data, self.data_auth_sha1)
|
||||
self.assertEqual(pkt.data, self.data_auth_sha1)
|
||||
|
||||
def test_json(self):
|
||||
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()
|
||||
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):
|
||||
auth_cls = bfd.SimplePassword(auth_key_id=2,
|
||||
@ -285,7 +284,7 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
jsondict = bfd1.to_jsondict()
|
||||
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):
|
||||
auth_cls = bfd.KeyedMD5(auth_key_id=2, seq=16859,
|
||||
@ -301,7 +300,7 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
jsondict = bfd1.to_jsondict()
|
||||
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):
|
||||
auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16859,
|
||||
@ -317,4 +316,4 @@ class TestBFD(unittest.TestCase):
|
||||
|
||||
jsondict = bfd1.to_jsondict()
|
||||
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 unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.utils import binary_str
|
||||
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')
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(len(msg), 29)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(len(msg), 29)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_open2(self):
|
||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||
@ -172,17 +170,17 @@ class Test_bgp(unittest.TestCase):
|
||||
opt_param=opt_param)
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
ok_(len(msg) > 29)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertTrue(len(msg) > 29)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_update1(self):
|
||||
msg = bgp.BGPUpdate()
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(len(msg), 23)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(len(msg), 23)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_update2(self):
|
||||
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
||||
@ -313,34 +311,34 @@ class Test_bgp(unittest.TestCase):
|
||||
nlri=nlri)
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
ok_(len(msg) > 23)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertTrue(len(msg) > 23)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_keepalive(self):
|
||||
msg = bgp.BGPKeepAlive()
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(len(msg), 19)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(len(msg), 19)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_notification(self):
|
||||
data = b'hoge'
|
||||
msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(len(msg), 21 + len(data))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(len(msg), 21 + len(data))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_route_refresh(self):
|
||||
msg = bgp.BGPRouteRefresh(afi=afi.IP, safi=safi.MPLS_VPN)
|
||||
binmsg = msg.serialize()
|
||||
msg2, _, rest = bgp.BGPMessage.parser(binmsg)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(len(msg), 23)
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(len(msg), 23)
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_stream_parser(self):
|
||||
msgs = [
|
||||
@ -354,7 +352,7 @@ class Test_bgp(unittest.TestCase):
|
||||
for b in binmsgs:
|
||||
for m in sp.parse(b):
|
||||
results.append(m)
|
||||
eq_(str(results), str(msgs))
|
||||
self.assertEqual(str(results), str(msgs))
|
||||
|
||||
def test_parser(self):
|
||||
files = [
|
||||
@ -391,12 +389,12 @@ class Test_bgp(unittest.TestCase):
|
||||
open(BGP4_PACKET_DATA_DIR + f + '.pcap', 'rb')):
|
||||
# Checks if BGP message can be parsed as expected.
|
||||
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)
|
||||
|
||||
# Checks if BGP message can be serialized as expected.
|
||||
pkt.serialize()
|
||||
eq_(buf, pkt.data,
|
||||
self.assertEqual(buf, pkt.data,
|
||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||
|
||||
def test_vlan_action_parser(self):
|
||||
@ -411,8 +409,8 @@ class Test_bgp(unittest.TestCase):
|
||||
)
|
||||
binmsg = action.serialize()
|
||||
msg, rest = bgp.BGPFlowSpecVlanActionCommunity.parse(binmsg)
|
||||
eq_(str(action), str(msg))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(action), str(msg))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_tpid_action_parser(self):
|
||||
action = bgp.BGPFlowSpecTPIDActionCommunity(
|
||||
@ -423,8 +421,8 @@ class Test_bgp(unittest.TestCase):
|
||||
)
|
||||
binmsg = action.serialize()
|
||||
msg, rest = bgp.BGPFlowSpecTPIDActionCommunity.parse(binmsg)
|
||||
eq_(str(action), str(msg))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(action), str(msg))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_json1(self):
|
||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||
@ -439,7 +437,7 @@ class Test_bgp(unittest.TestCase):
|
||||
opt_param=opt_param)
|
||||
jsondict = msg1.to_jsondict()
|
||||
msg2 = bgp.BGPOpen.from_jsondict(jsondict['BGPOpen'])
|
||||
eq_(str(msg1), str(msg2))
|
||||
self.assertEqual(str(msg1), str(msg2))
|
||||
|
||||
def test_json2(self):
|
||||
withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
|
||||
@ -568,7 +566,7 @@ class Test_bgp(unittest.TestCase):
|
||||
nlri=nlri)
|
||||
jsondict = msg1.to_jsondict()
|
||||
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):
|
||||
rules = RULES_BASE + [
|
||||
@ -614,11 +612,11 @@ class Test_bgp(unittest.TestCase):
|
||||
msg2 = bgp.FlowSpecIPv4NLRI(rules=rules)
|
||||
binmsg = msg.serialize()
|
||||
binmsg2 = msg2.serialize()
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||
msg3, rest = bgp.FlowSpecIPv4NLRI.parser(binmsg)
|
||||
eq_(str(msg), str(msg3))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg3))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_flowspec_user_interface_vpv4(self):
|
||||
rules = RULES_BASE + [
|
||||
@ -664,11 +662,11 @@ class Test_bgp(unittest.TestCase):
|
||||
msg2 = bgp.FlowSpecVPNv4NLRI(route_dist='65001:250', rules=rules)
|
||||
binmsg = msg.serialize()
|
||||
binmsg2 = msg2.serialize()
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||
msg3, rest = bgp.FlowSpecVPNv4NLRI.parser(binmsg)
|
||||
eq_(str(msg), str(msg3))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg3))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_flowspec_user_interface_ipv6(self):
|
||||
rules = RULES_BASE + [
|
||||
@ -721,11 +719,11 @@ class Test_bgp(unittest.TestCase):
|
||||
msg2 = bgp.FlowSpecIPv6NLRI(rules=rules)
|
||||
binmsg = msg.serialize()
|
||||
binmsg2 = msg2.serialize()
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||
msg3, rest = bgp.FlowSpecIPv6NLRI.parser(binmsg)
|
||||
eq_(str(msg), str(msg3))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg3))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_flowspec_user_interface_vpnv6(self):
|
||||
rules = RULES_BASE + [
|
||||
@ -779,11 +777,11 @@ class Test_bgp(unittest.TestCase):
|
||||
msg2 = bgp.FlowSpecVPNv6NLRI(route_dist='65001:250', rules=rules)
|
||||
binmsg = msg.serialize()
|
||||
binmsg2 = msg2.serialize()
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||
msg3, rest = bgp.FlowSpecVPNv6NLRI.parser(binmsg)
|
||||
eq_(str(msg), str(msg3))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg3))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_flowspec_user_interface_l2vpn(self):
|
||||
rules = RULES_L2VPN_BASE
|
||||
@ -804,8 +802,8 @@ class Test_bgp(unittest.TestCase):
|
||||
msg2 = bgp.FlowSpecL2VPNNLRI(route_dist='65001:250', rules=rules)
|
||||
binmsg = msg.serialize()
|
||||
binmsg2 = msg2.serialize()
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(binary_str(binmsg), binary_str(binmsg2))
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(binary_str(binmsg), binary_str(binmsg2))
|
||||
msg3, rest = bgp.FlowSpecL2VPNNLRI.parser(binmsg)
|
||||
eq_(str(msg), str(msg3))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(str(msg), str(msg3))
|
||||
self.assertEqual(rest, b'')
|
||||
|
@ -14,8 +14,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
from time import time
|
||||
|
||||
from os_ken.lib.packet import bmp
|
||||
@ -51,8 +49,8 @@ class Test_bmp(unittest.TestCase):
|
||||
timestamp=self._time())
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_route_monitoring_adj_rib_out(self):
|
||||
update = bgp.BGPUpdate()
|
||||
@ -67,8 +65,8 @@ class Test_bmp(unittest.TestCase):
|
||||
timestamp=self._time())
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_statistics_report(self):
|
||||
stats = [{'type': bmp.BMP_STAT_TYPE_REJECTED, 'value': 100},
|
||||
@ -89,8 +87,8 @@ class Test_bmp(unittest.TestCase):
|
||||
timestamp=self._time())
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_peer_down_notification(self):
|
||||
reason = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
|
||||
@ -106,8 +104,8 @@ class Test_bmp(unittest.TestCase):
|
||||
timestamp=self._time())
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_peer_up_notification(self):
|
||||
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
|
||||
@ -131,8 +129,8 @@ class Test_bmp(unittest.TestCase):
|
||||
timestamp=self._time())
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(), msg2.to_jsondict())
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(), msg2.to_jsondict())
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_initiation(self):
|
||||
initiation_info = [{'type': bmp.BMP_INIT_TYPE_STRING,
|
||||
@ -140,8 +138,8 @@ class Test_bmp(unittest.TestCase):
|
||||
msg = bmp.BMPInitiation(info=initiation_info)
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_termination(self):
|
||||
termination_info = [{'type': bmp.BMP_TERM_TYPE_STRING,
|
||||
@ -151,5 +149,5 @@ class Test_bmp(unittest.TestCase):
|
||||
msg = bmp.BMPTermination(info=termination_info)
|
||||
binmsg = msg.serialize()
|
||||
msg2, rest = bmp.BMPMessage.parser(binmsg)
|
||||
eq_(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.to_jsondict(lambda v: v), msg2.to_jsondict(lambda v: v))
|
||||
self.assertEqual(rest, b'')
|
||||
|
@ -19,7 +19,6 @@ import unittest
|
||||
import logging
|
||||
import struct
|
||||
|
||||
from nose.tools import eq_
|
||||
from os_ken.lib.packet import bpdu
|
||||
|
||||
|
||||
@ -92,48 +91,48 @@ class Test_ConfigurationBPDUs(unittest.TestCase):
|
||||
self.forward_delay))
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.protocol_id, self.msg._protocol_id)
|
||||
eq_(self.version_id, self.msg._version_id)
|
||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
||||
eq_(self.flags, self.msg.flags)
|
||||
eq_(self.root_priority, self.msg.root_priority)
|
||||
eq_(self.root_system_id_extension,
|
||||
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||
self.assertEqual(self.version_id, self.msg._version_id)
|
||||
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||
self.assertEqual(self.flags, self.msg.flags)
|
||||
self.assertEqual(self.root_priority, self.msg.root_priority)
|
||||
self.assertEqual(self.root_system_id_extension,
|
||||
self.msg.root_system_id_extension)
|
||||
eq_(self.root_mac_address, self.msg.root_mac_address)
|
||||
eq_(self.root_path_cost, self.msg.root_path_cost)
|
||||
eq_(self.bridge_priority, self.msg.bridge_priority)
|
||||
eq_(self.bridge_system_id_extension,
|
||||
self.assertEqual(self.root_mac_address, self.msg.root_mac_address)
|
||||
self.assertEqual(self.root_path_cost, self.msg.root_path_cost)
|
||||
self.assertEqual(self.bridge_priority, self.msg.bridge_priority)
|
||||
self.assertEqual(self.bridge_system_id_extension,
|
||||
self.msg.bridge_system_id_extension)
|
||||
eq_(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||
eq_(self.port_priority, self.msg.port_priority)
|
||||
eq_(self.port_number, self.msg.port_number)
|
||||
eq_(self.message_age, self.msg.message_age)
|
||||
eq_(self.max_age, self.msg.max_age)
|
||||
eq_(self.hello_time, self.msg.hello_time)
|
||||
eq_(self.forward_delay, self.msg.forward_delay)
|
||||
self.assertEqual(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||
self.assertEqual(self.port_priority, self.msg.port_priority)
|
||||
self.assertEqual(self.port_number, self.msg.port_number)
|
||||
self.assertEqual(self.message_age, self.msg.message_age)
|
||||
self.assertEqual(self.max_age, self.msg.max_age)
|
||||
self.assertEqual(self.hello_time, self.msg.hello_time)
|
||||
self.assertEqual(self.forward_delay, self.msg.forward_delay)
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||
|
||||
eq_(type(r1), type(self.msg))
|
||||
eq_(r1._protocol_id, self.protocol_id)
|
||||
eq_(r1._version_id, self.version_id)
|
||||
eq_(r1._bpdu_type, self.bpdu_type)
|
||||
eq_(r1.flags, self.flags)
|
||||
eq_(r1.root_priority, self.root_priority)
|
||||
eq_(r1.root_system_id_extension, self.root_system_id_extension)
|
||||
eq_(r1.root_mac_address, self.root_mac_address)
|
||||
eq_(r1.root_path_cost, self.root_path_cost)
|
||||
eq_(r1.bridge_priority, self.bridge_priority)
|
||||
eq_(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||
eq_(r1.bridge_mac_address, self.bridge_mac_address)
|
||||
eq_(r1.port_priority, self.port_priority)
|
||||
eq_(r1.port_number, self.port_number)
|
||||
eq_(r1.message_age, self.message_age)
|
||||
eq_(r1.max_age, self.max_age)
|
||||
eq_(r1.hello_time, self.hello_time)
|
||||
eq_(r1.forward_delay, self.forward_delay)
|
||||
eq_(r2, None)
|
||||
self.assertEqual(type(r1), type(self.msg))
|
||||
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||
self.assertEqual(r1._version_id, self.version_id)
|
||||
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||
self.assertEqual(r1.flags, self.flags)
|
||||
self.assertEqual(r1.root_priority, self.root_priority)
|
||||
self.assertEqual(r1.root_system_id_extension, self.root_system_id_extension)
|
||||
self.assertEqual(r1.root_mac_address, self.root_mac_address)
|
||||
self.assertEqual(r1.root_path_cost, self.root_path_cost)
|
||||
self.assertEqual(r1.bridge_priority, self.bridge_priority)
|
||||
self.assertEqual(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||
self.assertEqual(r1.bridge_mac_address, self.bridge_mac_address)
|
||||
self.assertEqual(r1.port_priority, self.port_priority)
|
||||
self.assertEqual(r1.port_number, self.port_number)
|
||||
self.assertEqual(r1.message_age, self.message_age)
|
||||
self.assertEqual(r1.max_age, self.max_age)
|
||||
self.assertEqual(r1.hello_time, self.hello_time)
|
||||
self.assertEqual(r1.forward_delay, self.forward_delay)
|
||||
self.assertEqual(r2, None)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -141,32 +140,32 @@ class Test_ConfigurationBPDUs(unittest.TestCase):
|
||||
buf = self.msg.serialize(data, prev)
|
||||
res = struct.unpack(self.fmt, buf)
|
||||
|
||||
eq_(res[0], self.protocol_id)
|
||||
eq_(res[1], self.version_id)
|
||||
eq_(res[2], self.bpdu_type)
|
||||
eq_(res[3], self.flags)
|
||||
eq_(bpdu.ConfigurationBPDUs._decode_bridge_id(res[4]),
|
||||
self.assertEqual(res[0], self.protocol_id)
|
||||
self.assertEqual(res[1], self.version_id)
|
||||
self.assertEqual(res[2], self.bpdu_type)
|
||||
self.assertEqual(res[3], self.flags)
|
||||
self.assertEqual(bpdu.ConfigurationBPDUs._decode_bridge_id(res[4]),
|
||||
(self.root_priority,
|
||||
self.root_system_id_extension,
|
||||
self.root_mac_address))
|
||||
eq_(res[5], self.root_path_cost)
|
||||
eq_(bpdu.ConfigurationBPDUs._decode_bridge_id(res[6]),
|
||||
self.assertEqual(res[5], self.root_path_cost)
|
||||
self.assertEqual(bpdu.ConfigurationBPDUs._decode_bridge_id(res[6]),
|
||||
(self.bridge_priority,
|
||||
self.bridge_system_id_extension,
|
||||
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_number))
|
||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[8]), self.message_age)
|
||||
eq_(bpdu.ConfigurationBPDUs._decode_timer(res[9]), self.max_age)
|
||||
eq_(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[8]), self.message_age)
|
||||
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[9]), self.max_age)
|
||||
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[10]), self.hello_time)
|
||||
self.assertEqual(bpdu.ConfigurationBPDUs._decode_timer(res[11]), self.forward_delay)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.msg.to_jsondict()
|
||||
msg = bpdu.ConfigurationBPDUs.from_jsondict(
|
||||
jsondict['ConfigurationBPDUs'])
|
||||
eq_(str(self.msg), str(msg))
|
||||
self.assertEqual(str(self.msg), str(msg))
|
||||
|
||||
|
||||
class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
||||
@ -187,18 +186,18 @@ class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
||||
self.bpdu_type)
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.protocol_id, self.msg._protocol_id)
|
||||
eq_(self.version_id, self.msg._version_id)
|
||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
||||
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||
self.assertEqual(self.version_id, self.msg._version_id)
|
||||
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||
|
||||
eq_(type(r1), type(self.msg))
|
||||
eq_(r1._protocol_id, self.protocol_id)
|
||||
eq_(r1._version_id, self.version_id)
|
||||
eq_(r1._bpdu_type, self.bpdu_type)
|
||||
eq_(r2, None)
|
||||
self.assertEqual(type(r1), type(self.msg))
|
||||
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||
self.assertEqual(r1._version_id, self.version_id)
|
||||
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||
self.assertEqual(r2, None)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -206,15 +205,15 @@ class Test_TopologyChangeNotificationBPDUs(unittest.TestCase):
|
||||
buf = self.msg.serialize(data, prev)
|
||||
res = struct.unpack(self.fmt, buf)
|
||||
|
||||
eq_(res[0], self.protocol_id)
|
||||
eq_(res[1], self.version_id)
|
||||
eq_(res[2], self.bpdu_type)
|
||||
self.assertEqual(res[0], self.protocol_id)
|
||||
self.assertEqual(res[1], self.version_id)
|
||||
self.assertEqual(res[2], self.bpdu_type)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.msg.to_jsondict()
|
||||
msg = bpdu.TopologyChangeNotificationBPDUs.from_jsondict(
|
||||
jsondict['TopologyChangeNotificationBPDUs'])
|
||||
eq_(str(self.msg), str(msg))
|
||||
self.assertEqual(str(self.msg), str(msg))
|
||||
|
||||
|
||||
class Test_RstBPDUs(unittest.TestCase):
|
||||
@ -282,50 +281,50 @@ class Test_RstBPDUs(unittest.TestCase):
|
||||
self.version_1_length)
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.protocol_id, self.msg._protocol_id)
|
||||
eq_(self.version_id, self.msg._version_id)
|
||||
eq_(self.bpdu_type, self.msg._bpdu_type)
|
||||
eq_(self.flags, self.msg.flags)
|
||||
eq_(self.root_priority, self.msg.root_priority)
|
||||
eq_(self.root_system_id_extension,
|
||||
self.assertEqual(self.protocol_id, self.msg._protocol_id)
|
||||
self.assertEqual(self.version_id, self.msg._version_id)
|
||||
self.assertEqual(self.bpdu_type, self.msg._bpdu_type)
|
||||
self.assertEqual(self.flags, self.msg.flags)
|
||||
self.assertEqual(self.root_priority, self.msg.root_priority)
|
||||
self.assertEqual(self.root_system_id_extension,
|
||||
self.msg.root_system_id_extension)
|
||||
eq_(self.root_mac_address, self.msg.root_mac_address)
|
||||
eq_(self.root_path_cost, self.msg.root_path_cost)
|
||||
eq_(self.bridge_priority, self.msg.bridge_priority)
|
||||
eq_(self.bridge_system_id_extension,
|
||||
self.assertEqual(self.root_mac_address, self.msg.root_mac_address)
|
||||
self.assertEqual(self.root_path_cost, self.msg.root_path_cost)
|
||||
self.assertEqual(self.bridge_priority, self.msg.bridge_priority)
|
||||
self.assertEqual(self.bridge_system_id_extension,
|
||||
self.msg.bridge_system_id_extension)
|
||||
eq_(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||
eq_(self.port_priority, self.msg.port_priority)
|
||||
eq_(self.port_number, self.msg.port_number)
|
||||
eq_(self.message_age, self.msg.message_age)
|
||||
eq_(self.max_age, self.msg.max_age)
|
||||
eq_(self.hello_time, self.msg.hello_time)
|
||||
eq_(self.forward_delay, self.msg.forward_delay)
|
||||
eq_(self.version_1_length, self.msg._version_1_length)
|
||||
self.assertEqual(self.bridge_mac_address, self.msg.bridge_mac_address)
|
||||
self.assertEqual(self.port_priority, self.msg.port_priority)
|
||||
self.assertEqual(self.port_number, self.msg.port_number)
|
||||
self.assertEqual(self.message_age, self.msg.message_age)
|
||||
self.assertEqual(self.max_age, self.msg.max_age)
|
||||
self.assertEqual(self.hello_time, self.msg.hello_time)
|
||||
self.assertEqual(self.forward_delay, self.msg.forward_delay)
|
||||
self.assertEqual(self.version_1_length, self.msg._version_1_length)
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||
|
||||
eq_(type(r1), type(self.msg))
|
||||
eq_(r1._protocol_id, self.protocol_id)
|
||||
eq_(r1._version_id, self.version_id)
|
||||
eq_(r1._bpdu_type, self.bpdu_type)
|
||||
eq_(r1.flags, self.flags)
|
||||
eq_(r1.root_priority, self.root_priority)
|
||||
eq_(r1.root_system_id_extension, self.root_system_id_extension)
|
||||
eq_(r1.root_mac_address, self.root_mac_address)
|
||||
eq_(r1.root_path_cost, self.root_path_cost)
|
||||
eq_(r1.bridge_priority, self.bridge_priority)
|
||||
eq_(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||
eq_(r1.bridge_mac_address, self.bridge_mac_address)
|
||||
eq_(r1.port_priority, self.port_priority)
|
||||
eq_(r1.port_number, self.port_number)
|
||||
eq_(r1.message_age, self.message_age)
|
||||
eq_(r1.max_age, self.max_age)
|
||||
eq_(r1.hello_time, self.hello_time)
|
||||
eq_(r1.forward_delay, self.forward_delay)
|
||||
eq_(r1._version_1_length, self.version_1_length)
|
||||
eq_(r2, None)
|
||||
self.assertEqual(type(r1), type(self.msg))
|
||||
self.assertEqual(r1._protocol_id, self.protocol_id)
|
||||
self.assertEqual(r1._version_id, self.version_id)
|
||||
self.assertEqual(r1._bpdu_type, self.bpdu_type)
|
||||
self.assertEqual(r1.flags, self.flags)
|
||||
self.assertEqual(r1.root_priority, self.root_priority)
|
||||
self.assertEqual(r1.root_system_id_extension, self.root_system_id_extension)
|
||||
self.assertEqual(r1.root_mac_address, self.root_mac_address)
|
||||
self.assertEqual(r1.root_path_cost, self.root_path_cost)
|
||||
self.assertEqual(r1.bridge_priority, self.bridge_priority)
|
||||
self.assertEqual(r1.bridge_system_id_extension, self.bridge_system_id_extension)
|
||||
self.assertEqual(r1.bridge_mac_address, self.bridge_mac_address)
|
||||
self.assertEqual(r1.port_priority, self.port_priority)
|
||||
self.assertEqual(r1.port_number, self.port_number)
|
||||
self.assertEqual(r1.message_age, self.message_age)
|
||||
self.assertEqual(r1.max_age, self.max_age)
|
||||
self.assertEqual(r1.hello_time, self.hello_time)
|
||||
self.assertEqual(r1.forward_delay, self.forward_delay)
|
||||
self.assertEqual(r1._version_1_length, self.version_1_length)
|
||||
self.assertEqual(r2, None)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -333,32 +332,32 @@ class Test_RstBPDUs(unittest.TestCase):
|
||||
buf = self.msg.serialize(data, prev)
|
||||
res = struct.unpack(self.fmt, buf)
|
||||
|
||||
eq_(res[0], self.protocol_id)
|
||||
eq_(res[1], self.version_id)
|
||||
eq_(res[2], self.bpdu_type)
|
||||
eq_(res[3], self.flags)
|
||||
eq_(bpdu.RstBPDUs._decode_bridge_id(res[4]),
|
||||
self.assertEqual(res[0], self.protocol_id)
|
||||
self.assertEqual(res[1], self.version_id)
|
||||
self.assertEqual(res[2], self.bpdu_type)
|
||||
self.assertEqual(res[3], self.flags)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_bridge_id(res[4]),
|
||||
(self.root_priority,
|
||||
self.root_system_id_extension,
|
||||
self.root_mac_address))
|
||||
eq_(res[5], self.root_path_cost)
|
||||
eq_(bpdu.RstBPDUs._decode_bridge_id(res[6]),
|
||||
self.assertEqual(res[5], self.root_path_cost)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_bridge_id(res[6]),
|
||||
(self.bridge_priority,
|
||||
self.bridge_system_id_extension,
|
||||
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_number))
|
||||
eq_(bpdu.RstBPDUs._decode_timer(res[8]), self.message_age)
|
||||
eq_(bpdu.RstBPDUs._decode_timer(res[9]), self.max_age)
|
||||
eq_(bpdu.RstBPDUs._decode_timer(res[10]), self.hello_time)
|
||||
eq_(bpdu.RstBPDUs._decode_timer(res[11]), self.forward_delay)
|
||||
eq_(res[12], self.version_1_length)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[8]), self.message_age)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[9]), self.max_age)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[10]), self.hello_time)
|
||||
self.assertEqual(bpdu.RstBPDUs._decode_timer(res[11]), self.forward_delay)
|
||||
self.assertEqual(res[12], self.version_1_length)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.msg.to_jsondict()
|
||||
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):
|
||||
@ -411,8 +410,8 @@ class Test_UnknownVersion(unittest.TestCase):
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||
eq_(r1, self.buf)
|
||||
eq_(r2, None)
|
||||
self.assertEqual(r1, self.buf)
|
||||
self.assertEqual(r2, None)
|
||||
|
||||
|
||||
class Test_UnknownType(unittest.TestCase):
|
||||
@ -465,5 +464,5 @@ class Test_UnknownType(unittest.TestCase):
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = bpdu.bpdu.parser(self.buf)
|
||||
eq_(r1, self.buf)
|
||||
eq_(r2, None)
|
||||
self.assertEqual(r1, self.buf)
|
||||
self.assertEqual(r2, None)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,6 @@ import struct
|
||||
import unittest
|
||||
|
||||
import six
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.lib import addrconv
|
||||
from os_ken.lib.packet import dhcp
|
||||
@ -92,57 +90,57 @@ class Test_dhcp_offer(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.op, self.dh.op)
|
||||
eq_(self.htype, self.dh.htype)
|
||||
eq_(self.hlen, self.dh.hlen)
|
||||
eq_(self.hops, self.dh.hops)
|
||||
eq_(self.xid, self.dh.xid)
|
||||
eq_(self.secs, self.dh.secs)
|
||||
eq_(self.flags, self.dh.flags)
|
||||
eq_(self.ciaddr, self.dh.ciaddr)
|
||||
eq_(self.yiaddr, self.dh.yiaddr)
|
||||
eq_(self.siaddr, self.dh.siaddr)
|
||||
eq_(self.giaddr, self.dh.giaddr)
|
||||
eq_(self.chaddr, self.dh.chaddr)
|
||||
eq_(self.sname, self.dh.sname)
|
||||
eq_(self.boot_file, self.dh.boot_file)
|
||||
eq_(str(self.options), str(self.dh.options))
|
||||
self.assertEqual(self.op, self.dh.op)
|
||||
self.assertEqual(self.htype, self.dh.htype)
|
||||
self.assertEqual(self.hlen, self.dh.hlen)
|
||||
self.assertEqual(self.hops, self.dh.hops)
|
||||
self.assertEqual(self.xid, self.dh.xid)
|
||||
self.assertEqual(self.secs, self.dh.secs)
|
||||
self.assertEqual(self.flags, self.dh.flags)
|
||||
self.assertEqual(self.ciaddr, self.dh.ciaddr)
|
||||
self.assertEqual(self.yiaddr, self.dh.yiaddr)
|
||||
self.assertEqual(self.siaddr, self.dh.siaddr)
|
||||
self.assertEqual(self.giaddr, self.dh.giaddr)
|
||||
self.assertEqual(self.chaddr, self.dh.chaddr)
|
||||
self.assertEqual(self.sname, self.dh.sname)
|
||||
self.assertEqual(self.boot_file, self.dh.boot_file)
|
||||
self.assertEqual(str(self.options), str(self.dh.options))
|
||||
|
||||
def test_parser(self):
|
||||
res, _, rest = dhcp.dhcp.parser(self.buf)
|
||||
|
||||
eq_(self.op, res.op)
|
||||
eq_(self.htype, res.htype)
|
||||
eq_(self.hlen, res.hlen)
|
||||
eq_(self.hops, res.hops)
|
||||
eq_(self.xid, res.xid)
|
||||
eq_(self.secs, res.secs)
|
||||
eq_(self.flags, res.flags)
|
||||
eq_(self.ciaddr, res.ciaddr)
|
||||
eq_(self.yiaddr, res.yiaddr)
|
||||
eq_(self.siaddr, res.siaddr)
|
||||
eq_(self.giaddr, res.giaddr)
|
||||
eq_(self.chaddr, res.chaddr)
|
||||
self.assertEqual(self.op, res.op)
|
||||
self.assertEqual(self.htype, res.htype)
|
||||
self.assertEqual(self.hlen, res.hlen)
|
||||
self.assertEqual(self.hops, res.hops)
|
||||
self.assertEqual(self.xid, res.xid)
|
||||
self.assertEqual(self.secs, res.secs)
|
||||
self.assertEqual(self.flags, res.flags)
|
||||
self.assertEqual(self.ciaddr, res.ciaddr)
|
||||
self.assertEqual(self.yiaddr, res.yiaddr)
|
||||
self.assertEqual(self.siaddr, res.siaddr)
|
||||
self.assertEqual(self.giaddr, res.giaddr)
|
||||
self.assertEqual(self.chaddr, res.chaddr)
|
||||
# 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'.
|
||||
eq_(self.boot_file.ljust(128, '\x00'), res.boot_file)
|
||||
eq_(str(self.options), str(res.options))
|
||||
eq_(b'', rest)
|
||||
self.assertEqual(self.boot_file.ljust(128, '\x00'), res.boot_file)
|
||||
self.assertEqual(str(self.options), str(res.options))
|
||||
self.assertEqual(b'', rest)
|
||||
|
||||
def test_parser_corrupted(self):
|
||||
corrupt_buf = self.buf[:-4]
|
||||
pkt, _, rest = dhcp.dhcp.parser(corrupt_buf)
|
||||
|
||||
ok_(isinstance(pkt, dhcp.dhcp))
|
||||
ok_(isinstance(pkt.options, dhcp.options))
|
||||
self.assertTrue(isinstance(pkt, dhcp.dhcp))
|
||||
self.assertTrue(isinstance(pkt.options, dhcp.options))
|
||||
for opt in pkt.options.option_list[:-1]:
|
||||
ok_(isinstance(opt, dhcp.option))
|
||||
ok_(isinstance(pkt.options.option_list[-1], six.binary_type))
|
||||
self.assertTrue(isinstance(opt, dhcp.option))
|
||||
self.assertTrue(isinstance(pkt.options.option_list[-1], six.binary_type))
|
||||
|
||||
buf = pkt.serialize()
|
||||
eq_(str(buf), str(corrupt_buf))
|
||||
eq_(b'', rest)
|
||||
self.assertEqual(str(buf), str(corrupt_buf))
|
||||
self.assertEqual(b'', rest)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.dh.serialize()
|
||||
@ -150,25 +148,25 @@ class Test_dhcp_offer(unittest.TestCase):
|
||||
res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR,
|
||||
six.binary_type(buf))
|
||||
|
||||
eq_(self.op, res[0])
|
||||
eq_(self.htype, res[1])
|
||||
eq_(self.hlen, res[2])
|
||||
eq_(self.hops, res[3])
|
||||
eq_(self.xid, res[4])
|
||||
eq_(self.secs, res[5])
|
||||
eq_(self.flags, res[6])
|
||||
eq_(self.ciaddr, addrconv.ipv4.bin_to_text(res[7]))
|
||||
eq_(self.yiaddr, addrconv.ipv4.bin_to_text(res[8]))
|
||||
eq_(self.siaddr, addrconv.ipv4.bin_to_text(res[9]))
|
||||
eq_(self.giaddr, addrconv.ipv4.bin_to_text(res[10]))
|
||||
eq_(self.chaddr, addrconv.mac.bin_to_text(res[11][:6]))
|
||||
self.assertEqual(self.op, res[0])
|
||||
self.assertEqual(self.htype, res[1])
|
||||
self.assertEqual(self.hlen, res[2])
|
||||
self.assertEqual(self.hops, res[3])
|
||||
self.assertEqual(self.xid, res[4])
|
||||
self.assertEqual(self.secs, res[5])
|
||||
self.assertEqual(self.flags, res[6])
|
||||
self.assertEqual(self.ciaddr, addrconv.ipv4.bin_to_text(res[7]))
|
||||
self.assertEqual(self.yiaddr, addrconv.ipv4.bin_to_text(res[8]))
|
||||
self.assertEqual(self.siaddr, addrconv.ipv4.bin_to_text(res[9]))
|
||||
self.assertEqual(self.giaddr, addrconv.ipv4.bin_to_text(res[10]))
|
||||
self.assertEqual(self.chaddr, addrconv.mac.bin_to_text(res[11][:6]))
|
||||
# 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'.
|
||||
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(
|
||||
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):
|
||||
option_values = ['tag', 'length', 'value']
|
||||
@ -209,10 +207,10 @@ class Test_dhcp_offer(unittest.TestCase):
|
||||
if k in dhcp_values])
|
||||
dh_str = '%s(%s)' % (dhcp.dhcp.__name__, _dh_str)
|
||||
|
||||
eq_(str(self.dh), dh_str)
|
||||
eq_(repr(self.dh), dh_str)
|
||||
self.assertEqual(str(self.dh), dh_str)
|
||||
self.assertEqual(repr(self.dh), dh_str)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.dh.to_jsondict()
|
||||
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 netaddr
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import ether, inet
|
||||
from os_ken.lib.packet.ethernet import ethernet
|
||||
from os_ken.lib.packet.packet import Packet
|
||||
@ -58,18 +57,18 @@ class Test_ethernet(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.dst, self.e.dst)
|
||||
eq_(self.src, self.e.src)
|
||||
eq_(self.ethertype, self.e.ethertype)
|
||||
self.assertEqual(self.dst, self.e.dst)
|
||||
self.assertEqual(self.src, self.e.src)
|
||||
self.assertEqual(self.ethertype, self.e.ethertype)
|
||||
|
||||
def test_parser(self):
|
||||
res, ptype, _ = self.e.parser(self.buf)
|
||||
LOG.debug((res, ptype))
|
||||
|
||||
eq_(res.dst, self.dst)
|
||||
eq_(res.src, self.src)
|
||||
eq_(res.ethertype, self.ethertype)
|
||||
eq_(ptype, arp)
|
||||
self.assertEqual(res.dst, self.dst)
|
||||
self.assertEqual(res.src, self.src)
|
||||
self.assertEqual(res.ethertype, self.ethertype)
|
||||
self.assertEqual(ptype, arp)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -79,25 +78,24 @@ class Test_ethernet(unittest.TestCase):
|
||||
fmt = ethernet._PACK_STR
|
||||
res = struct.unpack(fmt, buf)
|
||||
|
||||
eq_(res[0], addrconv.mac.text_to_bin(self.dst))
|
||||
eq_(res[1], addrconv.mac.text_to_bin(self.src))
|
||||
eq_(res[2], self.ethertype)
|
||||
self.assertEqual(res[0], addrconv.mac.text_to_bin(self.dst))
|
||||
self.assertEqual(res[1], addrconv.mac.text_to_bin(self.src))
|
||||
self.assertEqual(res[2], self.ethertype)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_ethernet(self):
|
||||
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):
|
||||
e = ethernet()
|
||||
buf = e.serialize(bytearray(), None)
|
||||
res = struct.unpack(e._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(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'))
|
||||
eq_(res[2], ether.ETH_TYPE_IP)
|
||||
self.assertEqual(res[0], addrconv.mac.text_to_bin('ff:ff:ff:ff:ff:ff'))
|
||||
self.assertEqual(res[1], addrconv.mac.text_to_bin('00:00:00:00:00:00'))
|
||||
self.assertEqual(res[2], ether.ETH_TYPE_IP)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.e.to_jsondict()
|
||||
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 unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.lib import pcaplib
|
||||
from os_ken.lib.packet import geneve
|
||||
@ -51,10 +49,10 @@ class Test_geneve(unittest.TestCase):
|
||||
# Checks if message can be parsed as expected.
|
||||
pkt = packet.Packet(buf)
|
||||
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)
|
||||
|
||||
# Checks if message can be serialized as expected.
|
||||
pkt.serialize()
|
||||
eq_(buf, pkt.data,
|
||||
self.assertEqual(buf, pkt.data,
|
||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||
|
@ -18,8 +18,6 @@ import os
|
||||
import sys
|
||||
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.lib import pcaplib
|
||||
from os_ken.lib.packet import gre
|
||||
@ -53,41 +51,41 @@ class Test_gre(unittest.TestCase):
|
||||
|
||||
def test_key_setter(self):
|
||||
self.gre.key = self.key
|
||||
eq_(self.gre._key, self.key)
|
||||
eq_(self.gre._vsid, self.vsid)
|
||||
eq_(self.gre._flow_id, self.flow_id)
|
||||
self.assertEqual(self.gre._key, self.key)
|
||||
self.assertEqual(self.gre._vsid, self.vsid)
|
||||
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||
|
||||
def test_key_setter_none(self):
|
||||
self.gre.key = None
|
||||
eq_(self.gre._key, None)
|
||||
eq_(self.gre._vsid, None)
|
||||
eq_(self.gre._flow_id, None)
|
||||
self.assertEqual(self.gre._key, None)
|
||||
self.assertEqual(self.gre._vsid, None)
|
||||
self.assertEqual(self.gre._flow_id, None)
|
||||
|
||||
self.gre.key = self.key
|
||||
|
||||
def test_vsid_setter(self):
|
||||
self.gre.vsid = self.vsid
|
||||
eq_(self.gre._key, self.key)
|
||||
eq_(self.gre._vsid, self.vsid)
|
||||
eq_(self.gre._flow_id, self.flow_id)
|
||||
self.assertEqual(self.gre._key, self.key)
|
||||
self.assertEqual(self.gre._vsid, self.vsid)
|
||||
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||
|
||||
def test_flowid_setter(self):
|
||||
self.gre.flow_id = self.flow_id
|
||||
eq_(self.gre._key, self.key)
|
||||
eq_(self.gre._vsid, self.vsid)
|
||||
eq_(self.gre._flow_id, self.flow_id)
|
||||
self.assertEqual(self.gre._key, self.key)
|
||||
self.assertEqual(self.gre._vsid, self.vsid)
|
||||
self.assertEqual(self.gre._flow_id, self.flow_id)
|
||||
|
||||
def test_nvgre_init(self):
|
||||
nvgre = gre.nvgre(version=self.version, vsid=self.vsid,
|
||||
flow_id=self.flow_id)
|
||||
|
||||
eq_(nvgre.version, self.version)
|
||||
eq_(nvgre.protocol, self.nvgre_proto)
|
||||
eq_(nvgre.checksum, None)
|
||||
eq_(nvgre.seq_number, None)
|
||||
eq_(nvgre._key, self.key)
|
||||
eq_(nvgre._vsid, self.vsid)
|
||||
eq_(nvgre._flow_id, self.flow_id)
|
||||
self.assertEqual(nvgre.version, self.version)
|
||||
self.assertEqual(nvgre.protocol, self.nvgre_proto)
|
||||
self.assertEqual(nvgre.checksum, None)
|
||||
self.assertEqual(nvgre.seq_number, None)
|
||||
self.assertEqual(nvgre._key, self.key)
|
||||
self.assertEqual(nvgre._vsid, self.vsid)
|
||||
self.assertEqual(nvgre._flow_id, self.flow_id)
|
||||
|
||||
def test_parser(self):
|
||||
files = [
|
||||
@ -103,11 +101,11 @@ class Test_gre(unittest.TestCase):
|
||||
# Checks if message can be parsed as expected.
|
||||
pkt = packet.Packet(buf)
|
||||
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)
|
||||
|
||||
# Checks if message can be serialized as expected.
|
||||
pkt.serialize()
|
||||
|
||||
eq_(buf, pkt.data,
|
||||
self.assertEqual(buf, pkt.data,
|
||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||
|
@ -20,7 +20,6 @@ import six
|
||||
import struct
|
||||
import unittest
|
||||
|
||||
from nose.tools import eq_
|
||||
from os_ken.lib.packet import icmp
|
||||
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)
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.ic.type)
|
||||
eq_(self.code, self.ic.code)
|
||||
eq_(self.csum, self.ic.csum)
|
||||
eq_(str(self.data), str(self.ic.data))
|
||||
self.assertEqual(self.type_, self.ic.type)
|
||||
self.assertEqual(self.code, self.ic.code)
|
||||
self.assertEqual(self.csum, self.ic.csum)
|
||||
self.assertEqual(str(self.data), str(self.ic.data))
|
||||
|
||||
def test_init_with_echo(self):
|
||||
self.setUp_with_echo()
|
||||
@ -135,10 +134,10 @@ class Test_icmp(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(self.type_, res.type)
|
||||
eq_(self.code, res.code)
|
||||
eq_(self.csum_calc, res.csum)
|
||||
eq_(str(self.data), str(res.data))
|
||||
self.assertEqual(self.type_, res.type)
|
||||
self.assertEqual(self.code, res.code)
|
||||
self.assertEqual(self.csum_calc, res.csum)
|
||||
self.assertEqual(str(self.data), str(res.data))
|
||||
|
||||
def test_parser_with_echo(self):
|
||||
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))
|
||||
|
||||
eq_(self.type_, res[0])
|
||||
eq_(self.code, res[1])
|
||||
eq_(self.csum_calc, res[2])
|
||||
self.assertEqual(self.type_, res[0])
|
||||
self.assertEqual(self.code, res[1])
|
||||
self.assertEqual(self.csum_calc, res[2])
|
||||
|
||||
def test_serialize_with_echo(self):
|
||||
self.setUp_with_echo()
|
||||
@ -171,7 +170,7 @@ class Test_icmp(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ic.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_dest_unreach()
|
||||
@ -181,7 +180,7 @@ class Test_icmp(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ic.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_TimeExceeded()
|
||||
@ -191,7 +190,7 @@ class Test_icmp(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ic.serialize(data, prev)
|
||||
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):
|
||||
icmp_values = {'type': repr(self.type_),
|
||||
@ -203,8 +202,8 @@ class Test_icmp(unittest.TestCase):
|
||||
if k in icmp_values])
|
||||
ic_str = '%s(%s)' % (icmp.icmp.__name__, _ic_str)
|
||||
|
||||
eq_(str(self.ic), ic_str)
|
||||
eq_(repr(self.ic), ic_str)
|
||||
self.assertEqual(str(self.ic), ic_str)
|
||||
self.assertEqual(repr(self.ic), ic_str)
|
||||
|
||||
def test_to_string_with_echo(self):
|
||||
self.setUp_with_echo()
|
||||
@ -223,23 +222,23 @@ class Test_icmp(unittest.TestCase):
|
||||
buf = ic.serialize(bytearray(), None)
|
||||
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
||||
|
||||
eq_(res[0], 8)
|
||||
eq_(res[1], 0)
|
||||
eq_(buf[4:], b'\x00\x00\x00\x00')
|
||||
self.assertEqual(res[0], 8)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(buf[4:], b'\x00\x00\x00\x00')
|
||||
|
||||
# with data
|
||||
ic = icmp.icmp(type_=icmp.ICMP_DEST_UNREACH, data=icmp.dest_unreach())
|
||||
buf = ic.serialize(bytearray(), None)
|
||||
res = struct.unpack(icmp.icmp._PACK_STR, six.binary_type(buf[:4]))
|
||||
|
||||
eq_(res[0], 3)
|
||||
eq_(res[1], 0)
|
||||
eq_(buf[4:], b'\x00\x00\x00\x00')
|
||||
self.assertEqual(res[0], 3)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(buf[4:], b'\x00\x00\x00\x00')
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.ic.to_jsondict()
|
||||
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):
|
||||
self.setUp_with_echo()
|
||||
@ -271,9 +270,9 @@ class Test_echo(unittest.TestCase):
|
||||
self.buf += self.data
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.id_, self.echo.id)
|
||||
eq_(self.seq, self.echo.seq)
|
||||
eq_(self.data, self.echo.data)
|
||||
self.assertEqual(self.id_, self.echo.id)
|
||||
self.assertEqual(self.seq, self.echo.seq)
|
||||
self.assertEqual(self.data, self.echo.data)
|
||||
|
||||
def test_parser(self):
|
||||
_res = icmp.echo.parser(self.buf, 0)
|
||||
@ -281,24 +280,24 @@ class Test_echo(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.id_, res.id)
|
||||
eq_(self.seq, res.seq)
|
||||
eq_(self.data, res.data)
|
||||
self.assertEqual(self.id_, res.id)
|
||||
self.assertEqual(self.seq, res.seq)
|
||||
self.assertEqual(self.data, res.data)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.echo.serialize()
|
||||
res = struct.unpack_from('!HH', six.binary_type(buf))
|
||||
eq_(self.id_, res[0])
|
||||
eq_(self.seq, res[1])
|
||||
eq_(self.data, buf[struct.calcsize('!HH'):])
|
||||
self.assertEqual(self.id_, res[0])
|
||||
self.assertEqual(self.seq, res[1])
|
||||
self.assertEqual(self.data, buf[struct.calcsize('!HH'):])
|
||||
|
||||
def test_default_args(self):
|
||||
ec = icmp.echo()
|
||||
buf = ec.serialize()
|
||||
res = struct.unpack(icmp.echo._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 0)
|
||||
self.assertEqual(res[0], 0)
|
||||
self.assertEqual(res[1], 0)
|
||||
|
||||
|
||||
class Test_dest_unreach(unittest.TestCase):
|
||||
@ -313,9 +312,9 @@ class Test_dest_unreach(unittest.TestCase):
|
||||
self.buf += self.data
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.data_len, self.dest_unreach.data_len)
|
||||
eq_(self.mtu, self.dest_unreach.mtu)
|
||||
eq_(self.data, self.dest_unreach.data)
|
||||
self.assertEqual(self.data_len, self.dest_unreach.data_len)
|
||||
self.assertEqual(self.mtu, self.dest_unreach.mtu)
|
||||
self.assertEqual(self.data, self.dest_unreach.data)
|
||||
|
||||
def test_parser(self):
|
||||
_res = icmp.dest_unreach.parser(self.buf, 0)
|
||||
@ -323,24 +322,24 @@ class Test_dest_unreach(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.data_len, res.data_len)
|
||||
eq_(self.mtu, res.mtu)
|
||||
eq_(self.data, res.data)
|
||||
self.assertEqual(self.data_len, res.data_len)
|
||||
self.assertEqual(self.mtu, res.mtu)
|
||||
self.assertEqual(self.data, res.data)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.dest_unreach.serialize()
|
||||
res = struct.unpack_from('!xBH', six.binary_type(buf))
|
||||
eq_(self.data_len, res[0])
|
||||
eq_(self.mtu, res[1])
|
||||
eq_(self.data, buf[struct.calcsize('!xBH'):])
|
||||
self.assertEqual(self.data_len, res[0])
|
||||
self.assertEqual(self.mtu, res[1])
|
||||
self.assertEqual(self.data, buf[struct.calcsize('!xBH'):])
|
||||
|
||||
def test_default_args(self):
|
||||
du = icmp.dest_unreach()
|
||||
buf = du.serialize()
|
||||
res = struct.unpack(icmp.dest_unreach._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 0)
|
||||
self.assertEqual(res[0], 0)
|
||||
self.assertEqual(res[1], 0)
|
||||
|
||||
|
||||
class Test_TimeExceeded(unittest.TestCase):
|
||||
@ -354,8 +353,8 @@ class Test_TimeExceeded(unittest.TestCase):
|
||||
self.buf += self.data
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.data_len, self.te.data_len)
|
||||
eq_(self.data, self.te.data)
|
||||
self.assertEqual(self.data_len, self.te.data_len)
|
||||
self.assertEqual(self.data, self.te.data)
|
||||
|
||||
def test_parser(self):
|
||||
_res = icmp.TimeExceeded.parser(self.buf, 0)
|
||||
@ -363,18 +362,18 @@ class Test_TimeExceeded(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.data_len, res.data_len)
|
||||
eq_(self.data, res.data)
|
||||
self.assertEqual(self.data_len, res.data_len)
|
||||
self.assertEqual(self.data, res.data)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.te.serialize()
|
||||
res = struct.unpack_from('!xBxx', six.binary_type(buf))
|
||||
eq_(self.data_len, res[0])
|
||||
eq_(self.data, buf[struct.calcsize('!xBxx'):])
|
||||
self.assertEqual(self.data_len, res[0])
|
||||
self.assertEqual(self.data, buf[struct.calcsize('!xBxx'):])
|
||||
|
||||
def test_default_args(self):
|
||||
te = icmp.TimeExceeded()
|
||||
buf = te.serialize()
|
||||
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
|
||||
|
||||
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 inet
|
||||
from os_ken.lib.packet.ethernet import ethernet
|
||||
@ -66,10 +65,10 @@ class Test_igmp(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.msgtype, self.g.msgtype)
|
||||
eq_(self.maxresp, self.g.maxresp)
|
||||
eq_(self.csum, self.g.csum)
|
||||
eq_(self.address, self.g.address)
|
||||
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||
self.assertEqual(self.maxresp, self.g.maxresp)
|
||||
self.assertEqual(self.csum, self.g.csum)
|
||||
self.assertEqual(self.address, self.g.address)
|
||||
|
||||
def test_parser(self):
|
||||
_res = self.g.parser(self.buf)
|
||||
@ -78,10 +77,10 @@ class Test_igmp(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(res.msgtype, self.msgtype)
|
||||
eq_(res.maxresp, self.maxresp)
|
||||
eq_(res.csum, self.csum)
|
||||
eq_(res.address, self.address)
|
||||
self.assertEqual(res.msgtype, self.msgtype)
|
||||
self.assertEqual(res.maxresp, self.maxresp)
|
||||
self.assertEqual(res.csum, self.csum)
|
||||
self.assertEqual(res.address, self.address)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -90,10 +89,10 @@ class Test_igmp(unittest.TestCase):
|
||||
|
||||
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], self.msgtype)
|
||||
eq_(res[1], self.maxresp)
|
||||
eq_(res[2], checksum(self.buf))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(res[0], self.msgtype)
|
||||
self.assertEqual(res[1], self.maxresp)
|
||||
self.assertEqual(res[2], checksum(self.buf))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
|
||||
def _build_igmp(self):
|
||||
dl_dst = '11:22:33:44:55:66'
|
||||
@ -120,20 +119,20 @@ class Test_igmp(unittest.TestCase):
|
||||
p = self._build_igmp()
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertIsNotNone(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
i = self.find_protocol(p, "ipv4")
|
||||
ok_(i)
|
||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
||||
self.assertTrue(i)
|
||||
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||
|
||||
g = self.find_protocol(p, "igmp")
|
||||
ok_(g)
|
||||
self.assertTrue(g)
|
||||
|
||||
eq_(g.msgtype, self.msgtype)
|
||||
eq_(g.maxresp, self.maxresp)
|
||||
eq_(g.csum, checksum(self.buf))
|
||||
eq_(g.address, self.address)
|
||||
self.assertEqual(g.msgtype, self.msgtype)
|
||||
self.assertEqual(g.maxresp, self.maxresp)
|
||||
self.assertEqual(g.csum, checksum(self.buf))
|
||||
self.assertEqual(g.address, self.address)
|
||||
|
||||
def test_to_string(self):
|
||||
igmp_values = {'msgtype': repr(self.msgtype),
|
||||
@ -145,27 +144,26 @@ class Test_igmp(unittest.TestCase):
|
||||
if k in igmp_values])
|
||||
g_str = '%s(%s)' % (igmp.__name__, _g_str)
|
||||
|
||||
eq_(str(self.g), g_str)
|
||||
eq_(repr(self.g), g_str)
|
||||
self.assertEqual(str(self.g), g_str)
|
||||
self.assertEqual(repr(self.g), g_str)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_igmp(self):
|
||||
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):
|
||||
ig = igmp()
|
||||
buf = ig.serialize(bytearray(), None)
|
||||
res = unpack_from(igmp._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0x11)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(res[0], 0x11)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.g.to_jsondict()
|
||||
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):
|
||||
@ -216,15 +214,15 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.msgtype, self.g.msgtype)
|
||||
eq_(self.maxresp, self.g.maxresp)
|
||||
eq_(self.csum, self.g.csum)
|
||||
eq_(self.address, self.g.address)
|
||||
eq_(self.s_flg, self.g.s_flg)
|
||||
eq_(self.qrv, self.g.qrv)
|
||||
eq_(self.qqic, self.g.qqic)
|
||||
eq_(self.num, self.g.num)
|
||||
eq_(self.srcs, self.g.srcs)
|
||||
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||
self.assertEqual(self.maxresp, self.g.maxresp)
|
||||
self.assertEqual(self.csum, self.g.csum)
|
||||
self.assertEqual(self.address, self.g.address)
|
||||
self.assertEqual(self.s_flg, self.g.s_flg)
|
||||
self.assertEqual(self.qrv, self.g.qrv)
|
||||
self.assertEqual(self.qqic, self.g.qqic)
|
||||
self.assertEqual(self.num, self.g.num)
|
||||
self.assertEqual(self.srcs, self.g.srcs)
|
||||
|
||||
def test_init_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -237,15 +235,15 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(res.msgtype, self.msgtype)
|
||||
eq_(res.maxresp, self.maxresp)
|
||||
eq_(res.csum, self.csum)
|
||||
eq_(res.address, self.address)
|
||||
eq_(res.s_flg, self.s_flg)
|
||||
eq_(res.qrv, self.qrv)
|
||||
eq_(res.qqic, self.qqic)
|
||||
eq_(res.num, self.num)
|
||||
eq_(res.srcs, self.srcs)
|
||||
self.assertEqual(res.msgtype, self.msgtype)
|
||||
self.assertEqual(res.maxresp, self.maxresp)
|
||||
self.assertEqual(res.csum, self.csum)
|
||||
self.assertEqual(res.address, self.address)
|
||||
self.assertEqual(res.s_flg, self.s_flg)
|
||||
self.assertEqual(res.qrv, self.qrv)
|
||||
self.assertEqual(res.qqic, self.qqic)
|
||||
self.assertEqual(res.num, self.num)
|
||||
self.assertEqual(res.srcs, self.srcs)
|
||||
|
||||
def test_parser_with_srcs(self):
|
||||
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))
|
||||
|
||||
eq_(res[0], self.msgtype)
|
||||
eq_(res[1], self.maxresp)
|
||||
eq_(res[2], checksum(self.buf))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
eq_(res[4], self.s_qrv)
|
||||
eq_(res[5], self.qqic)
|
||||
eq_(res[6], self.num)
|
||||
self.assertEqual(res[0], self.msgtype)
|
||||
self.assertEqual(res[1], self.maxresp)
|
||||
self.assertEqual(res[2], checksum(self.buf))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(res[4], self.s_qrv)
|
||||
self.assertEqual(res[5], self.qqic)
|
||||
self.assertEqual(res[6], self.num)
|
||||
|
||||
def test_serialize_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -276,16 +274,16 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
||||
igmpv3_query._MIN_LEN)
|
||||
|
||||
eq_(res[0], self.msgtype)
|
||||
eq_(res[1], self.maxresp)
|
||||
eq_(res[2], checksum(self.buf))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
eq_(res[4], self.s_qrv)
|
||||
eq_(res[5], self.qqic)
|
||||
eq_(res[6], self.num)
|
||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
self.assertEqual(res[0], self.msgtype)
|
||||
self.assertEqual(res[1], self.maxresp)
|
||||
self.assertEqual(res[2], checksum(self.buf))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(res[4], self.s_qrv)
|
||||
self.assertEqual(res[5], self.qqic)
|
||||
self.assertEqual(res[6], self.num)
|
||||
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
|
||||
def _build_igmp(self):
|
||||
dl_dst = '11:22:33:44:55:66'
|
||||
@ -312,25 +310,25 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
p = self._build_igmp()
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
i = self.find_protocol(p, "ipv4")
|
||||
ok_(i)
|
||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
||||
self.assertTrue(i)
|
||||
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||
|
||||
g = self.find_protocol(p, "igmpv3_query")
|
||||
ok_(g)
|
||||
self.assertTrue(g)
|
||||
|
||||
eq_(g.msgtype, self.msgtype)
|
||||
eq_(g.maxresp, self.maxresp)
|
||||
eq_(g.csum, checksum(self.buf))
|
||||
eq_(g.address, self.address)
|
||||
eq_(g.s_flg, self.s_flg)
|
||||
eq_(g.qrv, self.qrv)
|
||||
eq_(g.qqic, self.qqic)
|
||||
eq_(g.num, self.num)
|
||||
eq_(g.srcs, self.srcs)
|
||||
self.assertEqual(g.msgtype, self.msgtype)
|
||||
self.assertEqual(g.maxresp, self.maxresp)
|
||||
self.assertEqual(g.csum, checksum(self.buf))
|
||||
self.assertEqual(g.address, self.address)
|
||||
self.assertEqual(g.s_flg, self.s_flg)
|
||||
self.assertEqual(g.qrv, self.qrv)
|
||||
self.assertEqual(g.qqic, self.qqic)
|
||||
self.assertEqual(g.num, self.num)
|
||||
self.assertEqual(g.srcs, self.srcs)
|
||||
|
||||
def test_build_igmp_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -351,14 +349,13 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
if k in igmp_values])
|
||||
g_str = '%s(%s)' % (igmpv3_query.__name__, _g_str)
|
||||
|
||||
eq_(str(self.g), g_str)
|
||||
eq_(repr(self.g), g_str)
|
||||
self.assertEqual(str(self.g), g_str)
|
||||
self.assertEqual(repr(self.g), g_str)
|
||||
|
||||
def test_to_string_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
self.test_to_string()
|
||||
|
||||
@raises(Exception)
|
||||
def test_num_larger_than_srcs(self):
|
||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||
self.num = len(self.srcs) + 1
|
||||
@ -371,9 +368,8 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
self.g = igmpv3_query(
|
||||
self.msgtype, self.maxresp, self.csum, self.address,
|
||||
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):
|
||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||
self.num = len(self.srcs) - 1
|
||||
@ -386,7 +382,7 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
self.g = igmpv3_query(
|
||||
self.msgtype, self.maxresp, self.csum, self.address,
|
||||
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):
|
||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||
@ -397,13 +393,13 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
buf = bytearray(buf)
|
||||
pack_into('!H', buf, 2, 0)
|
||||
|
||||
eq_(res[0], IGMP_TYPE_QUERY)
|
||||
eq_(res[1], 100)
|
||||
eq_(res[2], checksum(buf))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
eq_(res[4], 2)
|
||||
eq_(res[5], 0)
|
||||
eq_(res[6], 0)
|
||||
self.assertEqual(res[0], IGMP_TYPE_QUERY)
|
||||
self.assertEqual(res[1], 100)
|
||||
self.assertEqual(res[2], checksum(buf))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(res[4], 2)
|
||||
self.assertEqual(res[5], 0)
|
||||
self.assertEqual(res[6], 0)
|
||||
|
||||
# srcs without num
|
||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||
@ -415,24 +411,24 @@ class Test_igmpv3_query(unittest.TestCase):
|
||||
buf = bytearray(buf)
|
||||
pack_into('!H', buf, 2, 0)
|
||||
|
||||
eq_(res[0], IGMP_TYPE_QUERY)
|
||||
eq_(res[1], 100)
|
||||
eq_(res[2], checksum(buf))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
eq_(res[4], 2)
|
||||
eq_(res[5], 0)
|
||||
eq_(res[6], len(srcs))
|
||||
self.assertEqual(res[0], IGMP_TYPE_QUERY)
|
||||
self.assertEqual(res[1], 100)
|
||||
self.assertEqual(res[2], checksum(buf))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(res[4], 2)
|
||||
self.assertEqual(res[5], 0)
|
||||
self.assertEqual(res[6], len(srcs))
|
||||
|
||||
res = unpack_from('4s4s4s', six.binary_type(buf), igmpv3_query._MIN_LEN)
|
||||
|
||||
eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||
eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||
eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||
self.assertEqual(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||
self.assertEqual(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.g.to_jsondict()
|
||||
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):
|
||||
self.setUp_with_srcs()
|
||||
@ -487,10 +483,10 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.msgtype, self.g.msgtype)
|
||||
eq_(self.csum, self.g.csum)
|
||||
eq_(self.record_num, self.g.record_num)
|
||||
eq_(self.records, self.g.records)
|
||||
self.assertEqual(self.msgtype, self.g.msgtype)
|
||||
self.assertEqual(self.csum, self.g.csum)
|
||||
self.assertEqual(self.record_num, self.g.record_num)
|
||||
self.assertEqual(self.records, self.g.records)
|
||||
|
||||
def test_init_with_records(self):
|
||||
self.setUp_with_records()
|
||||
@ -503,10 +499,10 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(res.msgtype, self.msgtype)
|
||||
eq_(res.csum, self.csum)
|
||||
eq_(res.record_num, self.record_num)
|
||||
eq_(repr(res.records), repr(self.records))
|
||||
self.assertEqual(res.msgtype, self.msgtype)
|
||||
self.assertEqual(res.csum, self.csum)
|
||||
self.assertEqual(res.record_num, self.record_num)
|
||||
self.assertEqual(repr(res.records), repr(self.records))
|
||||
|
||||
def test_parser_with_records(self):
|
||||
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))
|
||||
|
||||
eq_(res[0], self.msgtype)
|
||||
eq_(res[1], checksum(self.buf))
|
||||
eq_(res[2], self.record_num)
|
||||
self.assertEqual(res[0], self.msgtype)
|
||||
self.assertEqual(res[1], checksum(self.buf))
|
||||
self.assertEqual(res[2], self.record_num)
|
||||
|
||||
def test_serialize_with_records(self):
|
||||
self.setUp_with_records()
|
||||
@ -539,13 +535,13 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
offset += len(rec3)
|
||||
rec4 = igmpv3_report_group.parser(buf[offset:])
|
||||
|
||||
eq_(res[0], self.msgtype)
|
||||
eq_(res[1], checksum(self.buf))
|
||||
eq_(res[2], self.record_num)
|
||||
eq_(repr(rec1), repr(self.record1))
|
||||
eq_(repr(rec2), repr(self.record2))
|
||||
eq_(repr(rec3), repr(self.record3))
|
||||
eq_(repr(rec4), repr(self.record4))
|
||||
self.assertEqual(res[0], self.msgtype)
|
||||
self.assertEqual(res[1], checksum(self.buf))
|
||||
self.assertEqual(res[2], self.record_num)
|
||||
self.assertEqual(repr(rec1), repr(self.record1))
|
||||
self.assertEqual(repr(rec2), repr(self.record2))
|
||||
self.assertEqual(repr(rec3), repr(self.record3))
|
||||
self.assertEqual(repr(rec4), repr(self.record4))
|
||||
|
||||
def _build_igmp(self):
|
||||
dl_dst = '11:22:33:44:55:66'
|
||||
@ -572,20 +568,20 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
p = self._build_igmp()
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
i = self.find_protocol(p, "ipv4")
|
||||
ok_(i)
|
||||
eq_(i.proto, inet.IPPROTO_IGMP)
|
||||
self.assertTrue(i)
|
||||
self.assertEqual(i.proto, inet.IPPROTO_IGMP)
|
||||
|
||||
g = self.find_protocol(p, "igmpv3_report")
|
||||
ok_(g)
|
||||
self.assertTrue(g)
|
||||
|
||||
eq_(g.msgtype, self.msgtype)
|
||||
eq_(g.csum, checksum(self.buf))
|
||||
eq_(g.record_num, self.record_num)
|
||||
eq_(g.records, self.records)
|
||||
self.assertEqual(g.msgtype, self.msgtype)
|
||||
self.assertEqual(g.csum, checksum(self.buf))
|
||||
self.assertEqual(g.record_num, self.record_num)
|
||||
self.assertEqual(g.records, self.records)
|
||||
|
||||
def test_build_igmp_with_records(self):
|
||||
self.setUp_with_records()
|
||||
@ -601,14 +597,13 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
if k in igmp_values])
|
||||
g_str = '%s(%s)' % (igmpv3_report.__name__, _g_str)
|
||||
|
||||
eq_(str(self.g), g_str)
|
||||
eq_(repr(self.g), g_str)
|
||||
self.assertEqual(str(self.g), g_str)
|
||||
self.assertEqual(repr(self.g), g_str)
|
||||
|
||||
def test_to_string_with_records(self):
|
||||
self.setUp_with_records()
|
||||
self.test_to_string()
|
||||
|
||||
@raises(Exception)
|
||||
def test_record_num_larger_than_records(self):
|
||||
self.record1 = igmpv3_report_group(
|
||||
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.g = igmpv3_report(
|
||||
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):
|
||||
self.record1 = igmpv3_report_group(
|
||||
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.g = igmpv3_report(
|
||||
self.msgtype, self.csum, self.record_num, self.records)
|
||||
self.test_parser()
|
||||
self.assertRaises(Exception, self.test_parser)
|
||||
|
||||
def test_default_args(self):
|
||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||
@ -667,9 +661,9 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
buf = bytearray(buf)
|
||||
pack_into('!H', buf, 2, 0)
|
||||
|
||||
eq_(res[0], IGMP_TYPE_REPORT_V3)
|
||||
eq_(res[1], checksum(buf))
|
||||
eq_(res[2], 0)
|
||||
self.assertEqual(res[0], IGMP_TYPE_REPORT_V3)
|
||||
self.assertEqual(res[1], checksum(buf))
|
||||
self.assertEqual(res[2], 0)
|
||||
|
||||
# records without record_num
|
||||
prev = ipv4(proto=inet.IPPROTO_IGMP)
|
||||
@ -691,14 +685,14 @@ class Test_igmpv3_report(unittest.TestCase):
|
||||
buf = bytearray(buf)
|
||||
pack_into('!H', buf, 2, 0)
|
||||
|
||||
eq_(res[0], IGMP_TYPE_REPORT_V3)
|
||||
eq_(res[1], checksum(buf))
|
||||
eq_(res[2], len(records))
|
||||
self.assertEqual(res[0], IGMP_TYPE_REPORT_V3)
|
||||
self.assertEqual(res[1], checksum(buf))
|
||||
self.assertEqual(res[2], len(records))
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.g.to_jsondict()
|
||||
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):
|
||||
self.setUp_with_records()
|
||||
@ -767,12 +761,12 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.g.type_)
|
||||
eq_(self.aux_len, self.g.aux_len)
|
||||
eq_(self.num, self.g.num)
|
||||
eq_(self.address, self.g.address)
|
||||
eq_(self.srcs, self.g.srcs)
|
||||
eq_(self.aux, self.g.aux)
|
||||
self.assertEqual(self.type_, self.g.type_)
|
||||
self.assertEqual(self.aux_len, self.g.aux_len)
|
||||
self.assertEqual(self.num, self.g.num)
|
||||
self.assertEqual(self.address, self.g.address)
|
||||
self.assertEqual(self.srcs, self.g.srcs)
|
||||
self.assertEqual(self.aux, self.g.aux)
|
||||
|
||||
def test_init_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -793,12 +787,12 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(res.type_, self.type_)
|
||||
eq_(res.aux_len, self.aux_len)
|
||||
eq_(res.num, self.num)
|
||||
eq_(res.address, self.address)
|
||||
eq_(res.srcs, self.srcs)
|
||||
eq_(res.aux, self.aux)
|
||||
self.assertEqual(res.type_, self.type_)
|
||||
self.assertEqual(res.aux_len, self.aux_len)
|
||||
self.assertEqual(res.num, self.num)
|
||||
self.assertEqual(res.address, self.address)
|
||||
self.assertEqual(res.srcs, self.srcs)
|
||||
self.assertEqual(res.aux, self.aux)
|
||||
|
||||
def test_parser_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -816,10 +810,10 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
buf = self.g.serialize()
|
||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], self.type_)
|
||||
eq_(res[1], self.aux_len)
|
||||
eq_(res[2], self.num)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(res[0], self.type_)
|
||||
self.assertEqual(res[1], self.aux_len)
|
||||
self.assertEqual(res[2], self.num)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
|
||||
def test_serialize_with_srcs(self):
|
||||
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))
|
||||
(src1, src2, src3) = unpack_from('4s4s4s', six.binary_type(buf),
|
||||
igmpv3_report_group._MIN_LEN)
|
||||
eq_(res[0], self.type_)
|
||||
eq_(res[1], self.aux_len)
|
||||
eq_(res[2], self.num)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
self.assertEqual(res[0], self.type_)
|
||||
self.assertEqual(res[1], self.aux_len)
|
||||
self.assertEqual(res[2], self.num)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
|
||||
def test_serialize_with_aux(self):
|
||||
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))
|
||||
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
||||
igmpv3_report_group._MIN_LEN)
|
||||
eq_(res[0], self.type_)
|
||||
eq_(res[1], self.aux_len)
|
||||
eq_(res[2], self.num)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
eq_(aux, self.aux)
|
||||
self.assertEqual(res[0], self.type_)
|
||||
self.assertEqual(res[1], self.aux_len)
|
||||
self.assertEqual(res[2], self.num)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(aux, self.aux)
|
||||
|
||||
def test_serialize_with_srcs_and_aux(self):
|
||||
self.setUp_with_srcs_and_aux()
|
||||
@ -855,14 +849,14 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
igmpv3_report_group._MIN_LEN)
|
||||
(aux, ) = unpack_from('%ds' % (self.aux_len * 4), six.binary_type(buf),
|
||||
igmpv3_report_group._MIN_LEN + 12)
|
||||
eq_(res[0], self.type_)
|
||||
eq_(res[1], self.aux_len)
|
||||
eq_(res[2], self.num)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
eq_(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
eq_(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
eq_(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
eq_(aux, self.aux)
|
||||
self.assertEqual(res[0], self.type_)
|
||||
self.assertEqual(res[1], self.aux_len)
|
||||
self.assertEqual(res[2], self.num)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin(self.address))
|
||||
self.assertEqual(src1, addrconv.ipv4.text_to_bin(self.srcs[0]))
|
||||
self.assertEqual(src2, addrconv.ipv4.text_to_bin(self.srcs[1]))
|
||||
self.assertEqual(src3, addrconv.ipv4.text_to_bin(self.srcs[2]))
|
||||
self.assertEqual(aux, self.aux)
|
||||
|
||||
def test_to_string(self):
|
||||
igmp_values = {'type_': repr(self.type_),
|
||||
@ -876,8 +870,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
if k in igmp_values])
|
||||
g_str = '%s(%s)' % (igmpv3_report_group.__name__, _g_str)
|
||||
|
||||
eq_(str(self.g), g_str)
|
||||
eq_(repr(self.g), g_str)
|
||||
self.assertEqual(str(self.g), g_str)
|
||||
self.assertEqual(repr(self.g), g_str)
|
||||
|
||||
def test_to_string_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
@ -892,21 +886,20 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
self.test_to_string()
|
||||
|
||||
def test_len(self):
|
||||
eq_(len(self.g), 8)
|
||||
self.assertEqual(len(self.g), 8)
|
||||
|
||||
def test_len_with_srcs(self):
|
||||
self.setUp_with_srcs()
|
||||
eq_(len(self.g), 20)
|
||||
self.assertEqual(len(self.g), 20)
|
||||
|
||||
def test_len_with_aux(self):
|
||||
self.setUp_with_aux()
|
||||
eq_(len(self.g), 16)
|
||||
self.assertEqual(len(self.g), 16)
|
||||
|
||||
def test_len_with_srcs_and_aux(self):
|
||||
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):
|
||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||
self.num = len(self.srcs) + 1
|
||||
@ -918,9 +911,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
self.g = igmpv3_report_group(
|
||||
self.type_, self.aux_len, self.num, self.address,
|
||||
self.srcs, self.aux)
|
||||
self.test_parser()
|
||||
self.assertRaises(AssertionError, self.test_parser)
|
||||
|
||||
@raises
|
||||
def test_num_smaller_than_srcs(self):
|
||||
self.srcs = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
|
||||
self.num = len(self.srcs) - 1
|
||||
@ -932,9 +924,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
self.g = igmpv3_report_group(
|
||||
self.type_, self.aux_len, self.num, self.address,
|
||||
self.srcs, self.aux)
|
||||
self.test_parser()
|
||||
self.assertRaises(AssertionError, self.test_parser)
|
||||
|
||||
@raises
|
||||
def test_aux_len_larger_than_aux(self):
|
||||
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
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.type_, self.aux_len, self.num, self.address,
|
||||
self.srcs, self.aux)
|
||||
self.test_parser()
|
||||
self.assertRaises(Exception, self.test_parser)
|
||||
|
||||
@raises
|
||||
def test_aux_len_smaller_than_aux(self):
|
||||
self.aux = b'\x01\x02\x03\x04\x05\x00\x00\x00'
|
||||
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.type_, self.aux_len, self.num, self.address,
|
||||
self.srcs, self.aux)
|
||||
self.test_parser()
|
||||
self.assertRaises(AssertionError, self.test_parser)
|
||||
|
||||
def test_default_args(self):
|
||||
rep = igmpv3_report_group()
|
||||
buf = rep.serialize()
|
||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(res[0], 0)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
|
||||
# srcs without num
|
||||
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()
|
||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], len(srcs))
|
||||
eq_(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(res[0], 0)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[2], len(srcs))
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
|
||||
res = unpack_from('4s4s4s', six.binary_type(buf),
|
||||
igmpv3_report_group._MIN_LEN)
|
||||
|
||||
eq_(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||
eq_(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||
eq_(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||
self.assertEqual(res[0], addrconv.ipv4.text_to_bin(srcs[0]))
|
||||
self.assertEqual(res[1], addrconv.ipv4.text_to_bin(srcs[1]))
|
||||
self.assertEqual(res[2], addrconv.ipv4.text_to_bin(srcs[2]))
|
||||
|
||||
# aux without aux_len
|
||||
aux = b'abcde'
|
||||
@ -994,8 +984,8 @@ class Test_igmpv3_report_group(unittest.TestCase):
|
||||
buf = rep.serialize()
|
||||
res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 0)
|
||||
eq_(res[1], 2)
|
||||
eq_(res[2], 0)
|
||||
eq_(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(res[0], 0)
|
||||
self.assertEqual(res[1], 2)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], addrconv.ipv4.text_to_bin('0.0.0.0'))
|
||||
self.assertEqual(buf[igmpv3_report_group._MIN_LEN:], b'abcde\x00\x00\x00')
|
||||
|
@ -20,7 +20,6 @@ import logging
|
||||
import six
|
||||
import struct
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import ether, inet
|
||||
from os_ken.lib.packet import packet_utils
|
||||
from os_ken.lib.packet.ethernet import ethernet
|
||||
@ -74,64 +73,63 @@ class Test_ipv4(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.version, self.ip.version)
|
||||
eq_(self.header_length, self.ip.header_length)
|
||||
eq_(self.tos, self.ip.tos)
|
||||
eq_(self.total_length, self.ip.total_length)
|
||||
eq_(self.identification, self.ip.identification)
|
||||
eq_(self.flags, self.ip.flags)
|
||||
eq_(self.offset, self.ip.offset)
|
||||
eq_(self.ttl, self.ip.ttl)
|
||||
eq_(self.proto, self.ip.proto)
|
||||
eq_(self.csum, self.ip.csum)
|
||||
eq_(self.src, self.ip.src)
|
||||
eq_(self.dst, self.ip.dst)
|
||||
eq_(self.length, len(self.ip))
|
||||
eq_(self.option, self.ip.option)
|
||||
self.assertEqual(self.version, self.ip.version)
|
||||
self.assertEqual(self.header_length, self.ip.header_length)
|
||||
self.assertEqual(self.tos, self.ip.tos)
|
||||
self.assertEqual(self.total_length, self.ip.total_length)
|
||||
self.assertEqual(self.identification, self.ip.identification)
|
||||
self.assertEqual(self.flags, self.ip.flags)
|
||||
self.assertEqual(self.offset, self.ip.offset)
|
||||
self.assertEqual(self.ttl, self.ip.ttl)
|
||||
self.assertEqual(self.proto, self.ip.proto)
|
||||
self.assertEqual(self.csum, self.ip.csum)
|
||||
self.assertEqual(self.src, self.ip.src)
|
||||
self.assertEqual(self.dst, self.ip.dst)
|
||||
self.assertEqual(self.length, len(self.ip))
|
||||
self.assertEqual(self.option, self.ip.option)
|
||||
|
||||
def test_parser(self):
|
||||
res, ptype, _ = self.ip.parser(self.buf)
|
||||
|
||||
eq_(res.version, self.version)
|
||||
eq_(res.header_length, self.header_length)
|
||||
eq_(res.tos, self.tos)
|
||||
eq_(res.total_length, self.total_length)
|
||||
eq_(res.identification, self.identification)
|
||||
eq_(res.flags, self.flags)
|
||||
eq_(res.offset, self.offset)
|
||||
eq_(res.ttl, self.ttl)
|
||||
eq_(res.proto, self.proto)
|
||||
eq_(res.csum, self.csum)
|
||||
eq_(res.src, self.src)
|
||||
eq_(res.dst, self.dst)
|
||||
eq_(ptype, tcp)
|
||||
self.assertEqual(res.version, self.version)
|
||||
self.assertEqual(res.header_length, self.header_length)
|
||||
self.assertEqual(res.tos, self.tos)
|
||||
self.assertEqual(res.total_length, self.total_length)
|
||||
self.assertEqual(res.identification, self.identification)
|
||||
self.assertEqual(res.flags, self.flags)
|
||||
self.assertEqual(res.offset, self.offset)
|
||||
self.assertEqual(res.ttl, self.ttl)
|
||||
self.assertEqual(res.proto, self.proto)
|
||||
self.assertEqual(res.csum, self.csum)
|
||||
self.assertEqual(res.src, self.src)
|
||||
self.assertEqual(res.dst, self.dst)
|
||||
self.assertEqual(ptype, tcp)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.ip.serialize(bytearray(), None)
|
||||
res = struct.unpack_from(ipv4._PACK_STR, six.binary_type(buf))
|
||||
option = buf[ipv4._MIN_LEN:ipv4._MIN_LEN + len(self.option)]
|
||||
|
||||
eq_(res[0], self.ver_hlen)
|
||||
eq_(res[1], self.tos)
|
||||
eq_(res[2], self.total_length)
|
||||
eq_(res[3], self.identification)
|
||||
eq_(res[4], self.flg_off)
|
||||
eq_(res[5], self.ttl)
|
||||
eq_(res[6], self.proto)
|
||||
eq_(res[8], addrconv.ipv4.text_to_bin(self.src))
|
||||
eq_(res[9], addrconv.ipv4.text_to_bin(self.dst))
|
||||
eq_(option, self.option)
|
||||
self.assertEqual(res[0], self.ver_hlen)
|
||||
self.assertEqual(res[1], self.tos)
|
||||
self.assertEqual(res[2], self.total_length)
|
||||
self.assertEqual(res[3], self.identification)
|
||||
self.assertEqual(res[4], self.flg_off)
|
||||
self.assertEqual(res[5], self.ttl)
|
||||
self.assertEqual(res[6], self.proto)
|
||||
self.assertEqual(res[8], addrconv.ipv4.text_to_bin(self.src))
|
||||
self.assertEqual(res[9], addrconv.ipv4.text_to_bin(self.dst))
|
||||
self.assertEqual(option, self.option)
|
||||
|
||||
# checksum
|
||||
csum = packet_utils.checksum(buf)
|
||||
eq_(csum, 0)
|
||||
self.assertEqual(csum, 0)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_ipv4(self):
|
||||
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):
|
||||
jsondict = self.ip.to_jsondict()
|
||||
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 struct
|
||||
|
||||
from nose.tools import *
|
||||
from os_ken.lib import addrconv
|
||||
from os_ken.lib import ip
|
||||
from os_ken.lib.packet import ipv6
|
||||
@ -228,15 +227,15 @@ class Test_ipv6(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.version, self.ip.version)
|
||||
eq_(self.traffic_class, self.ip.traffic_class)
|
||||
eq_(self.flow_label, self.ip.flow_label)
|
||||
eq_(self.payload_length, self.ip.payload_length)
|
||||
eq_(self.nxt, self.ip.nxt)
|
||||
eq_(self.hop_limit, self.ip.hop_limit)
|
||||
eq_(self.src, self.ip.src)
|
||||
eq_(self.dst, self.ip.dst)
|
||||
eq_(str(self.ext_hdrs), str(self.ip.ext_hdrs))
|
||||
self.assertEqual(self.version, self.ip.version)
|
||||
self.assertEqual(self.traffic_class, self.ip.traffic_class)
|
||||
self.assertEqual(self.flow_label, self.ip.flow_label)
|
||||
self.assertEqual(self.payload_length, self.ip.payload_length)
|
||||
self.assertEqual(self.nxt, self.ip.nxt)
|
||||
self.assertEqual(self.hop_limit, self.ip.hop_limit)
|
||||
self.assertEqual(self.src, self.ip.src)
|
||||
self.assertEqual(self.dst, self.ip.dst)
|
||||
self.assertEqual(str(self.ext_hdrs), str(self.ip.ext_hdrs))
|
||||
|
||||
def test_init_with_hop_opts(self):
|
||||
self.setUp_with_hop_opts()
|
||||
@ -269,15 +268,15 @@ class Test_ipv6(unittest.TestCase):
|
||||
else:
|
||||
res = _res
|
||||
|
||||
eq_(self.version, res.version)
|
||||
eq_(self.traffic_class, res.traffic_class)
|
||||
eq_(self.flow_label, res.flow_label)
|
||||
eq_(self.payload_length, res.payload_length)
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.hop_limit, res.hop_limit)
|
||||
eq_(self.src, res.src)
|
||||
eq_(self.dst, res.dst)
|
||||
eq_(str(self.ext_hdrs), str(res.ext_hdrs))
|
||||
self.assertEqual(self.version, res.version)
|
||||
self.assertEqual(self.traffic_class, res.traffic_class)
|
||||
self.assertEqual(self.flow_label, res.flow_label)
|
||||
self.assertEqual(self.payload_length, res.payload_length)
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.hop_limit, res.hop_limit)
|
||||
self.assertEqual(self.src, res.src)
|
||||
self.assertEqual(self.dst, res.dst)
|
||||
self.assertEqual(str(self.ext_hdrs), str(res.ext_hdrs))
|
||||
|
||||
def test_parser_with_hop_opts(self):
|
||||
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))
|
||||
|
||||
eq_(self.v_tc_flow, res[0])
|
||||
eq_(self.payload_length, res[1])
|
||||
eq_(self.nxt, res[2])
|
||||
eq_(self.hop_limit, res[3])
|
||||
eq_(self.src, addrconv.ipv6.bin_to_text(res[4]))
|
||||
eq_(self.dst, addrconv.ipv6.bin_to_text(res[5]))
|
||||
self.assertEqual(self.v_tc_flow, res[0])
|
||||
self.assertEqual(self.payload_length, res[1])
|
||||
self.assertEqual(self.nxt, res[2])
|
||||
self.assertEqual(self.hop_limit, res[3])
|
||||
self.assertEqual(self.src, addrconv.ipv6.bin_to_text(res[4]))
|
||||
self.assertEqual(self.dst, addrconv.ipv6.bin_to_text(res[5]))
|
||||
|
||||
def test_serialize_with_hop_opts(self):
|
||||
self.setUp_with_hop_opts()
|
||||
@ -325,7 +324,7 @@ class Test_ipv6(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ip.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_dst_opts()
|
||||
@ -335,7 +334,7 @@ class Test_ipv6(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ip.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_routing_type3()
|
||||
@ -345,7 +344,7 @@ class Test_ipv6(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ip.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_fragment()
|
||||
@ -355,7 +354,7 @@ class Test_ipv6(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ip.serialize(data, prev)
|
||||
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):
|
||||
self.setUp_with_auth()
|
||||
@ -365,7 +364,7 @@ class Test_ipv6(unittest.TestCase):
|
||||
prev = None
|
||||
buf = self.ip.serialize(data, prev)
|
||||
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):
|
||||
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:]))
|
||||
offset += len(hop_opts)
|
||||
auth = ipv6.auth.parser(six.binary_type(buf[offset:]))
|
||||
eq_(repr(self.hop_opts), repr(hop_opts))
|
||||
eq_(repr(self.auth), repr(auth))
|
||||
self.assertEqual(repr(self.hop_opts), repr(hop_opts))
|
||||
self.assertEqual(repr(self.auth), repr(auth))
|
||||
|
||||
def test_to_string(self):
|
||||
ipv6_values = {'version': self.version,
|
||||
@ -396,8 +395,8 @@ class Test_ipv6(unittest.TestCase):
|
||||
if k in ipv6_values])
|
||||
ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)
|
||||
|
||||
eq_(str(self.ip), ipv6_str)
|
||||
eq_(repr(self.ip), ipv6_str)
|
||||
self.assertEqual(str(self.ip), ipv6_str)
|
||||
self.assertEqual(repr(self.ip), ipv6_str)
|
||||
|
||||
def test_to_string_with_hop_opts(self):
|
||||
self.setUp_with_hop_opts()
|
||||
@ -420,43 +419,43 @@ class Test_ipv6(unittest.TestCase):
|
||||
self.test_to_string()
|
||||
|
||||
def test_len(self):
|
||||
eq_(len(self.ip), 40)
|
||||
self.assertEqual(len(self.ip), 40)
|
||||
|
||||
def test_len_with_hop_opts(self):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
ip = ipv6.ipv6()
|
||||
buf = ip.serialize(bytearray(), None)
|
||||
res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 6 << 28)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], 6)
|
||||
eq_(res[3], 255)
|
||||
eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||
eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||
self.assertEqual(res[0], 6 << 28)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[2], 6)
|
||||
self.assertEqual(res[3], 255)
|
||||
self.assertEqual(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||
self.assertEqual(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||
|
||||
# with extension header
|
||||
ip = ipv6.ipv6(
|
||||
@ -467,18 +466,18 @@ class Test_ipv6(unittest.TestCase):
|
||||
buf = ip.serialize(bytearray(), None)
|
||||
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf))
|
||||
|
||||
eq_(res[0], 6 << 28)
|
||||
eq_(res[1], 8)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], 255)
|
||||
eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||
eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||
eq_(res[6], b'\x3a\x00\x05\x02\x00\x00\x01\x00')
|
||||
self.assertEqual(res[0], 6 << 28)
|
||||
self.assertEqual(res[1], 8)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], 255)
|
||||
self.assertEqual(res[4], addrconv.ipv6.text_to_bin('10::10'))
|
||||
self.assertEqual(res[5], addrconv.ipv6.text_to_bin('20::20'))
|
||||
self.assertEqual(res[6], b'\x3a\x00\x05\x02\x00\x00\x01\x00')
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.ip.to_jsondict()
|
||||
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):
|
||||
self.setUp_with_hop_opts()
|
||||
@ -528,13 +527,12 @@ class Test_hop_opts(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.nxt, self.hop.nxt)
|
||||
eq_(self.size, self.hop.size)
|
||||
eq_(self.data, self.hop.data)
|
||||
self.assertEqual(self.nxt, self.hop.nxt)
|
||||
self.assertEqual(self.size, self.hop.size)
|
||||
self.assertEqual(self.data, self.hop.data)
|
||||
|
||||
@raises(Exception)
|
||||
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):
|
||||
_res = ipv6.hop_opts.parser(self.buf)
|
||||
@ -542,15 +540,15 @@ class Test_hop_opts(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.size, res.size)
|
||||
eq_(str(self.data), str(res.data))
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.size, res.size)
|
||||
self.assertEqual(str(self.data), str(res.data))
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.hop.serialize()
|
||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||
eq_(self.nxt, res[0])
|
||||
eq_(self.size, res[1])
|
||||
self.assertEqual(self.nxt, res[0])
|
||||
self.assertEqual(self.size, res[1])
|
||||
offset = struct.calcsize(self.form)
|
||||
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
offset += len(opt1)
|
||||
@ -559,31 +557,31 @@ class Test_hop_opts(unittest.TestCase):
|
||||
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
offset += len(opt3)
|
||||
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
eq_(5, opt1.type_)
|
||||
eq_(2, opt1.len_)
|
||||
eq_(b'\x00\x00', opt1.data)
|
||||
eq_(1, opt2.type_)
|
||||
eq_(0, opt2.len_)
|
||||
eq_(None, opt2.data)
|
||||
eq_(0xc2, opt3.type_)
|
||||
eq_(4, opt3.len_)
|
||||
eq_(b'\x00\x01\x00\x00', opt3.data)
|
||||
eq_(1, opt4.type_)
|
||||
eq_(0, opt4.len_)
|
||||
eq_(None, opt4.data)
|
||||
self.assertEqual(5, opt1.type_)
|
||||
self.assertEqual(2, opt1.len_)
|
||||
self.assertEqual(b'\x00\x00', opt1.data)
|
||||
self.assertEqual(1, opt2.type_)
|
||||
self.assertEqual(0, opt2.len_)
|
||||
self.assertEqual(None, opt2.data)
|
||||
self.assertEqual(0xc2, opt3.type_)
|
||||
self.assertEqual(4, opt3.len_)
|
||||
self.assertEqual(b'\x00\x01\x00\x00', opt3.data)
|
||||
self.assertEqual(1, opt4.type_)
|
||||
self.assertEqual(0, opt4.len_)
|
||||
self.assertEqual(None, opt4.data)
|
||||
|
||||
def test_len(self):
|
||||
eq_(16, len(self.hop))
|
||||
self.assertEqual(16, len(self.hop))
|
||||
|
||||
def test_default_args(self):
|
||||
hdr = ipv6.hop_opts()
|
||||
buf = hdr.serialize()
|
||||
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
||||
|
||||
eq_(res[0], 6)
|
||||
eq_(res[1], 0)
|
||||
self.assertEqual(res[0], 6)
|
||||
self.assertEqual(res[1], 0)
|
||||
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):
|
||||
@ -609,13 +607,12 @@ class Test_dst_opts(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.nxt, self.dst.nxt)
|
||||
eq_(self.size, self.dst.size)
|
||||
eq_(self.data, self.dst.data)
|
||||
self.assertEqual(self.nxt, self.dst.nxt)
|
||||
self.assertEqual(self.size, self.dst.size)
|
||||
self.assertEqual(self.data, self.dst.data)
|
||||
|
||||
@raises(Exception)
|
||||
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):
|
||||
_res = ipv6.dst_opts.parser(self.buf)
|
||||
@ -623,15 +620,15 @@ class Test_dst_opts(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.size, res.size)
|
||||
eq_(str(self.data), str(res.data))
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.size, res.size)
|
||||
self.assertEqual(str(self.data), str(res.data))
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.dst.serialize()
|
||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||
eq_(self.nxt, res[0])
|
||||
eq_(self.size, res[1])
|
||||
self.assertEqual(self.nxt, res[0])
|
||||
self.assertEqual(self.size, res[1])
|
||||
offset = struct.calcsize(self.form)
|
||||
opt1 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
offset += len(opt1)
|
||||
@ -640,31 +637,31 @@ class Test_dst_opts(unittest.TestCase):
|
||||
opt3 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
offset += len(opt3)
|
||||
opt4 = ipv6.option.parser(six.binary_type(buf[offset:]))
|
||||
eq_(5, opt1.type_)
|
||||
eq_(2, opt1.len_)
|
||||
eq_(b'\x00\x00', opt1.data)
|
||||
eq_(1, opt2.type_)
|
||||
eq_(0, opt2.len_)
|
||||
eq_(None, opt2.data)
|
||||
eq_(0xc2, opt3.type_)
|
||||
eq_(4, opt3.len_)
|
||||
eq_(b'\x00\x01\x00\x00', opt3.data)
|
||||
eq_(1, opt4.type_)
|
||||
eq_(0, opt4.len_)
|
||||
eq_(None, opt4.data)
|
||||
self.assertEqual(5, opt1.type_)
|
||||
self.assertEqual(2, opt1.len_)
|
||||
self.assertEqual(b'\x00\x00', opt1.data)
|
||||
self.assertEqual(1, opt2.type_)
|
||||
self.assertEqual(0, opt2.len_)
|
||||
self.assertEqual(None, opt2.data)
|
||||
self.assertEqual(0xc2, opt3.type_)
|
||||
self.assertEqual(4, opt3.len_)
|
||||
self.assertEqual(b'\x00\x01\x00\x00', opt3.data)
|
||||
self.assertEqual(1, opt4.type_)
|
||||
self.assertEqual(0, opt4.len_)
|
||||
self.assertEqual(None, opt4.data)
|
||||
|
||||
def test_len(self):
|
||||
eq_(16, len(self.dst))
|
||||
self.assertEqual(16, len(self.dst))
|
||||
|
||||
def test_default_args(self):
|
||||
hdr = ipv6.dst_opts()
|
||||
buf = hdr.serialize()
|
||||
res = struct.unpack('!BB', six.binary_type(buf[:2]))
|
||||
|
||||
eq_(res[0], 6)
|
||||
eq_(res[1], 0)
|
||||
self.assertEqual(res[0], 6)
|
||||
self.assertEqual(res[1], 0)
|
||||
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):
|
||||
@ -681,9 +678,9 @@ class Test_option(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.opt.type_)
|
||||
eq_(self.len_, self.opt.len_)
|
||||
eq_(self.data, self.opt.data)
|
||||
self.assertEqual(self.type_, self.opt.type_)
|
||||
self.assertEqual(self.len_, self.opt.len_)
|
||||
self.assertEqual(self.data, self.opt.data)
|
||||
|
||||
def test_parser(self):
|
||||
_res = ipv6.option.parser(self.buf)
|
||||
@ -691,19 +688,19 @@ class Test_option(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.type_, res.type_)
|
||||
eq_(self.len_, res.len_)
|
||||
eq_(self.data, res.data)
|
||||
self.assertEqual(self.type_, res.type_)
|
||||
self.assertEqual(self.len_, res.len_)
|
||||
self.assertEqual(self.data, res.data)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.opt.serialize()
|
||||
res = struct.unpack_from(self.form, buf)
|
||||
eq_(self.type_, res[0])
|
||||
eq_(self.len_, res[1])
|
||||
eq_(self.data, res[2])
|
||||
self.assertEqual(self.type_, res[0])
|
||||
self.assertEqual(self.len_, res[1])
|
||||
self.assertEqual(self.data, res[2])
|
||||
|
||||
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):
|
||||
@ -719,14 +716,14 @@ class Test_option_pad1(Test_option):
|
||||
def test_serialize(self):
|
||||
buf = self.opt.serialize()
|
||||
res = struct.unpack_from(self.form, buf)
|
||||
eq_(self.type_, res[0])
|
||||
self.assertEqual(self.type_, res[0])
|
||||
|
||||
def test_default_args(self):
|
||||
opt = ipv6.option()
|
||||
buf = opt.serialize()
|
||||
res = struct.unpack('!B', buf)
|
||||
|
||||
eq_(res[0], 0)
|
||||
self.assertEqual(res[0], 0)
|
||||
|
||||
|
||||
class Test_option_padN(Test_option):
|
||||
@ -742,8 +739,8 @@ class Test_option_padN(Test_option):
|
||||
def test_serialize(self):
|
||||
buf = self.opt.serialize()
|
||||
res = struct.unpack_from(self.form, buf)
|
||||
eq_(self.type_, res[0])
|
||||
eq_(self.len_, res[1])
|
||||
self.assertEqual(self.type_, res[0])
|
||||
self.assertEqual(self.len_, res[1])
|
||||
|
||||
|
||||
class Test_routing(unittest.TestCase):
|
||||
@ -780,16 +777,16 @@ class Test_routing(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.size, res.size)
|
||||
eq_(self.type_, res.type_)
|
||||
eq_(self.seg, res.seg)
|
||||
eq_(self.cmpi, res.cmpi)
|
||||
eq_(self.cmpe, res.cmpe)
|
||||
eq_(self.pad, res._pad)
|
||||
eq_(self.adrs[0], res.adrs[0])
|
||||
eq_(self.adrs[1], res.adrs[1])
|
||||
eq_(self.adrs[2], res.adrs[2])
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.size, res.size)
|
||||
self.assertEqual(self.type_, res.type_)
|
||||
self.assertEqual(self.seg, res.seg)
|
||||
self.assertEqual(self.cmpi, res.cmpi)
|
||||
self.assertEqual(self.cmpe, res.cmpe)
|
||||
self.assertEqual(self.pad, res._pad)
|
||||
self.assertEqual(self.adrs[0], res.adrs[0])
|
||||
self.assertEqual(self.adrs[1], res.adrs[1])
|
||||
self.assertEqual(self.adrs[2], res.adrs[2])
|
||||
|
||||
def test_not_implemented_type(self):
|
||||
not_implemented_buf = struct.pack(
|
||||
@ -833,16 +830,16 @@ class Test_routing_type3(unittest.TestCase):
|
||||
addrconv.ipv6.text_to_bin(self.adrs[2]))
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.nxt, self.routing.nxt)
|
||||
eq_(self.size, self.routing.size)
|
||||
eq_(self.type_, self.routing.type_)
|
||||
eq_(self.seg, self.routing.seg)
|
||||
eq_(self.cmpi, self.routing.cmpi)
|
||||
eq_(self.cmpe, self.routing.cmpe)
|
||||
eq_(self.pad, self.routing._pad)
|
||||
eq_(self.adrs[0], self.routing.adrs[0])
|
||||
eq_(self.adrs[1], self.routing.adrs[1])
|
||||
eq_(self.adrs[2], self.routing.adrs[2])
|
||||
self.assertEqual(self.nxt, self.routing.nxt)
|
||||
self.assertEqual(self.size, self.routing.size)
|
||||
self.assertEqual(self.type_, self.routing.type_)
|
||||
self.assertEqual(self.seg, self.routing.seg)
|
||||
self.assertEqual(self.cmpi, self.routing.cmpi)
|
||||
self.assertEqual(self.cmpe, self.routing.cmpe)
|
||||
self.assertEqual(self.pad, self.routing._pad)
|
||||
self.assertEqual(self.adrs[0], self.routing.adrs[0])
|
||||
self.assertEqual(self.adrs[1], self.routing.adrs[1])
|
||||
self.assertEqual(self.adrs[2], self.routing.adrs[2])
|
||||
|
||||
def test_parser(self):
|
||||
_res = ipv6.routing.parser(self.buf)
|
||||
@ -850,30 +847,30 @@ class Test_routing_type3(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.size, res.size)
|
||||
eq_(self.type_, res.type_)
|
||||
eq_(self.seg, res.seg)
|
||||
eq_(self.cmpi, res.cmpi)
|
||||
eq_(self.cmpe, res.cmpe)
|
||||
eq_(self.pad, res._pad)
|
||||
eq_(self.adrs[0], res.adrs[0])
|
||||
eq_(self.adrs[1], res.adrs[1])
|
||||
eq_(self.adrs[2], res.adrs[2])
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.size, res.size)
|
||||
self.assertEqual(self.type_, res.type_)
|
||||
self.assertEqual(self.seg, res.seg)
|
||||
self.assertEqual(self.cmpi, res.cmpi)
|
||||
self.assertEqual(self.cmpe, res.cmpe)
|
||||
self.assertEqual(self.pad, res._pad)
|
||||
self.assertEqual(self.adrs[0], res.adrs[0])
|
||||
self.assertEqual(self.adrs[1], res.adrs[1])
|
||||
self.assertEqual(self.adrs[2], res.adrs[2])
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.routing.serialize()
|
||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||
eq_(self.nxt, res[0])
|
||||
eq_(self.size, res[1])
|
||||
eq_(self.type_, res[2])
|
||||
eq_(self.seg, res[3])
|
||||
eq_(self.cmpi, res[4] >> 4)
|
||||
eq_(self.cmpe, res[4] & 0xf)
|
||||
eq_(self.pad, res[5])
|
||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[0]), res[6])
|
||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[1]), res[7])
|
||||
eq_(addrconv.ipv6.text_to_bin(self.adrs[2]), res[8])
|
||||
self.assertEqual(self.nxt, res[0])
|
||||
self.assertEqual(self.size, res[1])
|
||||
self.assertEqual(self.type_, res[2])
|
||||
self.assertEqual(self.seg, res[3])
|
||||
self.assertEqual(self.cmpi, res[4] >> 4)
|
||||
self.assertEqual(self.cmpe, res[4] & 0xf)
|
||||
self.assertEqual(self.pad, res[5])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[0]), res[6])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[1]), res[7])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(self.adrs[2]), res[8])
|
||||
|
||||
def test_parser_with_adrs_zero(self):
|
||||
nxt = 0
|
||||
@ -894,13 +891,13 @@ class Test_routing_type3(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(nxt, res.nxt)
|
||||
eq_(size, res.size)
|
||||
eq_(type_, res.type_)
|
||||
eq_(seg, res.seg)
|
||||
eq_(cmpi, res.cmpi)
|
||||
eq_(cmpe, res.cmpe)
|
||||
eq_(pad, res._pad)
|
||||
self.assertEqual(nxt, res.nxt)
|
||||
self.assertEqual(size, res.size)
|
||||
self.assertEqual(type_, res.type_)
|
||||
self.assertEqual(seg, res.seg)
|
||||
self.assertEqual(cmpi, res.cmpi)
|
||||
self.assertEqual(cmpe, res.cmpe)
|
||||
self.assertEqual(pad, res._pad)
|
||||
|
||||
def test_serialize_with_adrs_zero(self):
|
||||
nxt = 0
|
||||
@ -918,13 +915,13 @@ class Test_routing_type3(unittest.TestCase):
|
||||
buf = routing.serialize()
|
||||
form = '!BBBBBB2x'
|
||||
res = struct.unpack_from(form, six.binary_type(buf))
|
||||
eq_(nxt, res[0])
|
||||
eq_(size, res[1])
|
||||
eq_(type_, res[2])
|
||||
eq_(seg, res[3])
|
||||
eq_(cmpi, res[4] >> 4)
|
||||
eq_(cmpe, res[4] & 0xf)
|
||||
eq_(pad, res[5])
|
||||
self.assertEqual(nxt, res[0])
|
||||
self.assertEqual(size, res[1])
|
||||
self.assertEqual(type_, res[2])
|
||||
self.assertEqual(seg, res[3])
|
||||
self.assertEqual(cmpi, res[4] >> 4)
|
||||
self.assertEqual(cmpe, res[4] & 0xf)
|
||||
self.assertEqual(pad, res[5])
|
||||
|
||||
def test_parser_with_compression(self):
|
||||
pass
|
||||
@ -952,16 +949,16 @@ class Test_routing_type3(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(nxt, res.nxt)
|
||||
eq_(size, res.size)
|
||||
eq_(type_, res.type_)
|
||||
eq_(seg, res.seg)
|
||||
eq_(cmpi, res.cmpi)
|
||||
eq_(cmpe, res.cmpe)
|
||||
eq_(pad, res._pad)
|
||||
eq_("::4567:89ab:cdef:1", res.adrs[0])
|
||||
eq_("::4567:89ab:cdef:2", res.adrs[1])
|
||||
eq_("::205.239.0.3", res.adrs[2])
|
||||
self.assertEqual(nxt, res.nxt)
|
||||
self.assertEqual(size, res.size)
|
||||
self.assertEqual(type_, res.type_)
|
||||
self.assertEqual(seg, res.seg)
|
||||
self.assertEqual(cmpi, res.cmpi)
|
||||
self.assertEqual(cmpe, res.cmpe)
|
||||
self.assertEqual(pad, res._pad)
|
||||
self.assertEqual("::4567:89ab:cdef:1", res.adrs[0])
|
||||
self.assertEqual("::4567:89ab:cdef:2", res.adrs[1])
|
||||
self.assertEqual("::205.239.0.3", res.adrs[2])
|
||||
|
||||
def test_serialize_with_compression(self):
|
||||
nxt = 0
|
||||
@ -982,19 +979,19 @@ class Test_routing_type3(unittest.TestCase):
|
||||
buf = routing.serialize()
|
||||
form = '!BBBBBB2x8s8s8s'
|
||||
res = struct.unpack_from(form, six.binary_type(buf))
|
||||
eq_(nxt, res[0])
|
||||
eq_(size, res[1])
|
||||
eq_(type_, res[2])
|
||||
eq_(seg, res[3])
|
||||
eq_(cmpi, res[4] >> 4)
|
||||
eq_(cmpe, res[4] & 0xf)
|
||||
eq_(pad, res[5])
|
||||
eq_(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6])
|
||||
eq_(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(nxt, res[0])
|
||||
self.assertEqual(size, res[1])
|
||||
self.assertEqual(type_, res[2])
|
||||
self.assertEqual(seg, res[3])
|
||||
self.assertEqual(cmpi, res[4] >> 4)
|
||||
self.assertEqual(cmpe, res[4] & 0xf)
|
||||
self.assertEqual(pad, res[5])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[1])[slice_i], res[7])
|
||||
self.assertEqual(addrconv.ipv6.text_to_bin(adrs[2])[slice_e], res[8])
|
||||
|
||||
def test_len(self):
|
||||
eq_((6 + 1) * 8, len(self.routing))
|
||||
self.assertEqual((6 + 1) * 8, len(self.routing))
|
||||
|
||||
def test_default_args(self):
|
||||
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))
|
||||
LOG.info(res)
|
||||
|
||||
eq_(res[0], 6)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], 3)
|
||||
eq_(res[3], 0)
|
||||
eq_(res[4], (0 << 4) | 0)
|
||||
eq_(res[5], 0)
|
||||
self.assertEqual(res[0], 6)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[2], 3)
|
||||
self.assertEqual(res[3], 0)
|
||||
self.assertEqual(res[4], (0 << 4) | 0)
|
||||
self.assertEqual(res[5], 0)
|
||||
|
||||
|
||||
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_)
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.nxt, self.fragment.nxt)
|
||||
eq_(self.offset, self.fragment.offset)
|
||||
eq_(self.more, self.fragment.more)
|
||||
eq_(self.id_, self.fragment.id_)
|
||||
self.assertEqual(self.nxt, self.fragment.nxt)
|
||||
self.assertEqual(self.offset, self.fragment.offset)
|
||||
self.assertEqual(self.more, self.fragment.more)
|
||||
self.assertEqual(self.id_, self.fragment.id_)
|
||||
|
||||
def test_parser(self):
|
||||
_res = ipv6.fragment.parser(self.buf)
|
||||
@ -1037,29 +1034,29 @@ class Test_fragment(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.offset, res.offset)
|
||||
eq_(self.more, res.more)
|
||||
eq_(self.id_, res.id_)
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.offset, res.offset)
|
||||
self.assertEqual(self.more, res.more)
|
||||
self.assertEqual(self.id_, res.id_)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.fragment.serialize()
|
||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||
eq_(self.nxt, res[0])
|
||||
eq_(self.off_m, res[1])
|
||||
eq_(self.id_, res[2])
|
||||
self.assertEqual(self.nxt, res[0])
|
||||
self.assertEqual(self.off_m, res[1])
|
||||
self.assertEqual(self.id_, res[2])
|
||||
|
||||
def test_len(self):
|
||||
eq_(8, len(self.fragment))
|
||||
self.assertEqual(8, len(self.fragment))
|
||||
|
||||
def test_default_args(self):
|
||||
hdr = ipv6.fragment()
|
||||
buf = hdr.serialize()
|
||||
res = struct.unpack_from(ipv6.fragment._PACK_STR, buf)
|
||||
|
||||
eq_(res[0], 6)
|
||||
eq_(res[1], 0)
|
||||
eq_(res[2], 0)
|
||||
self.assertEqual(res[0], 6)
|
||||
self.assertEqual(res[1], 0)
|
||||
self.assertEqual(res[2], 0)
|
||||
|
||||
|
||||
class Test_auth(unittest.TestCase):
|
||||
@ -1077,11 +1074,11 @@ class Test_auth(unittest.TestCase):
|
||||
self.seq, self.data)
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.nxt, self.auth.nxt)
|
||||
eq_(self.size, self.auth.size)
|
||||
eq_(self.spi, self.auth.spi)
|
||||
eq_(self.seq, self.auth.seq)
|
||||
eq_(self.data, self.auth.data)
|
||||
self.assertEqual(self.nxt, self.auth.nxt)
|
||||
self.assertEqual(self.size, self.auth.size)
|
||||
self.assertEqual(self.spi, self.auth.spi)
|
||||
self.assertEqual(self.seq, self.auth.seq)
|
||||
self.assertEqual(self.data, self.auth.data)
|
||||
|
||||
def test_parser(self):
|
||||
_res = ipv6.auth.parser(self.buf)
|
||||
@ -1089,30 +1086,30 @@ class Test_auth(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(self.nxt, res.nxt)
|
||||
eq_(self.size, res.size)
|
||||
eq_(self.spi, res.spi)
|
||||
eq_(self.seq, res.seq)
|
||||
eq_(self.data, res.data)
|
||||
self.assertEqual(self.nxt, res.nxt)
|
||||
self.assertEqual(self.size, res.size)
|
||||
self.assertEqual(self.spi, res.spi)
|
||||
self.assertEqual(self.seq, res.seq)
|
||||
self.assertEqual(self.data, res.data)
|
||||
|
||||
def test_serialize(self):
|
||||
buf = self.auth.serialize()
|
||||
res = struct.unpack_from(self.form, six.binary_type(buf))
|
||||
eq_(self.nxt, res[0])
|
||||
eq_(self.size, res[1])
|
||||
eq_(self.spi, res[2])
|
||||
eq_(self.seq, res[3])
|
||||
eq_(self.data, res[4])
|
||||
self.assertEqual(self.nxt, res[0])
|
||||
self.assertEqual(self.size, res[1])
|
||||
self.assertEqual(self.spi, res[2])
|
||||
self.assertEqual(self.seq, res[3])
|
||||
self.assertEqual(self.data, res[4])
|
||||
|
||||
def test_len(self):
|
||||
eq_((4 + 2) * 4, len(self.auth))
|
||||
self.assertEqual((4 + 2) * 4, len(self.auth))
|
||||
|
||||
def test_len_re(self):
|
||||
size = 5
|
||||
auth = ipv6.auth(
|
||||
0, size, 256, 1,
|
||||
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):
|
||||
hdr = ipv6.auth()
|
||||
@ -1121,8 +1118,8 @@ class Test_auth(unittest.TestCase):
|
||||
res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf))
|
||||
LOG.info(res)
|
||||
|
||||
eq_(res[0], 6)
|
||||
eq_(res[1], 2)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], 0)
|
||||
eq_(buf[ipv6.auth._MIN_LEN:], b'\x00\x00\x00\x00')
|
||||
self.assertEqual(res[0], 6)
|
||||
self.assertEqual(res[1], 2)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], 0)
|
||||
self.assertEqual(buf[ipv6.auth._MIN_LEN:], b'\x00\x00\x00\x00')
|
||||
|
@ -18,7 +18,6 @@
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
from nose.tools import eq_
|
||||
from os_ken.lib.packet import llc
|
||||
|
||||
|
||||
@ -31,7 +30,7 @@ class Test_ControlFormatI(unittest.TestCase):
|
||||
def test_json(self):
|
||||
jsondict = self.msg.to_jsondict()
|
||||
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):
|
||||
|
@ -20,7 +20,6 @@ import logging
|
||||
import six
|
||||
import struct
|
||||
import inspect
|
||||
from nose.tools import ok_, eq_, nottest
|
||||
|
||||
from os_ken.ofproto import ether
|
||||
from os_ken.lib.packet import packet
|
||||
@ -48,42 +47,42 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
||||
|
||||
def test_get_tlv_type(self):
|
||||
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):
|
||||
buf = self.data[ethernet.ethernet._MIN_LEN:]
|
||||
(lldp_pkt, cls, rest_buf) = lldp.lldp.parser(buf)
|
||||
eq_(len(rest_buf), 0)
|
||||
self.assertEqual(len(rest_buf), 0)
|
||||
|
||||
tlvs = lldp_pkt.tlvs
|
||||
eq_(tlvs[0].tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||
eq_(tlvs[0].len, 7)
|
||||
eq_(tlvs[0].subtype, lldp.ChassisID.SUB_MAC_ADDRESS)
|
||||
eq_(tlvs[0].chassis_id, b'\x00\x04\x96\x1f\xa7\x26')
|
||||
eq_(tlvs[1].tlv_type, lldp.LLDP_TLV_PORT_ID)
|
||||
eq_(tlvs[1].len, 4)
|
||||
eq_(tlvs[1].subtype, lldp.PortID.SUB_INTERFACE_NAME)
|
||||
eq_(tlvs[1].port_id, b'1/3')
|
||||
eq_(tlvs[2].tlv_type, lldp.LLDP_TLV_TTL)
|
||||
eq_(tlvs[2].len, 2)
|
||||
eq_(tlvs[2].ttl, 120)
|
||||
eq_(tlvs[3].tlv_type, lldp.LLDP_TLV_END)
|
||||
self.assertEqual(tlvs[0].tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||
self.assertEqual(tlvs[0].len, 7)
|
||||
self.assertEqual(tlvs[0].subtype, lldp.ChassisID.SUB_MAC_ADDRESS)
|
||||
self.assertEqual(tlvs[0].chassis_id, b'\x00\x04\x96\x1f\xa7\x26')
|
||||
self.assertEqual(tlvs[1].tlv_type, lldp.LLDP_TLV_PORT_ID)
|
||||
self.assertEqual(tlvs[1].len, 4)
|
||||
self.assertEqual(tlvs[1].subtype, lldp.PortID.SUB_INTERFACE_NAME)
|
||||
self.assertEqual(tlvs[1].port_id, b'1/3')
|
||||
self.assertEqual(tlvs[2].tlv_type, lldp.LLDP_TLV_TTL)
|
||||
self.assertEqual(tlvs[2].len, 2)
|
||||
self.assertEqual(tlvs[2].ttl, 120)
|
||||
self.assertEqual(tlvs[3].tlv_type, lldp.LLDP_TLV_END)
|
||||
|
||||
def test_parse(self):
|
||||
buf = self.data
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
eq_(type(next(i)), lldp.lldp)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), lldp.lldp)
|
||||
|
||||
def test_tlv(self):
|
||||
tlv = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||
chassis_id=b'\x00\x04\x96\x1f\xa7\x26')
|
||||
eq_(tlv.tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||
eq_(tlv.len, 7)
|
||||
self.assertEqual(tlv.tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
|
||||
self.assertEqual(tlv.len, 7)
|
||||
(typelen, ) = struct.unpack('!H', b'\x02\x07')
|
||||
eq_(tlv.typelen, typelen)
|
||||
self.assertEqual(tlv.typelen, typelen)
|
||||
|
||||
def test_serialize_without_ethernet(self):
|
||||
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)
|
||||
lldp_pkt = lldp.lldp(tlvs)
|
||||
|
||||
eq_(lldp_pkt.serialize(None, None),
|
||||
self.assertEqual(lldp_pkt.serialize(None, None),
|
||||
self.data[ethernet.ethernet._MIN_LEN:])
|
||||
|
||||
def test_serialize(self):
|
||||
@ -118,7 +117,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
||||
lldp_pkt = lldp.lldp(tlvs)
|
||||
pkt.add_protocol(lldp_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 2)
|
||||
self.assertEqual(len(pkt.protocols), 2)
|
||||
|
||||
pkt.serialize()
|
||||
|
||||
@ -128,9 +127,9 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
||||
data_len = len(self.data)
|
||||
pkt_data_lldp = 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):
|
||||
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__,
|
||||
tlvs_str)
|
||||
|
||||
eq_(str(lldp_pkt), lldp_str)
|
||||
eq_(repr(lldp_pkt), lldp_str)
|
||||
self.assertEqual(str(lldp_pkt), lldp_str)
|
||||
self.assertEqual(repr(lldp_pkt), lldp_str)
|
||||
|
||||
def test_json(self):
|
||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||
@ -199,7 +198,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
|
||||
lldp1 = lldp.lldp(tlvs)
|
||||
jsondict = lldp1.to_jsondict()
|
||||
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
|
||||
eq_(str(lldp1), str(lldp2))
|
||||
self.assertEqual(str(lldp1), str(lldp2))
|
||||
|
||||
|
||||
class TestLLDPOptionalTLV(unittest.TestCase):
|
||||
@ -250,49 +249,49 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
||||
pkt = packet.Packet(buf)
|
||||
i = iter(pkt)
|
||||
|
||||
eq_(type(next(i)), ethernet.ethernet)
|
||||
self.assertEqual(type(next(i)), ethernet.ethernet)
|
||||
lldp_pkt = next(i)
|
||||
eq_(type(lldp_pkt), lldp.lldp)
|
||||
self.assertEqual(type(lldp_pkt), lldp.lldp)
|
||||
|
||||
tlvs = lldp_pkt.tlvs
|
||||
|
||||
# Port Description
|
||||
eq_(tlvs[3].tlv_type, lldp.LLDP_TLV_PORT_DESCRIPTION)
|
||||
eq_(tlvs[3].port_description, b'Summit300-48-Port 1001\x00')
|
||||
self.assertEqual(tlvs[3].tlv_type, lldp.LLDP_TLV_PORT_DESCRIPTION)
|
||||
self.assertEqual(tlvs[3].port_description, b'Summit300-48-Port 1001\x00')
|
||||
|
||||
# System Name
|
||||
eq_(tlvs[4].tlv_type, lldp.LLDP_TLV_SYSTEM_NAME)
|
||||
eq_(tlvs[4].system_name, b'Summit300-48\x00')
|
||||
self.assertEqual(tlvs[4].tlv_type, lldp.LLDP_TLV_SYSTEM_NAME)
|
||||
self.assertEqual(tlvs[4].system_name, b'Summit300-48\x00')
|
||||
|
||||
# System Description
|
||||
|
||||
eq_(tlvs[5].tlv_type, lldp.LLDP_TLV_SYSTEM_DESCRIPTION)
|
||||
eq_(tlvs[5].system_description,
|
||||
self.assertEqual(tlvs[5].tlv_type, lldp.LLDP_TLV_SYSTEM_DESCRIPTION)
|
||||
self.assertEqual(tlvs[5].system_description,
|
||||
b'Summit300-48 - Version 7.4e.1 (Build 5) '
|
||||
+ b'by Release_Master 05/27/05 04:53:11\x00')
|
||||
|
||||
# SystemCapabilities
|
||||
eq_(tlvs[6].tlv_type, lldp.LLDP_TLV_SYSTEM_CAPABILITIES)
|
||||
eq_(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_MAC_BRIDGE,
|
||||
self.assertEqual(tlvs[6].tlv_type, lldp.LLDP_TLV_SYSTEM_CAPABILITIES)
|
||||
self.assertEqual(tlvs[6].system_cap & 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)
|
||||
eq_(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||
eq_(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||
self.assertEqual(tlvs[6].system_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||
self.assertEqual(tlvs[6].enabled_cap & lldp.SystemCapabilities.CAP_TELEPHONE, 0)
|
||||
|
||||
# Management Address
|
||||
eq_(tlvs[7].tlv_type, lldp.LLDP_TLV_MANAGEMENT_ADDRESS)
|
||||
eq_(tlvs[7].addr_len, 7)
|
||||
eq_(tlvs[7].addr, b'\x00\x01\x30\xf9\xad\xa0')
|
||||
eq_(tlvs[7].intf_num, 1001)
|
||||
self.assertEqual(tlvs[7].tlv_type, lldp.LLDP_TLV_MANAGEMENT_ADDRESS)
|
||||
self.assertEqual(tlvs[7].addr_len, 7)
|
||||
self.assertEqual(tlvs[7].addr, b'\x00\x01\x30\xf9\xad\xa0')
|
||||
self.assertEqual(tlvs[7].intf_num, 1001)
|
||||
|
||||
# Organizationally Specific
|
||||
eq_(tlvs[8].tlv_type, lldp.LLDP_TLV_ORGANIZATIONALLY_SPECIFIC)
|
||||
eq_(tlvs[8].oui, b'\x00\x12\x0f') # IEEE 802.3
|
||||
eq_(tlvs[8].subtype, 0x02) # Power Via MDI
|
||||
self.assertEqual(tlvs[8].tlv_type, lldp.LLDP_TLV_ORGANIZATIONALLY_SPECIFIC)
|
||||
self.assertEqual(tlvs[8].oui, b'\x00\x12\x0f') # IEEE 802.3
|
||||
self.assertEqual(tlvs[8].subtype, 0x02) # Power Via MDI
|
||||
|
||||
# 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):
|
||||
buf = self.data
|
||||
@ -336,13 +335,13 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
||||
lldp_pkt = lldp.lldp(tlvs)
|
||||
pkt.add_protocol(lldp_pkt)
|
||||
|
||||
eq_(len(pkt.protocols), 2)
|
||||
self.assertEqual(len(pkt.protocols), 2)
|
||||
|
||||
pkt.serialize()
|
||||
|
||||
# self.data has many organizationally specific TLVs
|
||||
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):
|
||||
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__,
|
||||
tlvs_str)
|
||||
|
||||
eq_(str(lldp_pkt), lldp_str)
|
||||
eq_(repr(lldp_pkt), lldp_str)
|
||||
self.assertEqual(str(lldp_pkt), lldp_str)
|
||||
self.assertEqual(repr(lldp_pkt), lldp_str)
|
||||
|
||||
def test_json(self):
|
||||
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
|
||||
@ -524,4 +523,4 @@ class TestLLDPOptionalTLV(unittest.TestCase):
|
||||
lldp1 = lldp.lldp(tlvs)
|
||||
jsondict = lldp1.to_jsondict()
|
||||
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 inspect
|
||||
|
||||
from nose.tools import eq_
|
||||
from os_ken.lib.packet import mpls
|
||||
|
||||
|
||||
@ -49,13 +48,13 @@ class Test_mpls(unittest.TestCase):
|
||||
if k in mpls_values])
|
||||
mpls_str = '%s(%s)' % (mpls.mpls.__name__, _mpls_str)
|
||||
|
||||
eq_(str(self.mp), mpls_str)
|
||||
eq_(repr(self.mp), mpls_str)
|
||||
self.assertEqual(str(self.mp), mpls_str)
|
||||
self.assertEqual(repr(self.mp), mpls_str)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.mp.to_jsondict()
|
||||
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):
|
||||
mpls_label = 0xfffff
|
||||
@ -63,8 +62,8 @@ class Test_mpls(unittest.TestCase):
|
||||
buf = b'\xff\xff\xf1'
|
||||
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
||||
|
||||
eq_(mpls_label, mpls_label_out)
|
||||
eq_(is_bos, is_bos_out)
|
||||
self.assertEqual(mpls_label, mpls_label_out)
|
||||
self.assertEqual(is_bos, is_bos_out)
|
||||
|
||||
def test_label_from_bin_false(self):
|
||||
mpls_label = 0xfffff
|
||||
@ -72,8 +71,8 @@ class Test_mpls(unittest.TestCase):
|
||||
buf = b'\xff\xff\xf0'
|
||||
mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
|
||||
|
||||
eq_(mpls_label, mpls_label_out)
|
||||
eq_(is_bos, is_bos_out)
|
||||
self.assertEqual(mpls_label, mpls_label_out)
|
||||
self.assertEqual(is_bos, is_bos_out)
|
||||
|
||||
def test_label_to_bin_true(self):
|
||||
mpls_label = 0xfffff
|
||||
@ -81,7 +80,7 @@ class Test_mpls(unittest.TestCase):
|
||||
label = b'\xff\xff\xf1'
|
||||
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):
|
||||
mpls_label = 0xfffff
|
||||
@ -89,4 +88,4 @@ class Test_mpls(unittest.TestCase):
|
||||
label = b'\xff\xff\xf0'
|
||||
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 unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.lib import pcaplib
|
||||
from os_ken.lib.packet import openflow
|
||||
@ -53,10 +51,10 @@ class Test_openflow(unittest.TestCase):
|
||||
# Checks if message can be parsed as expected.
|
||||
pkt = packet.Packet(buf)
|
||||
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)
|
||||
|
||||
# Checks if message can be serialized as expected.
|
||||
pkt.serialize()
|
||||
eq_(buf, pkt.data,
|
||||
self.assertEqual(buf, pkt.data,
|
||||
"b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data)))
|
||||
|
@ -14,8 +14,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
|
||||
from os_ken.lib.packet import ospf
|
||||
|
||||
@ -37,18 +35,18 @@ class Test_ospf(unittest.TestCase):
|
||||
links=[link1])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||
eq_(msg.header.checksum, msg2.header.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_network_lsa(self):
|
||||
msg = ospf.NetworkLSA(id_='192.168.0.1', adv_router='192.168.0.2',
|
||||
mask='255.255.255.0', routers=['192.168.0.2'])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||
eq_(msg.header.checksum, msg2.header.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_as_external_lsa(self):
|
||||
extnw1 = ospf.ASExternalLSA.ExternalNetwork(mask='255.255.255.0',
|
||||
@ -58,18 +56,18 @@ class Test_ospf(unittest.TestCase):
|
||||
extnws=[extnw1])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.LSA.parser(binmsg)
|
||||
eq_(msg.header.checksum, msg2.header.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.header.checksum, msg2.header.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_hello(self):
|
||||
msg = ospf.OSPFHello(router_id='192.168.0.1',
|
||||
neighbors=['192.168.0.2'])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||
eq_(msg.checksum, msg2.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.checksum, msg2.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_dbdesc(self):
|
||||
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])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||
eq_(msg.checksum, msg2.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.checksum, msg2.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_lsreq(self):
|
||||
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])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||
eq_(msg.checksum, msg2.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.checksum, msg2.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_lsupd(self):
|
||||
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])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||
eq_(msg.checksum, msg2.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.checksum, msg2.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
||||
def test_lsack(self):
|
||||
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])
|
||||
binmsg = msg.serialize()
|
||||
msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
|
||||
eq_(msg.checksum, msg2.checksum)
|
||||
eq_(str(msg), str(msg2))
|
||||
eq_(rest, b'')
|
||||
self.assertEqual(msg.checksum, msg2.checksum)
|
||||
self.assertEqual(str(msg), str(msg2))
|
||||
self.assertEqual(rest, b'')
|
||||
|
@ -19,7 +19,6 @@ import unittest
|
||||
import logging
|
||||
import struct
|
||||
import inspect
|
||||
from nose.tools import ok_, eq_
|
||||
import six
|
||||
from os_ken.ofproto import ether, inet
|
||||
from os_ken.lib.packet import arp
|
||||
@ -106,7 +105,7 @@ class TestPacket(unittest.TestCase):
|
||||
pad_len = 60 - len(buf)
|
||||
if pad_len > 0:
|
||||
buf += b'\x00' * pad_len
|
||||
eq_(buf, p.data)
|
||||
self.assertEqual(buf, p.data)
|
||||
|
||||
# parse
|
||||
pkt = packet.Packet(p.data)
|
||||
@ -115,22 +114,22 @@ class TestPacket(unittest.TestCase):
|
||||
p_arp = protocols['arp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_(self.dst_mac, p_eth.dst)
|
||||
eq_(self.src_mac, p_eth.src)
|
||||
eq_(ether.ETH_TYPE_ARP, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||
self.assertEqual(self.src_mac, p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_ARP, p_eth.ethertype)
|
||||
|
||||
# arp
|
||||
ok_(p_arp)
|
||||
eq_(1, p_arp.hwtype)
|
||||
eq_(ether.ETH_TYPE_IP, p_arp.proto)
|
||||
eq_(6, p_arp.hlen)
|
||||
eq_(4, p_arp.plen)
|
||||
eq_(2, p_arp.opcode)
|
||||
eq_(self.src_mac, p_arp.src_mac)
|
||||
eq_(self.src_ip, p_arp.src_ip)
|
||||
eq_(self.dst_mac, p_arp.dst_mac)
|
||||
eq_(self.dst_ip, p_arp.dst_ip)
|
||||
self.assertTrue(p_arp)
|
||||
self.assertEqual(1, p_arp.hwtype)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_arp.proto)
|
||||
self.assertEqual(6, p_arp.hlen)
|
||||
self.assertEqual(4, p_arp.plen)
|
||||
self.assertEqual(2, p_arp.opcode)
|
||||
self.assertEqual(self.src_mac, p_arp.src_mac)
|
||||
self.assertEqual(self.src_ip, p_arp.src_ip)
|
||||
self.assertEqual(self.dst_mac, p_arp.dst_mac)
|
||||
self.assertEqual(self.dst_ip, p_arp.dst_ip)
|
||||
|
||||
# to string
|
||||
eth_values = {'dst': self.dst_mac,
|
||||
@ -157,14 +156,14 @@ class TestPacket(unittest.TestCase):
|
||||
|
||||
pkt_str = '%s, %s' % (eth_str, arp_str)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(arp_str, str(p_arp))
|
||||
eq_(arp_str, repr(p_arp))
|
||||
self.assertEqual(arp_str, str(p_arp))
|
||||
self.assertEqual(arp_str, repr(p_arp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_vlan_arp(self):
|
||||
# buid packet
|
||||
@ -206,7 +205,7 @@ class TestPacket(unittest.TestCase):
|
||||
pad_len = 60 - len(buf)
|
||||
if pad_len > 0:
|
||||
buf += b'\x00' * pad_len
|
||||
eq_(buf, p.data)
|
||||
self.assertEqual(buf, p.data)
|
||||
|
||||
# parse
|
||||
pkt = packet.Packet(p.data)
|
||||
@ -216,29 +215,29 @@ class TestPacket(unittest.TestCase):
|
||||
p_arp = protocols['arp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_(self.dst_mac, p_eth.dst)
|
||||
eq_(self.src_mac, p_eth.src)
|
||||
eq_(ether.ETH_TYPE_8021Q, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||
self.assertEqual(self.src_mac, p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_8021Q, p_eth.ethertype)
|
||||
|
||||
# vlan
|
||||
ok_(p_vlan)
|
||||
eq_(0b111, p_vlan.pcp)
|
||||
eq_(0b1, p_vlan.cfi)
|
||||
eq_(3, p_vlan.vid)
|
||||
eq_(ether.ETH_TYPE_ARP, p_vlan.ethertype)
|
||||
self.assertTrue(p_vlan)
|
||||
self.assertEqual(0b111, p_vlan.pcp)
|
||||
self.assertEqual(0b1, p_vlan.cfi)
|
||||
self.assertEqual(3, p_vlan.vid)
|
||||
self.assertEqual(ether.ETH_TYPE_ARP, p_vlan.ethertype)
|
||||
|
||||
# arp
|
||||
ok_(p_arp)
|
||||
eq_(1, p_arp.hwtype)
|
||||
eq_(ether.ETH_TYPE_IP, p_arp.proto)
|
||||
eq_(6, p_arp.hlen)
|
||||
eq_(4, p_arp.plen)
|
||||
eq_(2, p_arp.opcode)
|
||||
eq_(self.src_mac, p_arp.src_mac)
|
||||
eq_(self.src_ip, p_arp.src_ip)
|
||||
eq_(self.dst_mac, p_arp.dst_mac)
|
||||
eq_(self.dst_ip, p_arp.dst_ip)
|
||||
self.assertTrue(p_arp)
|
||||
self.assertEqual(1, p_arp.hwtype)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_arp.proto)
|
||||
self.assertEqual(6, p_arp.hlen)
|
||||
self.assertEqual(4, p_arp.plen)
|
||||
self.assertEqual(2, p_arp.opcode)
|
||||
self.assertEqual(self.src_mac, p_arp.src_mac)
|
||||
self.assertEqual(self.src_ip, p_arp.src_ip)
|
||||
self.assertEqual(self.dst_mac, p_arp.dst_mac)
|
||||
self.assertEqual(self.dst_ip, p_arp.dst_ip)
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(vlan_str, str(p_vlan))
|
||||
eq_(vlan_str, repr(p_vlan))
|
||||
self.assertEqual(vlan_str, str(p_vlan))
|
||||
self.assertEqual(vlan_str, repr(p_vlan))
|
||||
|
||||
eq_(arp_str, str(p_arp))
|
||||
eq_(arp_str, repr(p_arp))
|
||||
self.assertEqual(arp_str, str(p_arp))
|
||||
self.assertEqual(arp_str, repr(p_arp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv4_udp(self):
|
||||
# buid packet
|
||||
@ -334,44 +333,44 @@ class TestPacket(unittest.TestCase):
|
||||
p_udp = protocols['udp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_(self.dst_mac, p_eth.dst)
|
||||
eq_(self.src_mac, p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||
self.assertEqual(self.src_mac, p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
|
||||
# ipv4
|
||||
ok_(p_ipv4)
|
||||
eq_(4, p_ipv4.version)
|
||||
eq_(5, p_ipv4.header_length)
|
||||
eq_(1, p_ipv4.tos)
|
||||
self.assertTrue(p_ipv4)
|
||||
self.assertEqual(4, p_ipv4.version)
|
||||
self.assertEqual(5, p_ipv4.header_length)
|
||||
self.assertEqual(1, p_ipv4.tos)
|
||||
l = len(ip_buf) + len(u_buf) + len(self.payload)
|
||||
eq_(l, p_ipv4.total_length)
|
||||
eq_(3, p_ipv4.identification)
|
||||
eq_(1, p_ipv4.flags)
|
||||
eq_(64, p_ipv4.ttl)
|
||||
eq_(inet.IPPROTO_UDP, p_ipv4.proto)
|
||||
eq_(self.src_ip, p_ipv4.src)
|
||||
eq_(self.dst_ip, p_ipv4.dst)
|
||||
self.assertEqual(l, p_ipv4.total_length)
|
||||
self.assertEqual(3, p_ipv4.identification)
|
||||
self.assertEqual(1, p_ipv4.flags)
|
||||
self.assertEqual(64, p_ipv4.ttl)
|
||||
self.assertEqual(inet.IPPROTO_UDP, p_ipv4.proto)
|
||||
self.assertEqual(self.src_ip, p_ipv4.src)
|
||||
self.assertEqual(self.dst_ip, p_ipv4.dst)
|
||||
t = bytearray(ip_buf)
|
||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||
eq_(packet_utils.checksum(t), 0)
|
||||
self.assertEqual(packet_utils.checksum(t), 0)
|
||||
|
||||
# udp
|
||||
ok_(p_udp)
|
||||
eq_(0x190f, p_udp.src_port)
|
||||
eq_(0x1F90, p_udp.dst_port)
|
||||
eq_(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||
eq_(0x77b2, p_udp.csum)
|
||||
self.assertTrue(p_udp)
|
||||
self.assertEqual(0x190f, p_udp.src_port)
|
||||
self.assertEqual(0x1F90, p_udp.dst_port)
|
||||
self.assertEqual(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||
self.assertEqual(0x77b2, p_udp.csum)
|
||||
t = bytearray(u_buf)
|
||||
struct.pack_into('!H', t, 6, p_udp.csum)
|
||||
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
||||
17, len(u_buf) + len(self.payload))
|
||||
t = ph + t + self.payload
|
||||
eq_(packet_utils.checksum(t), 0)
|
||||
self.assertEqual(packet_utils.checksum(t), 0)
|
||||
|
||||
# payload
|
||||
ok_('payload' in protocols)
|
||||
eq_(self.payload, protocols['payload'])
|
||||
self.assertTrue('payload' in protocols)
|
||||
self.assertEqual(self.payload, protocols['payload'])
|
||||
|
||||
# to string
|
||||
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,
|
||||
repr(protocols['payload']))
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv4_str, str(p_ipv4))
|
||||
eq_(ipv4_str, repr(p_ipv4))
|
||||
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||
|
||||
eq_(udp_str, str(p_udp))
|
||||
eq_(udp_str, repr(p_udp))
|
||||
self.assertEqual(udp_str, str(p_udp))
|
||||
self.assertEqual(udp_str, repr(p_udp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv4_tcp(self):
|
||||
# buid packet
|
||||
@ -479,49 +478,49 @@ class TestPacket(unittest.TestCase):
|
||||
p_tcp = protocols['tcp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_(self.dst_mac, p_eth.dst)
|
||||
eq_(self.src_mac, p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||
self.assertEqual(self.src_mac, p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
|
||||
# ipv4
|
||||
ok_(p_ipv4)
|
||||
eq_(4, p_ipv4.version)
|
||||
eq_(5, p_ipv4.header_length)
|
||||
eq_(0, p_ipv4.tos)
|
||||
self.assertTrue(p_ipv4)
|
||||
self.assertEqual(4, p_ipv4.version)
|
||||
self.assertEqual(5, p_ipv4.header_length)
|
||||
self.assertEqual(0, p_ipv4.tos)
|
||||
l = len(ip_buf) + len(t_buf) + len(self.payload)
|
||||
eq_(l, p_ipv4.total_length)
|
||||
eq_(0, p_ipv4.identification)
|
||||
eq_(0, p_ipv4.flags)
|
||||
eq_(64, p_ipv4.ttl)
|
||||
eq_(inet.IPPROTO_TCP, p_ipv4.proto)
|
||||
eq_(self.src_ip, p_ipv4.src)
|
||||
eq_(self.dst_ip, p_ipv4.dst)
|
||||
self.assertEqual(l, p_ipv4.total_length)
|
||||
self.assertEqual(0, p_ipv4.identification)
|
||||
self.assertEqual(0, p_ipv4.flags)
|
||||
self.assertEqual(64, p_ipv4.ttl)
|
||||
self.assertEqual(inet.IPPROTO_TCP, p_ipv4.proto)
|
||||
self.assertEqual(self.src_ip, p_ipv4.src)
|
||||
self.assertEqual(self.dst_ip, p_ipv4.dst)
|
||||
t = bytearray(ip_buf)
|
||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||
eq_(packet_utils.checksum(t), 0)
|
||||
self.assertEqual(packet_utils.checksum(t), 0)
|
||||
|
||||
# tcp
|
||||
ok_(p_tcp)
|
||||
eq_(0x190f, p_tcp.src_port)
|
||||
eq_(0x1F90, p_tcp.dst_port)
|
||||
eq_(0x123, p_tcp.seq)
|
||||
eq_(1, p_tcp.ack)
|
||||
eq_(6, p_tcp.offset)
|
||||
eq_(0b101010, p_tcp.bits)
|
||||
eq_(2048, p_tcp.window_size)
|
||||
eq_(0x6f, p_tcp.urgent)
|
||||
eq_(len(t_buf), len(p_tcp))
|
||||
self.assertTrue(p_tcp)
|
||||
self.assertEqual(0x190f, p_tcp.src_port)
|
||||
self.assertEqual(0x1F90, p_tcp.dst_port)
|
||||
self.assertEqual(0x123, p_tcp.seq)
|
||||
self.assertEqual(1, p_tcp.ack)
|
||||
self.assertEqual(6, p_tcp.offset)
|
||||
self.assertEqual(0b101010, p_tcp.bits)
|
||||
self.assertEqual(2048, p_tcp.window_size)
|
||||
self.assertEqual(0x6f, p_tcp.urgent)
|
||||
self.assertEqual(len(t_buf), len(p_tcp))
|
||||
t = bytearray(t_buf)
|
||||
struct.pack_into('!H', t, 16, p_tcp.csum)
|
||||
ph = struct.pack('!4s4sBBH', self.src_ip_bin, self.dst_ip_bin, 0,
|
||||
6, len(t_buf) + len(self.payload))
|
||||
t = ph + t + self.payload
|
||||
eq_(packet_utils.checksum(t), 0)
|
||||
self.assertEqual(packet_utils.checksum(t), 0)
|
||||
|
||||
# payload
|
||||
ok_('payload' in protocols)
|
||||
eq_(self.payload, protocols['payload'])
|
||||
self.assertTrue('payload' in protocols)
|
||||
self.assertEqual(self.payload, protocols['payload'])
|
||||
|
||||
# to string
|
||||
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,
|
||||
repr(protocols['payload']))
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv4_str, str(p_ipv4))
|
||||
eq_(ipv4_str, repr(p_ipv4))
|
||||
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||
|
||||
eq_(tcp_str, str(p_tcp))
|
||||
eq_(tcp_str, repr(p_tcp))
|
||||
self.assertEqual(tcp_str, str(p_tcp))
|
||||
self.assertEqual(tcp_str, repr(p_tcp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv4_sctp(self):
|
||||
# build packet
|
||||
@ -632,45 +631,45 @@ class TestPacket(unittest.TestCase):
|
||||
p_sctp = protocols['sctp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
|
||||
# ipv4
|
||||
ok_(p_ipv4)
|
||||
eq_(4, p_ipv4.version)
|
||||
eq_(5, p_ipv4.header_length)
|
||||
eq_(0, p_ipv4.tos)
|
||||
self.assertTrue(p_ipv4)
|
||||
self.assertEqual(4, p_ipv4.version)
|
||||
self.assertEqual(5, p_ipv4.header_length)
|
||||
self.assertEqual(0, p_ipv4.tos)
|
||||
l = len(ip_buf) + len(s_buf)
|
||||
eq_(l, p_ipv4.total_length)
|
||||
eq_(0, p_ipv4.identification)
|
||||
eq_(0, p_ipv4.flags)
|
||||
eq_(255, p_ipv4.ttl)
|
||||
eq_(inet.IPPROTO_SCTP, p_ipv4.proto)
|
||||
eq_('10.0.0.1', p_ipv4.src)
|
||||
eq_('10.0.0.2', p_ipv4.dst)
|
||||
self.assertEqual(l, p_ipv4.total_length)
|
||||
self.assertEqual(0, p_ipv4.identification)
|
||||
self.assertEqual(0, p_ipv4.flags)
|
||||
self.assertEqual(255, p_ipv4.ttl)
|
||||
self.assertEqual(inet.IPPROTO_SCTP, p_ipv4.proto)
|
||||
self.assertEqual('10.0.0.1', p_ipv4.src)
|
||||
self.assertEqual('10.0.0.2', p_ipv4.dst)
|
||||
t = bytearray(ip_buf)
|
||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||
eq_(packet_utils.checksum(t), 0x1403)
|
||||
self.assertEqual(packet_utils.checksum(t), 0x1403)
|
||||
|
||||
# sctp
|
||||
ok_(p_sctp)
|
||||
eq_(1, p_sctp.src_port)
|
||||
eq_(1, p_sctp.dst_port)
|
||||
eq_(0, p_sctp.vtag)
|
||||
self.assertTrue(p_sctp)
|
||||
self.assertEqual(1, p_sctp.src_port)
|
||||
self.assertEqual(1, p_sctp.dst_port)
|
||||
self.assertEqual(0, p_sctp.vtag)
|
||||
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
||||
eq_(0, p_sctp.chunks[0]._type)
|
||||
eq_(0, p_sctp.chunks[0].unordered)
|
||||
eq_(0, p_sctp.chunks[0].begin)
|
||||
eq_(0, p_sctp.chunks[0].end)
|
||||
eq_(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||
eq_(0, p_sctp.chunks[0].tsn)
|
||||
eq_(0, p_sctp.chunks[0].sid)
|
||||
eq_(0, p_sctp.chunks[0].seq)
|
||||
eq_(0, p_sctp.chunks[0].payload_id)
|
||||
eq_(self.payload, p_sctp.chunks[0].payload_data)
|
||||
eq_(len(s_buf), len(p_sctp))
|
||||
self.assertEqual(0, p_sctp.chunks[0]._type)
|
||||
self.assertEqual(0, p_sctp.chunks[0].unordered)
|
||||
self.assertEqual(0, p_sctp.chunks[0].begin)
|
||||
self.assertEqual(0, p_sctp.chunks[0].end)
|
||||
self.assertEqual(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||
self.assertEqual(0, p_sctp.chunks[0].tsn)
|
||||
self.assertEqual(0, p_sctp.chunks[0].sid)
|
||||
self.assertEqual(0, p_sctp.chunks[0].seq)
|
||||
self.assertEqual(0, p_sctp.chunks[0].payload_id)
|
||||
self.assertEqual(self.payload, p_sctp.chunks[0].payload_data)
|
||||
self.assertEqual(len(s_buf), len(p_sctp))
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv4_str, str(p_ipv4))
|
||||
eq_(ipv4_str, repr(p_ipv4))
|
||||
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||
|
||||
eq_(sctp_str, str(p_sctp))
|
||||
eq_(sctp_str, repr(p_sctp))
|
||||
self.assertEqual(sctp_str, str(p_sctp))
|
||||
self.assertEqual(sctp_str, repr(p_sctp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv4_icmp(self):
|
||||
# buid packet
|
||||
@ -781,38 +780,38 @@ class TestPacket(unittest.TestCase):
|
||||
p_icmp = protocols['icmp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IP, p_eth.ethertype)
|
||||
|
||||
# ipv4
|
||||
ok_(p_ipv4)
|
||||
eq_(4, p_ipv4.version)
|
||||
eq_(5, p_ipv4.header_length)
|
||||
eq_(0, p_ipv4.tos)
|
||||
self.assertTrue(p_ipv4)
|
||||
self.assertEqual(4, p_ipv4.version)
|
||||
self.assertEqual(5, p_ipv4.header_length)
|
||||
self.assertEqual(0, p_ipv4.tos)
|
||||
l = len(ip_buf) + len(ic_buf)
|
||||
eq_(l, p_ipv4.total_length)
|
||||
eq_(0, p_ipv4.identification)
|
||||
eq_(0, p_ipv4.flags)
|
||||
eq_(255, p_ipv4.ttl)
|
||||
eq_(inet.IPPROTO_ICMP, p_ipv4.proto)
|
||||
eq_('10.0.0.1', p_ipv4.src)
|
||||
eq_('10.0.0.2', p_ipv4.dst)
|
||||
self.assertEqual(l, p_ipv4.total_length)
|
||||
self.assertEqual(0, p_ipv4.identification)
|
||||
self.assertEqual(0, p_ipv4.flags)
|
||||
self.assertEqual(255, p_ipv4.ttl)
|
||||
self.assertEqual(inet.IPPROTO_ICMP, p_ipv4.proto)
|
||||
self.assertEqual('10.0.0.1', p_ipv4.src)
|
||||
self.assertEqual('10.0.0.2', p_ipv4.dst)
|
||||
t = bytearray(ip_buf)
|
||||
struct.pack_into('!H', t, 10, p_ipv4.csum)
|
||||
eq_(packet_utils.checksum(t), 0x1403)
|
||||
self.assertEqual(packet_utils.checksum(t), 0x1403)
|
||||
|
||||
# icmp
|
||||
ok_(p_icmp)
|
||||
eq_(8, p_icmp.type)
|
||||
eq_(0, p_icmp.code)
|
||||
eq_(0, p_icmp.data.id)
|
||||
eq_(0, p_icmp.data.seq)
|
||||
eq_(len(ic_buf), len(p_icmp))
|
||||
self.assertTrue(p_icmp)
|
||||
self.assertEqual(8, p_icmp.type)
|
||||
self.assertEqual(0, p_icmp.code)
|
||||
self.assertEqual(0, p_icmp.data.id)
|
||||
self.assertEqual(0, p_icmp.data.seq)
|
||||
self.assertEqual(len(ic_buf), len(p_icmp))
|
||||
t = bytearray(ic_buf)
|
||||
struct.pack_into('!H', t, 2, p_icmp.csum)
|
||||
eq_(packet_utils.checksum(t), 0)
|
||||
self.assertEqual(packet_utils.checksum(t), 0)
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv4_str, str(p_ipv4))
|
||||
eq_(ipv4_str, repr(p_ipv4))
|
||||
self.assertEqual(ipv4_str, str(p_ipv4))
|
||||
self.assertEqual(ipv4_str, repr(p_ipv4))
|
||||
|
||||
eq_(icmp_str, str(p_icmp))
|
||||
eq_(icmp_str, repr(p_icmp))
|
||||
self.assertEqual(icmp_str, str(p_icmp))
|
||||
self.assertEqual(icmp_str, repr(p_icmp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv6_udp(self):
|
||||
# build packet
|
||||
@ -911,38 +910,38 @@ class TestPacket(unittest.TestCase):
|
||||
p_udp = protocols['udp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
|
||||
# ipv6
|
||||
ok_(p_ipv6)
|
||||
eq_(6, p_ipv6.version)
|
||||
eq_(0, p_ipv6.traffic_class)
|
||||
eq_(0, p_ipv6.flow_label)
|
||||
eq_(len(u_buf) + len(self.payload), p_ipv6.payload_length)
|
||||
eq_(inet.IPPROTO_UDP, p_ipv6.nxt)
|
||||
eq_(255, p_ipv6.hop_limit)
|
||||
eq_('10::10', p_ipv6.src)
|
||||
eq_('20::20', p_ipv6.dst)
|
||||
self.assertTrue(p_ipv6)
|
||||
self.assertEqual(6, p_ipv6.version)
|
||||
self.assertEqual(0, p_ipv6.traffic_class)
|
||||
self.assertEqual(0, p_ipv6.flow_label)
|
||||
self.assertEqual(len(u_buf) + len(self.payload), p_ipv6.payload_length)
|
||||
self.assertEqual(inet.IPPROTO_UDP, p_ipv6.nxt)
|
||||
self.assertEqual(255, p_ipv6.hop_limit)
|
||||
self.assertEqual('10::10', p_ipv6.src)
|
||||
self.assertEqual('20::20', p_ipv6.dst)
|
||||
|
||||
# udp
|
||||
ok_(p_udp)
|
||||
eq_(1, p_udp.src_port)
|
||||
eq_(1, p_udp.dst_port)
|
||||
eq_(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||
eq_(0x2B60, p_udp.csum)
|
||||
self.assertTrue(p_udp)
|
||||
self.assertEqual(1, p_udp.src_port)
|
||||
self.assertEqual(1, p_udp.dst_port)
|
||||
self.assertEqual(len(u_buf) + len(self.payload), p_udp.total_length)
|
||||
self.assertEqual(0x2B60, p_udp.csum)
|
||||
t = bytearray(u_buf)
|
||||
struct.pack_into('!H', t, 6, p_udp.csum)
|
||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
||||
len(u_buf) + len(self.payload), 17)
|
||||
t = ph + t + self.payload
|
||||
eq_(packet_utils.checksum(t), 0x62)
|
||||
self.assertEqual(packet_utils.checksum(t), 0x62)
|
||||
|
||||
# payload
|
||||
ok_('payload' in protocols)
|
||||
eq_(self.payload, protocols['payload'])
|
||||
self.assertTrue('payload' in protocols)
|
||||
self.assertEqual(self.payload, protocols['payload'])
|
||||
|
||||
# to string
|
||||
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,
|
||||
repr(protocols['payload']))
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv6_str, str(p_ipv6))
|
||||
eq_(ipv6_str, repr(p_ipv6))
|
||||
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||
|
||||
eq_(udp_str, str(p_udp))
|
||||
eq_(udp_str, repr(p_udp))
|
||||
self.assertEqual(udp_str, str(p_udp))
|
||||
self.assertEqual(udp_str, repr(p_udp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv6_tcp(self):
|
||||
# build packet
|
||||
@ -1038,43 +1037,43 @@ class TestPacket(unittest.TestCase):
|
||||
p_tcp = protocols['tcp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
|
||||
# ipv6
|
||||
ok_(p_ipv6)
|
||||
eq_(6, p_ipv6.version)
|
||||
eq_(0, p_ipv6.traffic_class)
|
||||
eq_(0, p_ipv6.flow_label)
|
||||
eq_(len(t_buf) + len(self.payload), p_ipv6.payload_length)
|
||||
eq_(inet.IPPROTO_TCP, p_ipv6.nxt)
|
||||
eq_(255, p_ipv6.hop_limit)
|
||||
eq_('10::10', p_ipv6.src)
|
||||
eq_('20::20', p_ipv6.dst)
|
||||
self.assertTrue(p_ipv6)
|
||||
self.assertEqual(6, p_ipv6.version)
|
||||
self.assertEqual(0, p_ipv6.traffic_class)
|
||||
self.assertEqual(0, p_ipv6.flow_label)
|
||||
self.assertEqual(len(t_buf) + len(self.payload), p_ipv6.payload_length)
|
||||
self.assertEqual(inet.IPPROTO_TCP, p_ipv6.nxt)
|
||||
self.assertEqual(255, p_ipv6.hop_limit)
|
||||
self.assertEqual('10::10', p_ipv6.src)
|
||||
self.assertEqual('20::20', p_ipv6.dst)
|
||||
|
||||
# tcp
|
||||
ok_(p_tcp)
|
||||
eq_(1, p_tcp.src_port)
|
||||
eq_(1, p_tcp.dst_port)
|
||||
eq_(0, p_tcp.seq)
|
||||
eq_(0, p_tcp.ack)
|
||||
eq_(6, p_tcp.offset)
|
||||
eq_(0, p_tcp.bits)
|
||||
eq_(0, p_tcp.window_size)
|
||||
eq_(0, p_tcp.urgent)
|
||||
eq_(len(t_buf), len(p_tcp))
|
||||
self.assertTrue(p_tcp)
|
||||
self.assertEqual(1, p_tcp.src_port)
|
||||
self.assertEqual(1, p_tcp.dst_port)
|
||||
self.assertEqual(0, p_tcp.seq)
|
||||
self.assertEqual(0, p_tcp.ack)
|
||||
self.assertEqual(6, p_tcp.offset)
|
||||
self.assertEqual(0, p_tcp.bits)
|
||||
self.assertEqual(0, p_tcp.window_size)
|
||||
self.assertEqual(0, p_tcp.urgent)
|
||||
self.assertEqual(len(t_buf), len(p_tcp))
|
||||
t = bytearray(t_buf)
|
||||
struct.pack_into('!H', t, 16, p_tcp.csum)
|
||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
|
||||
len(t_buf) + len(self.payload), 6)
|
||||
t = ph + t + self.payload
|
||||
eq_(packet_utils.checksum(t), 0x62)
|
||||
self.assertEqual(packet_utils.checksum(t), 0x62)
|
||||
|
||||
# payload
|
||||
ok_('payload' in protocols)
|
||||
eq_(self.payload, protocols['payload'])
|
||||
self.assertTrue('payload' in protocols)
|
||||
self.assertEqual(self.payload, protocols['payload'])
|
||||
|
||||
# to string
|
||||
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,
|
||||
repr(protocols['payload']))
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv6_str, str(p_ipv6))
|
||||
eq_(ipv6_str, repr(p_ipv6))
|
||||
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||
|
||||
eq_(tcp_str, str(p_tcp))
|
||||
eq_(tcp_str, repr(p_tcp))
|
||||
self.assertEqual(tcp_str, str(p_tcp))
|
||||
self.assertEqual(tcp_str, repr(p_tcp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv6_sctp(self):
|
||||
# build packet
|
||||
@ -1178,39 +1177,39 @@ class TestPacket(unittest.TestCase):
|
||||
p_sctp = protocols['sctp']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
|
||||
# ipv6
|
||||
ok_(p_ipv6)
|
||||
eq_(6, p_ipv6.version)
|
||||
eq_(0, p_ipv6.traffic_class)
|
||||
eq_(0, p_ipv6.flow_label)
|
||||
eq_(len(s_buf), p_ipv6.payload_length)
|
||||
eq_(inet.IPPROTO_SCTP, p_ipv6.nxt)
|
||||
eq_(255, p_ipv6.hop_limit)
|
||||
eq_('10::10', p_ipv6.src)
|
||||
eq_('20::20', p_ipv6.dst)
|
||||
self.assertTrue(p_ipv6)
|
||||
self.assertEqual(6, p_ipv6.version)
|
||||
self.assertEqual(0, p_ipv6.traffic_class)
|
||||
self.assertEqual(0, p_ipv6.flow_label)
|
||||
self.assertEqual(len(s_buf), p_ipv6.payload_length)
|
||||
self.assertEqual(inet.IPPROTO_SCTP, p_ipv6.nxt)
|
||||
self.assertEqual(255, p_ipv6.hop_limit)
|
||||
self.assertEqual('10::10', p_ipv6.src)
|
||||
self.assertEqual('20::20', p_ipv6.dst)
|
||||
|
||||
# sctp
|
||||
ok_(p_sctp)
|
||||
eq_(1, p_sctp.src_port)
|
||||
eq_(1, p_sctp.dst_port)
|
||||
eq_(0, p_sctp.vtag)
|
||||
self.assertTrue(p_sctp)
|
||||
self.assertEqual(1, p_sctp.src_port)
|
||||
self.assertEqual(1, p_sctp.dst_port)
|
||||
self.assertEqual(0, p_sctp.vtag)
|
||||
assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
|
||||
eq_(0, p_sctp.chunks[0]._type)
|
||||
eq_(0, p_sctp.chunks[0].unordered)
|
||||
eq_(0, p_sctp.chunks[0].begin)
|
||||
eq_(0, p_sctp.chunks[0].end)
|
||||
eq_(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||
eq_(0, p_sctp.chunks[0].tsn)
|
||||
eq_(0, p_sctp.chunks[0].sid)
|
||||
eq_(0, p_sctp.chunks[0].seq)
|
||||
eq_(0, p_sctp.chunks[0].payload_id)
|
||||
eq_(self.payload, p_sctp.chunks[0].payload_data)
|
||||
eq_(len(s_buf), len(p_sctp))
|
||||
self.assertEqual(0, p_sctp.chunks[0]._type)
|
||||
self.assertEqual(0, p_sctp.chunks[0].unordered)
|
||||
self.assertEqual(0, p_sctp.chunks[0].begin)
|
||||
self.assertEqual(0, p_sctp.chunks[0].end)
|
||||
self.assertEqual(16 + len(self.payload), p_sctp.chunks[0].length)
|
||||
self.assertEqual(0, p_sctp.chunks[0].tsn)
|
||||
self.assertEqual(0, p_sctp.chunks[0].sid)
|
||||
self.assertEqual(0, p_sctp.chunks[0].seq)
|
||||
self.assertEqual(0, p_sctp.chunks[0].payload_id)
|
||||
self.assertEqual(self.payload, p_sctp.chunks[0].payload_data)
|
||||
self.assertEqual(len(s_buf), len(p_sctp))
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv6_str, str(p_ipv6))
|
||||
eq_(ipv6_str, repr(p_ipv6))
|
||||
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||
|
||||
eq_(sctp_str, str(p_sctp))
|
||||
eq_(sctp_str, repr(p_sctp))
|
||||
self.assertEqual(sctp_str, str(p_sctp))
|
||||
self.assertEqual(sctp_str, repr(p_sctp))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_ipv6_icmpv6(self):
|
||||
# build packet
|
||||
@ -1312,32 +1311,32 @@ class TestPacket(unittest.TestCase):
|
||||
p_icmpv6 = protocols['icmpv6']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
eq_('00:00:00:00:00:00', p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual('ff:ff:ff:ff:ff:ff', p_eth.dst)
|
||||
self.assertEqual('00:00:00:00:00:00', p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IPV6, p_eth.ethertype)
|
||||
|
||||
# ipv6
|
||||
ok_(p_ipv6)
|
||||
eq_(6, p_ipv6.version)
|
||||
eq_(0, p_ipv6.traffic_class)
|
||||
eq_(0, p_ipv6.flow_label)
|
||||
eq_(len(ic_buf), p_ipv6.payload_length)
|
||||
eq_(inet.IPPROTO_ICMPV6, p_ipv6.nxt)
|
||||
eq_(255, p_ipv6.hop_limit)
|
||||
eq_('10::10', p_ipv6.src)
|
||||
eq_('20::20', p_ipv6.dst)
|
||||
self.assertTrue(p_ipv6)
|
||||
self.assertEqual(6, p_ipv6.version)
|
||||
self.assertEqual(0, p_ipv6.traffic_class)
|
||||
self.assertEqual(0, p_ipv6.flow_label)
|
||||
self.assertEqual(len(ic_buf), p_ipv6.payload_length)
|
||||
self.assertEqual(inet.IPPROTO_ICMPV6, p_ipv6.nxt)
|
||||
self.assertEqual(255, p_ipv6.hop_limit)
|
||||
self.assertEqual('10::10', p_ipv6.src)
|
||||
self.assertEqual('20::20', p_ipv6.dst)
|
||||
|
||||
# icmpv6
|
||||
ok_(p_icmpv6)
|
||||
eq_(0, p_icmpv6.type_)
|
||||
eq_(0, p_icmpv6.code)
|
||||
eq_(len(ic_buf), len(p_icmpv6))
|
||||
self.assertTrue(p_icmpv6)
|
||||
self.assertEqual(0, p_icmpv6.type_)
|
||||
self.assertEqual(0, p_icmpv6.code)
|
||||
self.assertEqual(len(ic_buf), len(p_icmpv6))
|
||||
t = bytearray(ic_buf)
|
||||
struct.pack_into('!H', t, 2, p_icmpv6.csum)
|
||||
ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr, len(ic_buf), 58)
|
||||
t = ph + t
|
||||
eq_(packet_utils.checksum(t), 0x60)
|
||||
self.assertEqual(packet_utils.checksum(t), 0x60)
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(ipv6_str, str(p_ipv6))
|
||||
eq_(ipv6_str, repr(p_ipv6))
|
||||
self.assertEqual(ipv6_str, str(p_ipv6))
|
||||
self.assertEqual(ipv6_str, repr(p_ipv6))
|
||||
|
||||
eq_(icmpv6_str, str(p_icmpv6))
|
||||
eq_(icmpv6_str, repr(p_icmpv6))
|
||||
self.assertEqual(icmpv6_str, str(p_icmpv6))
|
||||
self.assertEqual(icmpv6_str, repr(p_icmpv6))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_llc_bpdu(self):
|
||||
# buid packet
|
||||
@ -1440,7 +1439,7 @@ class TestPacket(unittest.TestCase):
|
||||
pad_len = 60 - len(buf)
|
||||
if pad_len > 0:
|
||||
buf += b'\x00' * pad_len
|
||||
eq_(buf, p.data)
|
||||
self.assertEqual(buf, p.data)
|
||||
|
||||
# parse
|
||||
pkt = packet.Packet(p.data)
|
||||
@ -1450,38 +1449,38 @@ class TestPacket(unittest.TestCase):
|
||||
p_bpdu = protocols['ConfigurationBPDUs']
|
||||
|
||||
# ethernet
|
||||
ok_(p_eth)
|
||||
eq_(self.dst_mac, p_eth.dst)
|
||||
eq_(self.src_mac, p_eth.src)
|
||||
eq_(ether.ETH_TYPE_IEEE802_3, p_eth.ethertype)
|
||||
self.assertTrue(p_eth)
|
||||
self.assertEqual(self.dst_mac, p_eth.dst)
|
||||
self.assertEqual(self.src_mac, p_eth.src)
|
||||
self.assertEqual(ether.ETH_TYPE_IEEE802_3, p_eth.ethertype)
|
||||
|
||||
# llc
|
||||
ok_(p_llc)
|
||||
eq_(llc.SAP_BPDU, p_llc.dsap_addr)
|
||||
eq_(llc.SAP_BPDU, p_llc.ssap_addr)
|
||||
eq_(0, p_llc.control.modifier_function1)
|
||||
eq_(0, p_llc.control.pf_bit)
|
||||
eq_(0, p_llc.control.modifier_function2)
|
||||
self.assertTrue(p_llc)
|
||||
self.assertEqual(llc.SAP_BPDU, p_llc.dsap_addr)
|
||||
self.assertEqual(llc.SAP_BPDU, p_llc.ssap_addr)
|
||||
self.assertEqual(0, p_llc.control.modifier_function1)
|
||||
self.assertEqual(0, p_llc.control.pf_bit)
|
||||
self.assertEqual(0, p_llc.control.modifier_function2)
|
||||
|
||||
# bpdu
|
||||
ok_(p_bpdu)
|
||||
eq_(bpdu.PROTOCOL_IDENTIFIER, p_bpdu._protocol_id)
|
||||
eq_(bpdu.PROTOCOLVERSION_ID_BPDU, p_bpdu._version_id)
|
||||
eq_(bpdu.TYPE_CONFIG_BPDU, p_bpdu._bpdu_type)
|
||||
eq_(0, p_bpdu.flags)
|
||||
eq_(32768, p_bpdu.root_priority)
|
||||
eq_(0, p_bpdu.root_system_id_extension)
|
||||
eq_(self.src_mac, p_bpdu.root_mac_address)
|
||||
eq_(0, p_bpdu.root_path_cost)
|
||||
eq_(32768, p_bpdu.bridge_priority)
|
||||
eq_(0, p_bpdu.bridge_system_id_extension)
|
||||
eq_(self.dst_mac, p_bpdu.bridge_mac_address)
|
||||
eq_(128, p_bpdu.port_priority)
|
||||
eq_(4, p_bpdu.port_number)
|
||||
eq_(1, p_bpdu.message_age)
|
||||
eq_(20, p_bpdu.max_age)
|
||||
eq_(2, p_bpdu.hello_time)
|
||||
eq_(15, p_bpdu.forward_delay)
|
||||
self.assertTrue(p_bpdu)
|
||||
self.assertEqual(bpdu.PROTOCOL_IDENTIFIER, p_bpdu._protocol_id)
|
||||
self.assertEqual(bpdu.PROTOCOLVERSION_ID_BPDU, p_bpdu._version_id)
|
||||
self.assertEqual(bpdu.TYPE_CONFIG_BPDU, p_bpdu._bpdu_type)
|
||||
self.assertEqual(0, p_bpdu.flags)
|
||||
self.assertEqual(32768, p_bpdu.root_priority)
|
||||
self.assertEqual(0, p_bpdu.root_system_id_extension)
|
||||
self.assertEqual(self.src_mac, p_bpdu.root_mac_address)
|
||||
self.assertEqual(0, p_bpdu.root_path_cost)
|
||||
self.assertEqual(32768, p_bpdu.bridge_priority)
|
||||
self.assertEqual(0, p_bpdu.bridge_system_id_extension)
|
||||
self.assertEqual(self.dst_mac, p_bpdu.bridge_mac_address)
|
||||
self.assertEqual(128, p_bpdu.port_priority)
|
||||
self.assertEqual(4, p_bpdu.port_number)
|
||||
self.assertEqual(1, p_bpdu.message_age)
|
||||
self.assertEqual(20, p_bpdu.max_age)
|
||||
self.assertEqual(2, p_bpdu.hello_time)
|
||||
self.assertEqual(15, p_bpdu.forward_delay)
|
||||
|
||||
# to string
|
||||
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)
|
||||
|
||||
eq_(eth_str, str(p_eth))
|
||||
eq_(eth_str, repr(p_eth))
|
||||
self.assertEqual(eth_str, str(p_eth))
|
||||
self.assertEqual(eth_str, repr(p_eth))
|
||||
|
||||
eq_(llc_str, str(p_llc))
|
||||
eq_(llc_str, repr(p_llc))
|
||||
self.assertEqual(llc_str, str(p_llc))
|
||||
self.assertEqual(llc_str, repr(p_llc))
|
||||
|
||||
eq_(bpdu_str, str(p_bpdu))
|
||||
eq_(bpdu_str, repr(p_bpdu))
|
||||
self.assertEqual(bpdu_str, str(p_bpdu))
|
||||
self.assertEqual(bpdu_str, repr(p_bpdu))
|
||||
|
||||
eq_(pkt_str, str(pkt))
|
||||
eq_(pkt_str, repr(pkt))
|
||||
self.assertEqual(pkt_str, str(pkt))
|
||||
self.assertEqual(pkt_str, repr(pkt))
|
||||
|
||||
def test_div_api(self):
|
||||
e = ethernet.ethernet(self.dst_mac, self.src_mac, ether.ETH_TYPE_IP)
|
||||
i = ipv4.ipv4()
|
||||
u = udp.udp(self.src_port, self.dst_port)
|
||||
pkt = e / i / u
|
||||
ok_(isinstance(pkt, packet.Packet))
|
||||
ok_(isinstance(pkt.protocols[0], ethernet.ethernet))
|
||||
ok_(isinstance(pkt.protocols[1], ipv4.ipv4))
|
||||
ok_(isinstance(pkt.protocols[2], udp.udp))
|
||||
self.assertTrue(isinstance(pkt, packet.Packet))
|
||||
self.assertTrue(isinstance(pkt.protocols[0], ethernet.ethernet))
|
||||
self.assertTrue(isinstance(pkt.protocols[1], ipv4.ipv4))
|
||||
self.assertTrue(isinstance(pkt.protocols[2], udp.udp))
|
||||
|
@ -17,9 +17,6 @@ import logging
|
||||
import struct
|
||||
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 inet
|
||||
from os_ken.lib.packet import ethernet
|
||||
@ -49,10 +46,10 @@ class Test_itag(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.pcp, self.it.pcp)
|
||||
eq_(self.dei, self.it.dei)
|
||||
eq_(self.uca, self.it.uca)
|
||||
eq_(self.sid, self.it.sid)
|
||||
self.assertEqual(self.pcp, self.it.pcp)
|
||||
self.assertEqual(self.dei, self.it.dei)
|
||||
self.assertEqual(self.uca, self.it.uca)
|
||||
self.assertEqual(self.sid, self.it.sid)
|
||||
|
||||
def test_parser(self):
|
||||
_res = pbb.itag.parser(self.buf)
|
||||
@ -60,17 +57,17 @@ class Test_itag(unittest.TestCase):
|
||||
res = _res[0]
|
||||
else:
|
||||
res = _res
|
||||
eq_(res.pcp, self.pcp)
|
||||
eq_(res.dei, self.dei)
|
||||
eq_(res.uca, self.uca)
|
||||
eq_(res.sid, self.sid)
|
||||
self.assertEqual(res.pcp, self.pcp)
|
||||
self.assertEqual(res.dei, self.dei)
|
||||
self.assertEqual(res.uca, self.uca)
|
||||
self.assertEqual(res.sid, self.sid)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
prev = None
|
||||
buf = self.it.serialize(data, prev)
|
||||
res = struct.unpack(pbb.itag._PACK_STR, buf)
|
||||
eq_(res[0], self.data)
|
||||
self.assertEqual(res[0], self.data)
|
||||
|
||||
def _build_itag(self):
|
||||
b_src_mac = '00:07:0d:af:f4:54'
|
||||
@ -135,38 +132,37 @@ class Test_itag(unittest.TestCase):
|
||||
p = self._build_itag()
|
||||
|
||||
e = p.get_protocols(ethernet.ethernet)
|
||||
ok_(e)
|
||||
ok_(isinstance(e, list))
|
||||
eq_(e[0].ethertype, ether.ETH_TYPE_8021AD)
|
||||
eq_(e[1].ethertype, ether.ETH_TYPE_8021AD)
|
||||
self.assertTrue(e)
|
||||
self.assertTrue(isinstance(e, list))
|
||||
self.assertEqual(e[0].ethertype, ether.ETH_TYPE_8021AD)
|
||||
self.assertEqual(e[1].ethertype, ether.ETH_TYPE_8021AD)
|
||||
|
||||
sv = p.get_protocols(vlan.svlan)
|
||||
ok_(sv)
|
||||
ok_(isinstance(sv, list))
|
||||
eq_(sv[0].ethertype, ether.ETH_TYPE_8021Q)
|
||||
eq_(sv[1].ethertype, ether.ETH_TYPE_8021Q)
|
||||
self.assertTrue(sv)
|
||||
self.assertTrue(isinstance(sv, list))
|
||||
self.assertEqual(sv[0].ethertype, ether.ETH_TYPE_8021Q)
|
||||
self.assertEqual(sv[1].ethertype, ether.ETH_TYPE_8021Q)
|
||||
|
||||
it = p.get_protocol(pbb.itag)
|
||||
ok_(it)
|
||||
self.assertTrue(it)
|
||||
|
||||
v = p.get_protocol(vlan.vlan)
|
||||
ok_(v)
|
||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(v)
|
||||
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
ip = p.get_protocol(ipv4.ipv4)
|
||||
ok_(ip)
|
||||
self.assertTrue(ip)
|
||||
|
||||
eq_(it.pcp, self.pcp)
|
||||
eq_(it.dei, self.dei)
|
||||
eq_(it.uca, self.uca)
|
||||
eq_(it.sid, self.sid)
|
||||
self.assertEqual(it.pcp, self.pcp)
|
||||
self.assertEqual(it.dei, self.dei)
|
||||
self.assertEqual(it.uca, self.uca)
|
||||
self.assertEqual(it.sid, self.sid)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_itag(self):
|
||||
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):
|
||||
jsondict = self.it.to_jsondict()
|
||||
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 unittest
|
||||
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
from os_ken.lib import addrconv
|
||||
from os_ken.lib.packet import packet
|
||||
from os_ken.lib.packet import ethernet
|
||||
@ -518,11 +516,11 @@ class Test_sctp(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.src_port, self.sc.src_port)
|
||||
eq_(self.dst_port, self.sc.dst_port)
|
||||
eq_(self.vtag, self.sc.vtag)
|
||||
eq_(self.csum, self.sc.csum)
|
||||
eq_(self.chunks, self.sc.chunks)
|
||||
self.assertEqual(self.src_port, self.sc.src_port)
|
||||
self.assertEqual(self.dst_port, self.sc.dst_port)
|
||||
self.assertEqual(self.vtag, self.sc.vtag)
|
||||
self.assertEqual(self.csum, self.sc.csum)
|
||||
self.assertEqual(self.chunks, self.sc.chunks)
|
||||
|
||||
def test_init_with_data(self):
|
||||
self.setUp_with_data()
|
||||
@ -597,11 +595,11 @@ class Test_sctp(unittest.TestCase):
|
||||
# to calculate the lengths of parameters.
|
||||
self.sc.serialize(None, None)
|
||||
|
||||
eq_(self.src_port, res.src_port)
|
||||
eq_(self.dst_port, res.dst_port)
|
||||
eq_(self.vtag, res.vtag)
|
||||
eq_(self.csum, res.csum)
|
||||
eq_(str(self.chunks), str(res.chunks))
|
||||
self.assertEqual(self.src_port, res.src_port)
|
||||
self.assertEqual(self.dst_port, res.dst_port)
|
||||
self.assertEqual(self.vtag, res.vtag)
|
||||
self.assertEqual(self.csum, res.csum)
|
||||
self.assertEqual(str(self.chunks), str(res.chunks))
|
||||
|
||||
def test_parser_with_data(self):
|
||||
self.setUp_with_data()
|
||||
@ -670,11 +668,11 @@ class Test_sctp(unittest.TestCase):
|
||||
def _test_serialize(self):
|
||||
buf = self.sc.serialize(bytearray(), None)
|
||||
res = struct.unpack_from(sctp.sctp._PACK_STR, buf)
|
||||
eq_(self.src_port, res[0])
|
||||
eq_(self.dst_port, res[1])
|
||||
eq_(self.vtag, res[2])
|
||||
self.assertEqual(self.src_port, res[0])
|
||||
self.assertEqual(self.dst_port, res[1])
|
||||
self.assertEqual(self.vtag, res[2])
|
||||
# skip compare checksum
|
||||
# eq_(self.csum, res[3])
|
||||
# self.assertEqual(self.csum, res[3])
|
||||
|
||||
return buf[sctp.sctp._MIN_LEN:]
|
||||
|
||||
@ -685,71 +683,71 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_data()
|
||||
buf = self._test_serialize()
|
||||
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 = (
|
||||
(self.unordered << 2) |
|
||||
(self.begin << 1) |
|
||||
(self.end << 0))
|
||||
eq_(flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.tsn, res[3])
|
||||
eq_(self.sid, res[4])
|
||||
eq_(self.seq, res[5])
|
||||
eq_(self.payload_id, res[6])
|
||||
eq_(self.payload_data, buf[sctp.chunk_data._MIN_LEN:])
|
||||
self.assertEqual(flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.tsn, res[3])
|
||||
self.assertEqual(self.sid, res[4])
|
||||
self.assertEqual(self.seq, res[5])
|
||||
self.assertEqual(self.payload_id, res[6])
|
||||
self.assertEqual(self.payload_data, buf[sctp.chunk_data._MIN_LEN:])
|
||||
|
||||
def test_serialize_with_init(self):
|
||||
self.setUp_with_init()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_init._PACK_STR, buf)
|
||||
eq_(sctp.chunk_init.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.init_tag, res[3])
|
||||
eq_(self.a_rwnd, res[4])
|
||||
eq_(self.os, res[5])
|
||||
eq_(self.mis, res[6])
|
||||
eq_(self.i_tsn, res[7])
|
||||
self.assertEqual(sctp.chunk_init.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.init_tag, res[3])
|
||||
self.assertEqual(self.a_rwnd, res[4])
|
||||
self.assertEqual(self.os, res[5])
|
||||
self.assertEqual(self.mis, res[6])
|
||||
self.assertEqual(self.i_tsn, res[7])
|
||||
|
||||
buf = buf[sctp.chunk_init._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
||||
eq_(sctp.param_ipv4.param_type(), res1[0])
|
||||
eq_(8, res1[1])
|
||||
eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||
self.assertEqual(sctp.param_ipv4.param_type(), res1[0])
|
||||
self.assertEqual(8, res1[1])
|
||||
self.assertEqual('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
||||
|
||||
buf = buf[8:]
|
||||
res2 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
||||
eq_(sctp.param_ipv6.param_type(), res2[0])
|
||||
eq_(20, res2[1])
|
||||
eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
||||
self.assertEqual(sctp.param_ipv6.param_type(), res2[0])
|
||||
self.assertEqual(20, res2[1])
|
||||
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 = buf[20:]
|
||||
res3 = struct.unpack_from(sctp.param_cookie_preserve._PACK_STR,
|
||||
buf)
|
||||
eq_(sctp.param_cookie_preserve.param_type(), res3[0])
|
||||
eq_(8, res3[1])
|
||||
eq_(5000, res3[2])
|
||||
self.assertEqual(sctp.param_cookie_preserve.param_type(), res3[0])
|
||||
self.assertEqual(8, res3[1])
|
||||
self.assertEqual(5000, res3[2])
|
||||
|
||||
buf = buf[8:]
|
||||
res4 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
||||
eq_(sctp.param_ecn.param_type(), res4[0])
|
||||
eq_(4, res4[1])
|
||||
self.assertEqual(sctp.param_ecn.param_type(), res4[0])
|
||||
self.assertEqual(4, res4[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res5 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
||||
eq_(sctp.param_host_addr.param_type(), res5[0])
|
||||
eq_(14, res5[1])
|
||||
eq_(b'test host\x00',
|
||||
self.assertEqual(sctp.param_host_addr.param_type(), res5[0])
|
||||
self.assertEqual(14, res5[1])
|
||||
self.assertEqual(b'test host\x00',
|
||||
buf[sctp.param_host_addr._MIN_LEN:
|
||||
sctp.param_host_addr._MIN_LEN + 10])
|
||||
|
||||
buf = buf[16:]
|
||||
res6 = struct.unpack_from(sctp.param_supported_addr._PACK_STR, buf)
|
||||
res6 = list(res6)
|
||||
eq_(sctp.param_supported_addr.param_type(), res6[0])
|
||||
eq_(14, res6[1])
|
||||
self.assertEqual(sctp.param_supported_addr.param_type(), res6[0])
|
||||
self.assertEqual(14, res6[1])
|
||||
buf = buf[sctp.param_supported_addr._MIN_LEN:]
|
||||
offset = 0
|
||||
tmplist = []
|
||||
@ -758,66 +756,66 @@ class Test_sctp(unittest.TestCase):
|
||||
tmplist.append(tmp)
|
||||
offset += struct.calcsize('!H')
|
||||
res6.extend(tmplist)
|
||||
eq_(sctp.PTYPE_IPV4, res6[2])
|
||||
eq_(sctp.PTYPE_IPV6, res6[3])
|
||||
eq_(sctp.PTYPE_COOKIE_PRESERVE, res6[4])
|
||||
eq_(sctp.PTYPE_ECN, res6[5])
|
||||
eq_(sctp.PTYPE_HOST_ADDR, res6[6])
|
||||
self.assertEqual(sctp.PTYPE_IPV4, res6[2])
|
||||
self.assertEqual(sctp.PTYPE_IPV6, res6[3])
|
||||
self.assertEqual(sctp.PTYPE_COOKIE_PRESERVE, res6[4])
|
||||
self.assertEqual(sctp.PTYPE_ECN, res6[5])
|
||||
self.assertEqual(sctp.PTYPE_HOST_ADDR, res6[6])
|
||||
|
||||
def test_serialize_with_init_ack(self):
|
||||
self.setUp_with_init_ack()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_init_ack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_init_ack.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.init_tag, res[3])
|
||||
eq_(self.a_rwnd, res[4])
|
||||
eq_(self.os, res[5])
|
||||
eq_(self.mis, res[6])
|
||||
eq_(self.i_tsn, res[7])
|
||||
self.assertEqual(sctp.chunk_init_ack.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.init_tag, res[3])
|
||||
self.assertEqual(self.a_rwnd, res[4])
|
||||
self.assertEqual(self.os, res[5])
|
||||
self.assertEqual(self.mis, res[6])
|
||||
self.assertEqual(self.i_tsn, res[7])
|
||||
|
||||
buf = buf[sctp.chunk_init_ack._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.param_state_cookie._PACK_STR, buf)
|
||||
eq_(sctp.param_state_cookie.param_type(), res1[0])
|
||||
eq_(7, res1[1])
|
||||
eq_(b'\x01\x02\x03',
|
||||
self.assertEqual(sctp.param_state_cookie.param_type(), res1[0])
|
||||
self.assertEqual(7, res1[1])
|
||||
self.assertEqual(b'\x01\x02\x03',
|
||||
buf[sctp.param_state_cookie._MIN_LEN:
|
||||
sctp.param_state_cookie._MIN_LEN + 3])
|
||||
|
||||
buf = buf[8:]
|
||||
res2 = struct.unpack_from(sctp.param_ipv4._PACK_STR, buf)
|
||||
eq_(sctp.param_ipv4.param_type(), res2[0])
|
||||
eq_(8, res2[1])
|
||||
eq_('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||
self.assertEqual(sctp.param_ipv4.param_type(), res2[0])
|
||||
self.assertEqual(8, res2[1])
|
||||
self.assertEqual('192.168.1.1', addrconv.ipv4.bin_to_text(
|
||||
buf[sctp.param_ipv4._MIN_LEN:sctp.param_ipv4._MIN_LEN + 4]))
|
||||
|
||||
buf = buf[8:]
|
||||
res3 = struct.unpack_from(sctp.param_ipv6._PACK_STR, buf)
|
||||
eq_(sctp.param_ipv6.param_type(), res3[0])
|
||||
eq_(20, res3[1])
|
||||
eq_('fe80::647e:1aff:fec4:8284', addrconv.ipv6.bin_to_text(
|
||||
self.assertEqual(sctp.param_ipv6.param_type(), res3[0])
|
||||
self.assertEqual(20, res3[1])
|
||||
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 = buf[20:]
|
||||
res4 = struct.unpack_from(
|
||||
sctp.param_unrecognized_param._PACK_STR, buf)
|
||||
eq_(sctp.param_unrecognized_param.param_type(), res4[0])
|
||||
eq_(8, res4[1])
|
||||
eq_(b'\xff\xff\x00\x04',
|
||||
self.assertEqual(sctp.param_unrecognized_param.param_type(), res4[0])
|
||||
self.assertEqual(8, res4[1])
|
||||
self.assertEqual(b'\xff\xff\x00\x04',
|
||||
buf[sctp.param_unrecognized_param._MIN_LEN:
|
||||
sctp.param_unrecognized_param._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res5 = struct.unpack_from(sctp.param_ecn._PACK_STR, buf)
|
||||
eq_(sctp.param_ecn.param_type(), res5[0])
|
||||
eq_(4, res5[1])
|
||||
self.assertEqual(sctp.param_ecn.param_type(), res5[0])
|
||||
self.assertEqual(4, res5[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res6 = struct.unpack_from(sctp.param_host_addr._PACK_STR, buf)
|
||||
eq_(sctp.param_host_addr.param_type(), res6[0])
|
||||
eq_(14, res6[1])
|
||||
eq_(b'test host\x00',
|
||||
self.assertEqual(sctp.param_host_addr.param_type(), res6[0])
|
||||
self.assertEqual(14, res6[1])
|
||||
self.assertEqual(b'test host\x00',
|
||||
buf[sctp.param_host_addr._MIN_LEN:
|
||||
sctp.param_host_addr._MIN_LEN + 10])
|
||||
|
||||
@ -825,13 +823,13 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_sack()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_sack.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.tsn_ack, res[3])
|
||||
eq_(self.a_rwnd, res[4])
|
||||
eq_(self.gapack_num, res[5])
|
||||
eq_(self.duptsn_num, res[6])
|
||||
self.assertEqual(sctp.chunk_sack.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.tsn_ack, res[3])
|
||||
self.assertEqual(self.a_rwnd, res[4])
|
||||
self.assertEqual(self.gapack_num, res[5])
|
||||
self.assertEqual(self.duptsn_num, res[6])
|
||||
|
||||
buf = buf[sctp.chunk_sack._MIN_LEN:]
|
||||
gapacks = []
|
||||
@ -847,22 +845,22 @@ class Test_sctp(unittest.TestCase):
|
||||
sctp.chunk_sack._DUPTSN_STR, buf)
|
||||
duptsns.append(duptsn)
|
||||
buf = buf[sctp.chunk_sack._DUPTSN_LEN:]
|
||||
eq_(self.gapacks, gapacks)
|
||||
eq_(self.duptsns, duptsns)
|
||||
self.assertEqual(self.gapacks, gapacks)
|
||||
self.assertEqual(self.duptsns, duptsns)
|
||||
|
||||
def test_serialize_with_heartbeat(self):
|
||||
self.setUp_with_heartbeat()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_heartbeat._PACK_STR, buf)
|
||||
eq_(sctp.chunk_heartbeat.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(sctp.chunk_heartbeat.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
buf = buf[sctp.chunk_heartbeat._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
||||
eq_(sctp.param_heartbeat.param_type(), res1[0])
|
||||
eq_(8, res1[1])
|
||||
eq_(b'\x01\x02\x03\x04',
|
||||
self.assertEqual(sctp.param_heartbeat.param_type(), res1[0])
|
||||
self.assertEqual(8, res1[1])
|
||||
self.assertEqual(b'\x01\x02\x03\x04',
|
||||
buf[sctp.param_heartbeat._MIN_LEN:
|
||||
sctp.param_heartbeat._MIN_LEN + 4])
|
||||
|
||||
@ -870,15 +868,15 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_heartbeat_ack()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_heartbeat_ack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_heartbeat_ack.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(sctp.chunk_heartbeat_ack.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
buf = buf[sctp.chunk_heartbeat_ack._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.param_heartbeat._PACK_STR, buf)
|
||||
eq_(sctp.param_heartbeat.param_type(), res1[0])
|
||||
eq_(12, res1[1])
|
||||
eq_(b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88',
|
||||
self.assertEqual(sctp.param_heartbeat.param_type(), res1[0])
|
||||
self.assertEqual(12, res1[1])
|
||||
self.assertEqual(b'\xff\xee\xdd\xcc\xbb\xaa\x99\x88',
|
||||
buf[sctp.param_heartbeat._MIN_LEN:
|
||||
sctp.param_heartbeat._MIN_LEN + 8])
|
||||
|
||||
@ -886,50 +884,50 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_abort()
|
||||
buf = self._test_serialize()
|
||||
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
|
||||
eq_(flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
buf = buf[sctp.chunk_abort._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
||||
eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||
eq_(8, res1[1])
|
||||
eq_(4096, res1[2])
|
||||
self.assertEqual(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||
self.assertEqual(8, res1[1])
|
||||
self.assertEqual(4096, res1[2])
|
||||
|
||||
buf = buf[8:]
|
||||
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_missing_param.cause_code(), res2[0])
|
||||
eq_(16, res2[1])
|
||||
eq_(4, res2[2])
|
||||
self.assertEqual(sctp.cause_missing_param.cause_code(), res2[0])
|
||||
self.assertEqual(16, res2[1])
|
||||
self.assertEqual(4, res2[2])
|
||||
types = []
|
||||
for count in range(4):
|
||||
(tmp, ) = struct.unpack_from(
|
||||
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
||||
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]),
|
||||
str(types))
|
||||
|
||||
buf = buf[16:]
|
||||
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
||||
eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||
eq_(8, res3[1])
|
||||
eq_(b'\x00\x00\x13\x88',
|
||||
self.assertEqual(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||
self.assertEqual(8, res3[1])
|
||||
self.assertEqual(b'\x00\x00\x13\x88',
|
||||
buf[sctp.cause_stale_cookie._MIN_LEN:
|
||||
sctp.cause_stale_cookie._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
||||
eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||
eq_(4, res4[1])
|
||||
self.assertEqual(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||
self.assertEqual(4, res4[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res5 = struct.unpack_from(
|
||||
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
||||
eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||
eq_(20, res5[1])
|
||||
eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||
self.assertEqual(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||
self.assertEqual(20, res5[1])
|
||||
self.assertEqual(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
||||
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
||||
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
||||
@ -937,64 +935,64 @@ class Test_sctp(unittest.TestCase):
|
||||
buf = buf[20:]
|
||||
res6 = struct.unpack_from(
|
||||
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
||||
eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||
eq_(8, res6[1])
|
||||
eq_(b'\xff\x00\x00\x04',
|
||||
self.assertEqual(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||
self.assertEqual(8, res6[1])
|
||||
self.assertEqual(b'\xff\x00\x00\x04',
|
||||
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
||||
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||
eq_(4, res7[1])
|
||||
self.assertEqual(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||
self.assertEqual(4, res7[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res8 = struct.unpack_from(
|
||||
sctp.cause_unrecognized_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||
eq_(8, res8[1])
|
||||
eq_(b'\xff\xff\x00\x04',
|
||||
self.assertEqual(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||
self.assertEqual(8, res8[1])
|
||||
self.assertEqual(b'\xff\xff\x00\x04',
|
||||
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
||||
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
||||
eq_(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||
eq_(8, res9[1])
|
||||
eq_(b'\x00\x01\xe2\x40',
|
||||
self.assertEqual(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||
self.assertEqual(8, res9[1])
|
||||
self.assertEqual(b'\x00\x01\xe2\x40',
|
||||
buf[sctp.cause_no_userdata._MIN_LEN:
|
||||
sctp.cause_no_userdata._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res10 = struct.unpack_from(
|
||||
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
||||
eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||
eq_(4, res10[1])
|
||||
self.assertEqual(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||
self.assertEqual(4, res10[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res11 = struct.unpack_from(
|
||||
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
||||
eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||
eq_(12, res11[1])
|
||||
eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||
self.assertEqual(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||
self.assertEqual(12, res11[1])
|
||||
self.assertEqual(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
||||
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
||||
|
||||
buf = buf[12:]
|
||||
res12 = struct.unpack_from(
|
||||
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
||||
eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||
eq_(19, res12[1])
|
||||
eq_(b'Key Interrupt.\x00',
|
||||
self.assertEqual(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||
self.assertEqual(19, res12[1])
|
||||
self.assertEqual(b'Key Interrupt.\x00',
|
||||
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
||||
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
||||
|
||||
buf = buf[20:]
|
||||
res13 = struct.unpack_from(
|
||||
sctp.cause_protocol_violation._PACK_STR, buf)
|
||||
eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||
eq_(20, res13[1])
|
||||
eq_(b'Unknown reason.\x00',
|
||||
self.assertEqual(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||
self.assertEqual(20, res13[1])
|
||||
self.assertEqual(b'Unknown reason.\x00',
|
||||
buf[sctp.cause_protocol_violation._MIN_LEN:
|
||||
sctp.cause_protocol_violation._MIN_LEN + 16])
|
||||
|
||||
@ -1002,66 +1000,66 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_shutdown()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_shutdown._PACK_STR, buf)
|
||||
eq_(sctp.chunk_shutdown.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.tsn_ack, res[3])
|
||||
self.assertEqual(sctp.chunk_shutdown.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.tsn_ack, res[3])
|
||||
|
||||
def test_serialize_with_shutdown_ack(self):
|
||||
self.setUp_with_shutdown_ack()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_shutdown_ack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_shutdown_ack.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(sctp.chunk_shutdown_ack.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
def test_serialize_with_error(self):
|
||||
self.setUp_with_error()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_error._PACK_STR, buf)
|
||||
eq_(sctp.chunk_error.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(sctp.chunk_error.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
buf = buf[sctp.chunk_error._MIN_LEN:]
|
||||
res1 = struct.unpack_from(sctp.cause_invalid_stream_id._PACK_STR, buf)
|
||||
eq_(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||
eq_(8, res1[1])
|
||||
eq_(4096, res1[2])
|
||||
self.assertEqual(sctp.cause_invalid_stream_id.cause_code(), res1[0])
|
||||
self.assertEqual(8, res1[1])
|
||||
self.assertEqual(4096, res1[2])
|
||||
|
||||
buf = buf[8:]
|
||||
res2 = struct.unpack_from(sctp.cause_missing_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_missing_param.cause_code(), res2[0])
|
||||
eq_(16, res2[1])
|
||||
eq_(4, res2[2])
|
||||
self.assertEqual(sctp.cause_missing_param.cause_code(), res2[0])
|
||||
self.assertEqual(16, res2[1])
|
||||
self.assertEqual(4, res2[2])
|
||||
types = []
|
||||
for count in range(4):
|
||||
(tmp, ) = struct.unpack_from(
|
||||
'!H', buf, sctp.cause_missing_param._MIN_LEN + 2 * count)
|
||||
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]),
|
||||
str(types))
|
||||
|
||||
buf = buf[16:]
|
||||
res3 = struct.unpack_from(sctp.cause_stale_cookie._PACK_STR, buf)
|
||||
eq_(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||
eq_(8, res3[1])
|
||||
eq_(b'\x00\x00\x13\x88',
|
||||
self.assertEqual(sctp.cause_stale_cookie.cause_code(), res3[0])
|
||||
self.assertEqual(8, res3[1])
|
||||
self.assertEqual(b'\x00\x00\x13\x88',
|
||||
buf[sctp.cause_stale_cookie._MIN_LEN:
|
||||
sctp.cause_stale_cookie._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res4 = struct.unpack_from(sctp.cause_out_of_resource._PACK_STR, buf)
|
||||
eq_(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||
eq_(4, res4[1])
|
||||
self.assertEqual(sctp.cause_out_of_resource.cause_code(), res4[0])
|
||||
self.assertEqual(4, res4[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res5 = struct.unpack_from(
|
||||
sctp.cause_unresolvable_addr._PACK_STR, buf)
|
||||
eq_(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||
eq_(20, res5[1])
|
||||
eq_(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||
self.assertEqual(sctp.cause_unresolvable_addr.cause_code(), res5[0])
|
||||
self.assertEqual(20, res5[1])
|
||||
self.assertEqual(b'\x00\x0b\x00\x0e\x74\x65\x73\x74' +
|
||||
b'\x20\x68\x6f\x73\x74\x00\x00\x00',
|
||||
buf[sctp.cause_unresolvable_addr._MIN_LEN:
|
||||
sctp.cause_unresolvable_addr._MIN_LEN + 16])
|
||||
@ -1069,64 +1067,64 @@ class Test_sctp(unittest.TestCase):
|
||||
buf = buf[20:]
|
||||
res6 = struct.unpack_from(
|
||||
sctp.cause_unrecognized_chunk._PACK_STR, buf)
|
||||
eq_(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||
eq_(8, res6[1])
|
||||
eq_(b'\xff\x00\x00\x04',
|
||||
self.assertEqual(sctp.cause_unrecognized_chunk.cause_code(), res6[0])
|
||||
self.assertEqual(8, res6[1])
|
||||
self.assertEqual(b'\xff\x00\x00\x04',
|
||||
buf[sctp.cause_unrecognized_chunk._MIN_LEN:
|
||||
sctp.cause_unrecognized_chunk._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res7 = struct.unpack_from(sctp.cause_invalid_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||
eq_(4, res7[1])
|
||||
self.assertEqual(sctp.cause_invalid_param.cause_code(), res7[0])
|
||||
self.assertEqual(4, res7[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res8 = struct.unpack_from(
|
||||
sctp.cause_unrecognized_param._PACK_STR, buf)
|
||||
eq_(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||
eq_(8, res8[1])
|
||||
eq_(b'\xff\xff\x00\x04',
|
||||
self.assertEqual(sctp.cause_unrecognized_param.cause_code(), res8[0])
|
||||
self.assertEqual(8, res8[1])
|
||||
self.assertEqual(b'\xff\xff\x00\x04',
|
||||
buf[sctp.cause_unrecognized_param._MIN_LEN:
|
||||
sctp.cause_unrecognized_param._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res9 = struct.unpack_from(sctp.cause_no_userdata._PACK_STR, buf)
|
||||
eq_(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||
eq_(8, res9[1])
|
||||
eq_(b'\x00\x01\xe2\x40',
|
||||
self.assertEqual(sctp.cause_no_userdata.cause_code(), res9[0])
|
||||
self.assertEqual(8, res9[1])
|
||||
self.assertEqual(b'\x00\x01\xe2\x40',
|
||||
buf[sctp.cause_no_userdata._MIN_LEN:
|
||||
sctp.cause_no_userdata._MIN_LEN + 4])
|
||||
|
||||
buf = buf[8:]
|
||||
res10 = struct.unpack_from(
|
||||
sctp.cause_cookie_while_shutdown._PACK_STR, buf)
|
||||
eq_(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||
eq_(4, res10[1])
|
||||
self.assertEqual(sctp.cause_cookie_while_shutdown.cause_code(), res10[0])
|
||||
self.assertEqual(4, res10[1])
|
||||
|
||||
buf = buf[4:]
|
||||
res11 = struct.unpack_from(
|
||||
sctp.cause_restart_with_new_addr._PACK_STR, buf)
|
||||
eq_(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||
eq_(12, res11[1])
|
||||
eq_(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||
self.assertEqual(sctp.cause_restart_with_new_addr.cause_code(), res11[0])
|
||||
self.assertEqual(12, res11[1])
|
||||
self.assertEqual(b'\x00\x05\x00\x08\xc0\xa8\x01\x01',
|
||||
buf[sctp.cause_restart_with_new_addr._MIN_LEN:
|
||||
sctp.cause_restart_with_new_addr._MIN_LEN + 8])
|
||||
|
||||
buf = buf[12:]
|
||||
res12 = struct.unpack_from(
|
||||
sctp.cause_user_initiated_abort._PACK_STR, buf)
|
||||
eq_(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||
eq_(19, res12[1])
|
||||
eq_(b'Key Interrupt.\x00',
|
||||
self.assertEqual(sctp.cause_user_initiated_abort.cause_code(), res12[0])
|
||||
self.assertEqual(19, res12[1])
|
||||
self.assertEqual(b'Key Interrupt.\x00',
|
||||
buf[sctp.cause_user_initiated_abort._MIN_LEN:
|
||||
sctp.cause_user_initiated_abort._MIN_LEN + 15])
|
||||
|
||||
buf = buf[20:]
|
||||
res13 = struct.unpack_from(
|
||||
sctp.cause_protocol_violation._PACK_STR, buf)
|
||||
eq_(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||
eq_(20, res13[1])
|
||||
eq_(b'Unknown reason.\x00',
|
||||
self.assertEqual(sctp.cause_protocol_violation.cause_code(), res13[0])
|
||||
self.assertEqual(20, res13[1])
|
||||
self.assertEqual(b'Unknown reason.\x00',
|
||||
buf[sctp.cause_protocol_violation._MIN_LEN:
|
||||
sctp.cause_protocol_violation._MIN_LEN + 16])
|
||||
|
||||
@ -1134,10 +1132,10 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_cookie_echo()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_cookie_echo._PACK_STR, buf)
|
||||
eq_(sctp.chunk_cookie_echo.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.cookie,
|
||||
self.assertEqual(sctp.chunk_cookie_echo.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.cookie,
|
||||
buf[sctp.chunk_cookie_echo._MIN_LEN:
|
||||
sctp.chunk_cookie_echo._MIN_LEN + 4])
|
||||
|
||||
@ -1145,81 +1143,81 @@ class Test_sctp(unittest.TestCase):
|
||||
self.setUp_with_cookie_ack()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_cookie_ack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_cookie_ack.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(sctp.chunk_cookie_ack.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
def test_serialize_with_ecn_echo(self):
|
||||
self.setUp_with_ecn_echo()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_ecn_echo._PACK_STR, buf)
|
||||
eq_(sctp.chunk_ecn_echo.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.low_tsn, res[3])
|
||||
self.assertEqual(sctp.chunk_ecn_echo.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.low_tsn, res[3])
|
||||
|
||||
def test_serialize_with_cwr(self):
|
||||
self.setUp_with_cwr()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_cwr._PACK_STR, buf)
|
||||
eq_(sctp.chunk_cwr.chunk_type(), res[0])
|
||||
eq_(self.flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
eq_(self.low_tsn, res[3])
|
||||
self.assertEqual(sctp.chunk_cwr.chunk_type(), res[0])
|
||||
self.assertEqual(self.flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
self.assertEqual(self.low_tsn, res[3])
|
||||
|
||||
def test_serialize_with_shutdown_complete(self):
|
||||
self.setUp_with_shutdown_complete()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(
|
||||
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
|
||||
eq_(flags, res[1])
|
||||
eq_(self.length, res[2])
|
||||
self.assertEqual(flags, res[1])
|
||||
self.assertEqual(self.length, res[2])
|
||||
|
||||
def test_serialize_with_multi_chunks(self):
|
||||
self.setUp_with_multi_chunks()
|
||||
buf = self._test_serialize()
|
||||
res = struct.unpack_from(sctp.chunk_sack._PACK_STR, buf)
|
||||
eq_(sctp.chunk_sack.chunk_type(), res[0])
|
||||
eq_(self.s_flags, res[1])
|
||||
eq_(self.s_length, res[2])
|
||||
eq_(self.s_tsn_ack, res[3])
|
||||
eq_(self.s_a_rwnd, res[4])
|
||||
eq_(self.s_gapack_num, res[5])
|
||||
eq_(self.s_duptsn_num, res[6])
|
||||
self.assertEqual(sctp.chunk_sack.chunk_type(), res[0])
|
||||
self.assertEqual(self.s_flags, res[1])
|
||||
self.assertEqual(self.s_length, res[2])
|
||||
self.assertEqual(self.s_tsn_ack, res[3])
|
||||
self.assertEqual(self.s_a_rwnd, res[4])
|
||||
self.assertEqual(self.s_gapack_num, res[5])
|
||||
self.assertEqual(self.s_duptsn_num, res[6])
|
||||
|
||||
buf = buf[self.s_length:]
|
||||
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 = (
|
||||
(self.d1_unordered << 2) |
|
||||
(self.d1_begin << 1) |
|
||||
(self.d1_end << 0))
|
||||
eq_(d1_flags, res[1])
|
||||
eq_(self.d1_length, res[2])
|
||||
eq_(self.d1_tsn, res[3])
|
||||
eq_(self.d1_sid, res[4])
|
||||
eq_(self.d1_seq, res[5])
|
||||
eq_(self.d1_payload_id, res[6])
|
||||
eq_(self.d1_payload_data,
|
||||
self.assertEqual(d1_flags, res[1])
|
||||
self.assertEqual(self.d1_length, res[2])
|
||||
self.assertEqual(self.d1_tsn, res[3])
|
||||
self.assertEqual(self.d1_sid, res[4])
|
||||
self.assertEqual(self.d1_seq, res[5])
|
||||
self.assertEqual(self.d1_payload_id, res[6])
|
||||
self.assertEqual(self.d1_payload_data,
|
||||
buf[sctp.chunk_data._MIN_LEN:
|
||||
sctp.chunk_data._MIN_LEN + 10])
|
||||
|
||||
buf = buf[self.d1_length:]
|
||||
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 = (
|
||||
(self.d2_unordered << 2) |
|
||||
(self.d2_begin << 1) |
|
||||
(self.d2_end << 0))
|
||||
eq_(d2_flags, res[1])
|
||||
eq_(self.d2_length, res[2])
|
||||
eq_(self.d2_tsn, res[3])
|
||||
eq_(self.d2_sid, res[4])
|
||||
eq_(self.d2_seq, res[5])
|
||||
eq_(self.d2_payload_id, res[6])
|
||||
eq_(self.d2_payload_data,
|
||||
self.assertEqual(d2_flags, res[1])
|
||||
self.assertEqual(self.d2_length, res[2])
|
||||
self.assertEqual(self.d2_tsn, res[3])
|
||||
self.assertEqual(self.d2_sid, res[4])
|
||||
self.assertEqual(self.d2_seq, res[5])
|
||||
self.assertEqual(self.d2_payload_id, res[6])
|
||||
self.assertEqual(self.d2_payload_data,
|
||||
buf[sctp.chunk_data._MIN_LEN:
|
||||
sctp.chunk_data._MIN_LEN + 10])
|
||||
|
||||
@ -1231,16 +1229,16 @@ class Test_sctp(unittest.TestCase):
|
||||
pkt = eth / ip4 / self.sc
|
||||
|
||||
eth = pkt.get_protocol(ethernet.ethernet)
|
||||
ok_(eth)
|
||||
eq_(eth.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(eth)
|
||||
self.assertEqual(eth.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
ip4 = pkt.get_protocol(ipv4.ipv4)
|
||||
ok_(ip4)
|
||||
eq_(ip4.proto, inet.IPPROTO_SCTP)
|
||||
self.assertTrue(ip4)
|
||||
self.assertEqual(ip4.proto, inet.IPPROTO_SCTP)
|
||||
|
||||
sc = pkt.get_protocol(sctp.sctp)
|
||||
ok_(sc)
|
||||
eq_(sc, self.sc)
|
||||
self.assertTrue(sc)
|
||||
self.assertEqual(sc, self.sc)
|
||||
|
||||
def test_build_sctp_with_data(self):
|
||||
self.setUp_with_data()
|
||||
@ -1317,8 +1315,8 @@ class Test_sctp(unittest.TestCase):
|
||||
if k in sctp_values])
|
||||
sctp_str = '%s(%s)' % (sctp.sctp.__name__, _sctp_str)
|
||||
|
||||
eq_(str(self.sc), sctp_str)
|
||||
eq_(repr(self.sc), sctp_str)
|
||||
self.assertEqual(str(self.sc), sctp_str)
|
||||
self.assertEqual(repr(self.sc), sctp_str)
|
||||
|
||||
def test_to_string_with_data(self):
|
||||
self.setUp_with_data()
|
||||
@ -1387,7 +1385,7 @@ class Test_sctp(unittest.TestCase):
|
||||
def test_json(self):
|
||||
jsondict = self.sc.to_jsondict()
|
||||
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):
|
||||
self.setUp_with_data()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,6 @@ import logging
|
||||
import six
|
||||
import struct
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import inet
|
||||
from os_ken.lib.packet import tcp
|
||||
from os_ken.lib.packet.ipv4 import ipv4
|
||||
@ -59,31 +58,31 @@ class Test_tcp(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.src_port, self.t.src_port)
|
||||
eq_(self.dst_port, self.t.dst_port)
|
||||
eq_(self.seq, self.t.seq)
|
||||
eq_(self.ack, self.t.ack)
|
||||
eq_(self.offset, self.t.offset)
|
||||
eq_(self.bits, self.t.bits)
|
||||
eq_(self.window_size, self.t.window_size)
|
||||
eq_(self.csum, self.t.csum)
|
||||
eq_(self.urgent, self.t.urgent)
|
||||
eq_(self.option, self.t.option)
|
||||
self.assertEqual(self.src_port, self.t.src_port)
|
||||
self.assertEqual(self.dst_port, self.t.dst_port)
|
||||
self.assertEqual(self.seq, self.t.seq)
|
||||
self.assertEqual(self.ack, self.t.ack)
|
||||
self.assertEqual(self.offset, self.t.offset)
|
||||
self.assertEqual(self.bits, self.t.bits)
|
||||
self.assertEqual(self.window_size, self.t.window_size)
|
||||
self.assertEqual(self.csum, self.t.csum)
|
||||
self.assertEqual(self.urgent, self.t.urgent)
|
||||
self.assertEqual(self.option, self.t.option)
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = self.t.parser(self.buf)
|
||||
|
||||
eq_(self.src_port, r1.src_port)
|
||||
eq_(self.dst_port, r1.dst_port)
|
||||
eq_(self.seq, r1.seq)
|
||||
eq_(self.ack, r1.ack)
|
||||
eq_(self.offset, r1.offset)
|
||||
eq_(self.bits, r1.bits)
|
||||
eq_(self.window_size, r1.window_size)
|
||||
eq_(self.csum, r1.csum)
|
||||
eq_(self.urgent, r1.urgent)
|
||||
eq_(self.option, r1.option)
|
||||
eq_(None, r2)
|
||||
self.assertEqual(self.src_port, r1.src_port)
|
||||
self.assertEqual(self.dst_port, r1.dst_port)
|
||||
self.assertEqual(self.seq, r1.seq)
|
||||
self.assertEqual(self.ack, r1.ack)
|
||||
self.assertEqual(self.offset, r1.offset)
|
||||
self.assertEqual(self.bits, r1.bits)
|
||||
self.assertEqual(self.window_size, r1.window_size)
|
||||
self.assertEqual(self.csum, r1.csum)
|
||||
self.assertEqual(self.urgent, r1.urgent)
|
||||
self.assertEqual(self.option, r1.option)
|
||||
self.assertEqual(None, r2)
|
||||
|
||||
def test_serialize(self):
|
||||
offset = 5
|
||||
@ -99,20 +98,20 @@ class Test_tcp(unittest.TestCase):
|
||||
buf = t.serialize(bytearray(), prev)
|
||||
res = struct.unpack(tcp.tcp._PACK_STR, six.binary_type(buf))
|
||||
|
||||
eq_(res[0], self.src_port)
|
||||
eq_(res[1], self.dst_port)
|
||||
eq_(res[2], self.seq)
|
||||
eq_(res[3], self.ack)
|
||||
eq_(res[4], offset << 4)
|
||||
eq_(res[5], self.bits)
|
||||
eq_(res[6], self.window_size)
|
||||
eq_(res[8], self.urgent)
|
||||
self.assertEqual(res[0], self.src_port)
|
||||
self.assertEqual(res[1], self.dst_port)
|
||||
self.assertEqual(res[2], self.seq)
|
||||
self.assertEqual(res[3], self.ack)
|
||||
self.assertEqual(res[4], offset << 4)
|
||||
self.assertEqual(res[5], self.bits)
|
||||
self.assertEqual(res[6], self.window_size)
|
||||
self.assertEqual(res[8], self.urgent)
|
||||
|
||||
# test __len__
|
||||
# offset indicates the number of 32 bit (= 4 bytes)
|
||||
# words in the TCP Header.
|
||||
# So, we compare len(tcp) with offset * 4, here.
|
||||
eq_(offset * 4, len(t))
|
||||
self.assertEqual(offset * 4, len(t))
|
||||
|
||||
# checksum
|
||||
ph = struct.pack('!4s4sBBH',
|
||||
@ -120,7 +119,7 @@ class Test_tcp(unittest.TestCase):
|
||||
addrconv.ipv4.text_to_bin(dst_ip), 0, 6, offset * 4)
|
||||
d = ph + buf
|
||||
s = packet_utils.checksum(d)
|
||||
eq_(0, s)
|
||||
self.assertEqual(0, s)
|
||||
|
||||
def test_serialize_option(self):
|
||||
# prepare test data
|
||||
@ -149,16 +148,15 @@ class Test_tcp(unittest.TestCase):
|
||||
option)
|
||||
buf = t.serialize(bytearray(), prev)
|
||||
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
|
||||
(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):
|
||||
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):
|
||||
prev = ipv4(proto=inet.IPPROTO_TCP)
|
||||
@ -166,49 +164,49 @@ class Test_tcp(unittest.TestCase):
|
||||
buf = t.serialize(bytearray(), prev)
|
||||
res = struct.unpack(tcp.tcp._PACK_STR, buf)
|
||||
|
||||
eq_(res[0], 1)
|
||||
eq_(res[1], 1)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], 0)
|
||||
eq_(res[4], 5 << 4)
|
||||
eq_(res[5], 0)
|
||||
eq_(res[6], 0)
|
||||
eq_(res[8], 0)
|
||||
self.assertEqual(res[0], 1)
|
||||
self.assertEqual(res[1], 1)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], 0)
|
||||
self.assertEqual(res[4], 5 << 4)
|
||||
self.assertEqual(res[5], 0)
|
||||
self.assertEqual(res[6], 0)
|
||||
self.assertEqual(res[8], 0)
|
||||
|
||||
# with option, without offset
|
||||
t = tcp.tcp(option=[tcp.TCPOptionMaximumSegmentSize(1460)])
|
||||
buf = t.serialize(bytearray(), prev)
|
||||
res = struct.unpack(tcp.tcp._PACK_STR + '4s', buf)
|
||||
|
||||
eq_(res[0], 1)
|
||||
eq_(res[1], 1)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], 0)
|
||||
eq_(res[4], 6 << 4)
|
||||
eq_(res[5], 0)
|
||||
eq_(res[6], 0)
|
||||
eq_(res[8], 0)
|
||||
eq_(res[9], b'\x02\x04\x05\xb4')
|
||||
self.assertEqual(res[0], 1)
|
||||
self.assertEqual(res[1], 1)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], 0)
|
||||
self.assertEqual(res[4], 6 << 4)
|
||||
self.assertEqual(res[5], 0)
|
||||
self.assertEqual(res[6], 0)
|
||||
self.assertEqual(res[8], 0)
|
||||
self.assertEqual(res[9], b'\x02\x04\x05\xb4')
|
||||
|
||||
# with option, with long offset
|
||||
t = tcp.tcp(offset=7, option=[tcp.TCPOptionWindowScale(shift_cnt=9)])
|
||||
buf = t.serialize(bytearray(), prev)
|
||||
res = struct.unpack(tcp.tcp._PACK_STR + '8s', buf)
|
||||
|
||||
eq_(res[0], 1)
|
||||
eq_(res[1], 1)
|
||||
eq_(res[2], 0)
|
||||
eq_(res[3], 0)
|
||||
eq_(res[4], 7 << 4)
|
||||
eq_(res[5], 0)
|
||||
eq_(res[6], 0)
|
||||
eq_(res[8], 0)
|
||||
eq_(res[9], b'\x03\x03\x09\x00\x00\x00\x00\x00')
|
||||
self.assertEqual(res[0], 1)
|
||||
self.assertEqual(res[1], 1)
|
||||
self.assertEqual(res[2], 0)
|
||||
self.assertEqual(res[3], 0)
|
||||
self.assertEqual(res[4], 7 << 4)
|
||||
self.assertEqual(res[5], 0)
|
||||
self.assertEqual(res[6], 0)
|
||||
self.assertEqual(res[8], 0)
|
||||
self.assertEqual(res[9], b'\x03\x03\x09\x00\x00\x00\x00\x00')
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.t.to_jsondict()
|
||||
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):
|
||||
@ -250,7 +248,7 @@ class Test_TCPOption(unittest.TestCase):
|
||||
output_buf = bytearray()
|
||||
for option in self.input_options:
|
||||
output_buf += option.serialize()
|
||||
eq_(self.input_buf, output_buf)
|
||||
self.assertEqual(self.input_buf, output_buf)
|
||||
|
||||
def test_parser(self):
|
||||
buf = self.input_buf
|
||||
@ -258,10 +256,10 @@ class Test_TCPOption(unittest.TestCase):
|
||||
while buf:
|
||||
opt, buf = tcp.TCPOption.parser(buf)
|
||||
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):
|
||||
for option in self.input_options:
|
||||
json_dict = option.to_jsondict()[option.__class__.__name__]
|
||||
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 struct
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import ether, inet
|
||||
from os_ken.lib.packet.packet import Packet
|
||||
from os_ken.lib.packet.udp import udp
|
||||
@ -48,19 +47,19 @@ class Test_udp(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.src_port, self.u.src_port)
|
||||
eq_(self.dst_port, self.u.dst_port)
|
||||
eq_(self.total_length, self.u.total_length)
|
||||
eq_(self.csum, self.u.csum)
|
||||
self.assertEqual(self.src_port, self.u.src_port)
|
||||
self.assertEqual(self.dst_port, self.u.dst_port)
|
||||
self.assertEqual(self.total_length, self.u.total_length)
|
||||
self.assertEqual(self.csum, self.u.csum)
|
||||
|
||||
def test_parser(self):
|
||||
r1, r2, _ = self.u.parser(self.buf)
|
||||
|
||||
eq_(self.src_port, r1.src_port)
|
||||
eq_(self.dst_port, r1.dst_port)
|
||||
eq_(self.total_length, r1.total_length)
|
||||
eq_(self.csum, r1.csum)
|
||||
eq_(None, r2)
|
||||
self.assertEqual(self.src_port, r1.src_port)
|
||||
self.assertEqual(self.dst_port, r1.dst_port)
|
||||
self.assertEqual(self.total_length, r1.total_length)
|
||||
self.assertEqual(self.csum, r1.csum)
|
||||
self.assertEqual(None, r2)
|
||||
|
||||
def test_serialize(self):
|
||||
src_port = 6431
|
||||
@ -77,9 +76,9 @@ class Test_udp(unittest.TestCase):
|
||||
buf = u.serialize(bytearray(), prev)
|
||||
res = struct.unpack(udp._PACK_STR, buf)
|
||||
|
||||
eq_(res[0], src_port)
|
||||
eq_(res[1], dst_port)
|
||||
eq_(res[2], struct.calcsize(udp._PACK_STR))
|
||||
self.assertEqual(res[0], src_port)
|
||||
self.assertEqual(res[1], dst_port)
|
||||
self.assertEqual(res[2], struct.calcsize(udp._PACK_STR))
|
||||
|
||||
# checksum
|
||||
ph = struct.pack('!4s4sBBH',
|
||||
@ -87,12 +86,11 @@ class Test_udp(unittest.TestCase):
|
||||
addrconv.ipv4.text_to_bin(dst_ip), 0, 17, res[2])
|
||||
d = ph + buf + bytearray()
|
||||
s = packet_utils.checksum(d)
|
||||
eq_(0, s)
|
||||
self.assertEqual(0, s)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_udp(self):
|
||||
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):
|
||||
prev = ipv4(proto=inet.IPPROTO_UDP)
|
||||
@ -100,11 +98,11 @@ class Test_udp(unittest.TestCase):
|
||||
buf = u.serialize(bytearray(), prev)
|
||||
res = struct.unpack(udp._PACK_STR, buf)
|
||||
|
||||
eq_(res[0], 1)
|
||||
eq_(res[1], 1)
|
||||
eq_(res[2], udp._MIN_LEN)
|
||||
self.assertEqual(res[0], 1)
|
||||
self.assertEqual(res[1], 1)
|
||||
self.assertEqual(res[2], udp._MIN_LEN)
|
||||
|
||||
def test_json(self):
|
||||
jsondict = self.u.to_jsondict()
|
||||
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 struct
|
||||
from struct import *
|
||||
from nose.tools import *
|
||||
from os_ken.ofproto import ether, inet
|
||||
from os_ken.lib.packet.ethernet import ethernet
|
||||
from os_ken.lib.packet.packet import Packet
|
||||
@ -57,19 +56,19 @@ class Test_vlan(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.pcp, self.v.pcp)
|
||||
eq_(self.cfi, self.v.cfi)
|
||||
eq_(self.vid, self.v.vid)
|
||||
eq_(self.ethertype, self.v.ethertype)
|
||||
self.assertEqual(self.pcp, self.v.pcp)
|
||||
self.assertEqual(self.cfi, self.v.cfi)
|
||||
self.assertEqual(self.vid, self.v.vid)
|
||||
self.assertEqual(self.ethertype, self.v.ethertype)
|
||||
|
||||
def test_parser(self):
|
||||
res, ptype, _ = self.v.parser(self.buf)
|
||||
|
||||
eq_(res.pcp, self.pcp)
|
||||
eq_(res.cfi, self.cfi)
|
||||
eq_(res.vid, self.vid)
|
||||
eq_(res.ethertype, self.ethertype)
|
||||
eq_(ptype, ipv4)
|
||||
self.assertEqual(res.pcp, self.pcp)
|
||||
self.assertEqual(res.cfi, self.cfi)
|
||||
self.assertEqual(res.vid, self.vid)
|
||||
self.assertEqual(res.ethertype, self.ethertype)
|
||||
self.assertEqual(ptype, ipv4)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -79,8 +78,8 @@ class Test_vlan(unittest.TestCase):
|
||||
fmt = vlan._PACK_STR
|
||||
res = struct.unpack(fmt, buf)
|
||||
|
||||
eq_(res[0], self.tci)
|
||||
eq_(res[1], self.ethertype)
|
||||
self.assertEqual(res[0], self.tci)
|
||||
self.assertEqual(res[1], self.ethertype)
|
||||
|
||||
def _build_vlan(self):
|
||||
src_mac = '00:07:0d:af:f4:54'
|
||||
@ -117,30 +116,29 @@ class Test_vlan(unittest.TestCase):
|
||||
p = self._build_vlan()
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021Q)
|
||||
|
||||
v = self.find_protocol(p, "vlan")
|
||||
ok_(v)
|
||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(v)
|
||||
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
ip = self.find_protocol(p, "ipv4")
|
||||
ok_(ip)
|
||||
self.assertTrue(ip)
|
||||
|
||||
eq_(v.pcp, self.pcp)
|
||||
eq_(v.cfi, self.cfi)
|
||||
eq_(v.vid, self.vid)
|
||||
eq_(v.ethertype, self.ethertype)
|
||||
self.assertEqual(v.pcp, self.pcp)
|
||||
self.assertEqual(v.cfi, self.cfi)
|
||||
self.assertEqual(v.vid, self.vid)
|
||||
self.assertEqual(v.ethertype, self.ethertype)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_vlan(self):
|
||||
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):
|
||||
jsondict = self.v.to_jsondict()
|
||||
v = vlan.from_jsondict(jsondict['vlan'])
|
||||
eq_(str(self.v), str(v))
|
||||
self.assertEqual(str(self.v), str(v))
|
||||
|
||||
|
||||
class Test_svlan(unittest.TestCase):
|
||||
@ -167,19 +165,19 @@ class Test_svlan(unittest.TestCase):
|
||||
return p
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.pcp, self.sv.pcp)
|
||||
eq_(self.cfi, self.sv.cfi)
|
||||
eq_(self.vid, self.sv.vid)
|
||||
eq_(self.ethertype, self.sv.ethertype)
|
||||
self.assertEqual(self.pcp, self.sv.pcp)
|
||||
self.assertEqual(self.cfi, self.sv.cfi)
|
||||
self.assertEqual(self.vid, self.sv.vid)
|
||||
self.assertEqual(self.ethertype, self.sv.ethertype)
|
||||
|
||||
def test_parser(self):
|
||||
res, ptype, _ = self.sv.parser(self.buf)
|
||||
|
||||
eq_(res.pcp, self.pcp)
|
||||
eq_(res.cfi, self.cfi)
|
||||
eq_(res.vid, self.vid)
|
||||
eq_(res.ethertype, self.ethertype)
|
||||
eq_(ptype, vlan)
|
||||
self.assertEqual(res.pcp, self.pcp)
|
||||
self.assertEqual(res.cfi, self.cfi)
|
||||
self.assertEqual(res.vid, self.vid)
|
||||
self.assertEqual(res.ethertype, self.ethertype)
|
||||
self.assertEqual(ptype, vlan)
|
||||
|
||||
def test_serialize(self):
|
||||
data = bytearray()
|
||||
@ -189,8 +187,8 @@ class Test_svlan(unittest.TestCase):
|
||||
fmt = svlan._PACK_STR
|
||||
res = struct.unpack(fmt, buf)
|
||||
|
||||
eq_(res[0], self.tci)
|
||||
eq_(res[1], self.ethertype)
|
||||
self.assertEqual(res[0], self.tci)
|
||||
self.assertEqual(res[1], self.ethertype)
|
||||
|
||||
def _build_svlan(self):
|
||||
src_mac = '00:07:0d:af:f4:54'
|
||||
@ -235,31 +233,30 @@ class Test_svlan(unittest.TestCase):
|
||||
p = self._build_svlan()
|
||||
|
||||
e = self.find_protocol(p, "ethernet")
|
||||
ok_(e)
|
||||
eq_(e.ethertype, ether.ETH_TYPE_8021AD)
|
||||
self.assertTrue(e)
|
||||
self.assertEqual(e.ethertype, ether.ETH_TYPE_8021AD)
|
||||
|
||||
sv = self.find_protocol(p, "svlan")
|
||||
ok_(sv)
|
||||
eq_(sv.ethertype, ether.ETH_TYPE_8021Q)
|
||||
self.assertTrue(sv)
|
||||
self.assertEqual(sv.ethertype, ether.ETH_TYPE_8021Q)
|
||||
|
||||
v = self.find_protocol(p, "vlan")
|
||||
ok_(v)
|
||||
eq_(v.ethertype, ether.ETH_TYPE_IP)
|
||||
self.assertTrue(v)
|
||||
self.assertEqual(v.ethertype, ether.ETH_TYPE_IP)
|
||||
|
||||
ip = self.find_protocol(p, "ipv4")
|
||||
ok_(ip)
|
||||
self.assertTrue(ip)
|
||||
|
||||
eq_(sv.pcp, self.pcp)
|
||||
eq_(sv.cfi, self.cfi)
|
||||
eq_(sv.vid, self.vid)
|
||||
eq_(sv.ethertype, self.ethertype)
|
||||
self.assertEqual(sv.pcp, self.pcp)
|
||||
self.assertEqual(sv.cfi, self.cfi)
|
||||
self.assertEqual(sv.vid, self.vid)
|
||||
self.assertEqual(sv.ethertype, self.ethertype)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_svlan(self):
|
||||
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):
|
||||
jsondict = self.sv.to_jsondict()
|
||||
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 inspect
|
||||
|
||||
from nose.tools import eq_, ok_
|
||||
from nose.tools import raises
|
||||
|
||||
from os_ken.ofproto import inet
|
||||
from os_ken.lib.packet import ipv4
|
||||
from os_ken.lib.packet import ipv6
|
||||
@ -66,30 +63,30 @@ class Test_vrrpv2(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.vrrpv2.type)
|
||||
eq_(self.vrid, self.vrrpv2.vrid)
|
||||
eq_(self.priority, self.vrrpv2.priority)
|
||||
eq_(self.count_ip, self.vrrpv2.count_ip)
|
||||
eq_(self.auth_type, self.vrrpv2.auth_type)
|
||||
eq_(1, len(self.vrrpv2.ip_addresses))
|
||||
eq_(self.ip_address, self.vrrpv2.ip_addresses[0])
|
||||
eq_(self.auth_data, self.vrrpv2.auth_data)
|
||||
self.assertEqual(self.type_, self.vrrpv2.type)
|
||||
self.assertEqual(self.vrid, self.vrrpv2.vrid)
|
||||
self.assertEqual(self.priority, self.vrrpv2.priority)
|
||||
self.assertEqual(self.count_ip, self.vrrpv2.count_ip)
|
||||
self.assertEqual(self.auth_type, self.vrrpv2.auth_type)
|
||||
self.assertEqual(1, len(self.vrrpv2.ip_addresses))
|
||||
self.assertEqual(self.ip_address, self.vrrpv2.ip_addresses[0])
|
||||
self.assertEqual(self.auth_data, self.vrrpv2.auth_data)
|
||||
|
||||
def test_parser(self):
|
||||
vrrpv2, _cls, _ = self.vrrpv2.parser(self.buf)
|
||||
|
||||
eq_(self.version, vrrpv2.version)
|
||||
eq_(self.type_, vrrpv2.type)
|
||||
eq_(self.vrid, vrrpv2.vrid)
|
||||
eq_(self.priority, vrrpv2.priority)
|
||||
eq_(self.count_ip, vrrpv2.count_ip)
|
||||
eq_(self.auth_type, vrrpv2.auth_type)
|
||||
eq_(self.max_adver_int, vrrpv2.max_adver_int)
|
||||
eq_(self.checksum, vrrpv2.checksum)
|
||||
eq_(1, len(vrrpv2.ip_addresses))
|
||||
eq_(str, type(vrrpv2.ip_addresses[0]))
|
||||
eq_(self.ip_address, vrrpv2.ip_addresses[0])
|
||||
eq_(self.auth_data, vrrpv2.auth_data)
|
||||
self.assertEqual(self.version, vrrpv2.version)
|
||||
self.assertEqual(self.type_, vrrpv2.type)
|
||||
self.assertEqual(self.vrid, vrrpv2.vrid)
|
||||
self.assertEqual(self.priority, vrrpv2.priority)
|
||||
self.assertEqual(self.count_ip, vrrpv2.count_ip)
|
||||
self.assertEqual(self.auth_type, vrrpv2.auth_type)
|
||||
self.assertEqual(self.max_adver_int, vrrpv2.max_adver_int)
|
||||
self.assertEqual(self.checksum, vrrpv2.checksum)
|
||||
self.assertEqual(1, len(vrrpv2.ip_addresses))
|
||||
self.assertEqual(str, type(vrrpv2.ip_addresses[0]))
|
||||
self.assertEqual(self.ip_address, vrrpv2.ip_addresses[0])
|
||||
self.assertEqual(self.auth_data, vrrpv2.auth_data)
|
||||
|
||||
def test_serialize(self):
|
||||
src_ip = '192.168.0.1'
|
||||
@ -111,26 +108,25 @@ class Test_vrrpv2(unittest.TestCase):
|
||||
pack_str = vrrp.vrrpv2._PACK_STR + '4sII'
|
||||
pack_len = struct.calcsize(pack_str)
|
||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_))
|
||||
eq_(res[1], vrid)
|
||||
eq_(res[2], priority)
|
||||
eq_(res[3], len(ip_addresses))
|
||||
eq_(res[4], vrrp.VRRP_AUTH_NO_AUTH)
|
||||
eq_(res[5], max_adver_int)
|
||||
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V2, type_))
|
||||
self.assertEqual(res[1], vrid)
|
||||
self.assertEqual(res[2], priority)
|
||||
self.assertEqual(res[3], len(ip_addresses))
|
||||
self.assertEqual(res[4], vrrp.VRRP_AUTH_NO_AUTH)
|
||||
self.assertEqual(res[5], max_adver_int)
|
||||
# res[6] is checksum
|
||||
eq_(res[7], addrconv.ipv4.text_to_bin(ip_address))
|
||||
eq_(res[8], 0)
|
||||
eq_(res[9], 0)
|
||||
eq_(len(buf), pack_len)
|
||||
self.assertEqual(res[7], addrconv.ipv4.text_to_bin(ip_address))
|
||||
self.assertEqual(res[8], 0)
|
||||
self.assertEqual(res[9], 0)
|
||||
self.assertEqual(len(buf), pack_len)
|
||||
|
||||
# checksum
|
||||
s = packet_utils.checksum(buf)
|
||||
eq_(0, s)
|
||||
self.assertEqual(0, s)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_vrrpv2(self):
|
||||
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):
|
||||
primary_ip = '192.168.0.2'
|
||||
@ -138,7 +134,7 @@ class Test_vrrpv2(unittest.TestCase):
|
||||
p0.serialize()
|
||||
p1 = packet.Packet(six.binary_type(p0.data))
|
||||
p1.serialize()
|
||||
eq_(p0.data, p1.data)
|
||||
self.assertEqual(p0.data, p1.data)
|
||||
|
||||
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
||||
max_adver_int=None):
|
||||
@ -156,34 +152,34 @@ class Test_vrrpv2(unittest.TestCase):
|
||||
return vrrp_.is_valid()
|
||||
|
||||
def test_is_valid_ok(self):
|
||||
ok_(self._test_is_valid())
|
||||
self.assertTrue(self._test_is_valid())
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
vrrpv2_values = {'version': self.version,
|
||||
@ -202,8 +198,8 @@ class Test_vrrpv2(unittest.TestCase):
|
||||
if k in vrrpv2_values])
|
||||
vrrpv2_str = '%s(%s)' % (vrrp.vrrpv2.__name__, _vrrpv2_str)
|
||||
|
||||
eq_(str(self.vrrpv2), vrrpv2_str)
|
||||
eq_(repr(self.vrrpv2), vrrpv2_str)
|
||||
self.assertEqual(str(self.vrrpv2), vrrpv2_str)
|
||||
self.assertEqual(repr(self.vrrpv2), vrrpv2_str)
|
||||
|
||||
|
||||
class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
@ -232,26 +228,26 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.vrrpv3.type)
|
||||
eq_(self.vrid, self.vrrpv3.vrid)
|
||||
eq_(self.priority, self.vrrpv3.priority)
|
||||
eq_(self.count_ip, self.vrrpv3.count_ip)
|
||||
eq_(1, len(self.vrrpv3.ip_addresses))
|
||||
eq_(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||
self.assertEqual(self.type_, self.vrrpv3.type)
|
||||
self.assertEqual(self.vrid, self.vrrpv3.vrid)
|
||||
self.assertEqual(self.priority, self.vrrpv3.priority)
|
||||
self.assertEqual(self.count_ip, self.vrrpv3.count_ip)
|
||||
self.assertEqual(1, len(self.vrrpv3.ip_addresses))
|
||||
self.assertEqual(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||
|
||||
def test_parser(self):
|
||||
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
||||
|
||||
eq_(self.version, vrrpv3.version)
|
||||
eq_(self.type_, vrrpv3.type)
|
||||
eq_(self.vrid, vrrpv3.vrid)
|
||||
eq_(self.priority, vrrpv3.priority)
|
||||
eq_(self.count_ip, vrrpv3.count_ip)
|
||||
eq_(self.max_adver_int, vrrpv3.max_adver_int)
|
||||
eq_(self.checksum, vrrpv3.checksum)
|
||||
eq_(1, len(vrrpv3.ip_addresses))
|
||||
eq_(str, type(vrrpv3.ip_addresses[0]))
|
||||
eq_(self.ip_address, vrrpv3.ip_addresses[0])
|
||||
self.assertEqual(self.version, vrrpv3.version)
|
||||
self.assertEqual(self.type_, vrrpv3.type)
|
||||
self.assertEqual(self.vrid, vrrpv3.vrid)
|
||||
self.assertEqual(self.priority, vrrpv3.priority)
|
||||
self.assertEqual(self.count_ip, vrrpv3.count_ip)
|
||||
self.assertEqual(self.max_adver_int, vrrpv3.max_adver_int)
|
||||
self.assertEqual(self.checksum, vrrpv3.checksum)
|
||||
self.assertEqual(1, len(vrrpv3.ip_addresses))
|
||||
self.assertEqual(str, type(vrrpv3.ip_addresses[0]))
|
||||
self.assertEqual(self.ip_address, vrrpv3.ip_addresses[0])
|
||||
|
||||
def test_serialize(self):
|
||||
src_ip = '192.168.0.1'
|
||||
@ -274,14 +270,14 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
pack_str = vrrp.vrrpv3._PACK_STR + '4s'
|
||||
pack_len = struct.calcsize(pack_str)
|
||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||
eq_(res[1], vrid)
|
||||
eq_(res[2], priority)
|
||||
eq_(res[3], len(ip_addresses))
|
||||
eq_(res[4], max_adver_int)
|
||||
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||
self.assertEqual(res[1], vrid)
|
||||
self.assertEqual(res[2], priority)
|
||||
self.assertEqual(res[3], len(ip_addresses))
|
||||
self.assertEqual(res[4], max_adver_int)
|
||||
# res[5] is checksum
|
||||
eq_(res[6], addrconv.ipv4.text_to_bin(ip_address))
|
||||
eq_(len(buf), pack_len)
|
||||
self.assertEqual(res[6], addrconv.ipv4.text_to_bin(ip_address))
|
||||
self.assertEqual(len(buf), pack_len)
|
||||
print(res)
|
||||
|
||||
# checksum
|
||||
@ -290,12 +286,11 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
addrconv.ipv4.text_to_bin(dst_ip),
|
||||
inet.IPPROTO_VRRP, pack_len)
|
||||
s = packet_utils.checksum(ph + buf)
|
||||
eq_(0, s)
|
||||
self.assertEqual(0, s)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_vrrpv3(self):
|
||||
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):
|
||||
primary_ip = '192.168.0.2'
|
||||
@ -303,7 +298,7 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
p0.serialize()
|
||||
p1 = packet.Packet(six.binary_type(p0.data))
|
||||
p1.serialize()
|
||||
eq_(p0.data, p1.data)
|
||||
self.assertEqual(p0.data, p1.data)
|
||||
|
||||
def _test_is_valid(self, type_=None, vrid=None, priority=None,
|
||||
max_adver_int=None):
|
||||
@ -321,34 +316,34 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
return vrrp_.is_valid()
|
||||
|
||||
def test_is_valid_ok(self):
|
||||
ok_(self._test_is_valid())
|
||||
self.assertTrue(self._test_is_valid())
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
vrrpv3_values = {'version': self.version,
|
||||
@ -367,8 +362,8 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
|
||||
if k in vrrpv3_values])
|
||||
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
||||
|
||||
eq_(str(self.vrrpv3), vrrpv3_str)
|
||||
eq_(repr(self.vrrpv3), vrrpv3_str)
|
||||
self.assertEqual(str(self.vrrpv3), vrrpv3_str)
|
||||
self.assertEqual(repr(self.vrrpv3), vrrpv3_str)
|
||||
|
||||
|
||||
class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
@ -397,26 +392,26 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.type_, self.vrrpv3.type)
|
||||
eq_(self.vrid, self.vrrpv3.vrid)
|
||||
eq_(self.priority, self.vrrpv3.priority)
|
||||
eq_(self.count_ip, self.vrrpv3.count_ip)
|
||||
eq_(1, len(self.vrrpv3.ip_addresses))
|
||||
eq_(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||
self.assertEqual(self.type_, self.vrrpv3.type)
|
||||
self.assertEqual(self.vrid, self.vrrpv3.vrid)
|
||||
self.assertEqual(self.priority, self.vrrpv3.priority)
|
||||
self.assertEqual(self.count_ip, self.vrrpv3.count_ip)
|
||||
self.assertEqual(1, len(self.vrrpv3.ip_addresses))
|
||||
self.assertEqual(self.ip_address, self.vrrpv3.ip_addresses[0])
|
||||
|
||||
def test_parser(self):
|
||||
vrrpv3, _cls, _ = self.vrrpv3.parser(self.buf)
|
||||
|
||||
eq_(self.version, vrrpv3.version)
|
||||
eq_(self.type_, vrrpv3.type)
|
||||
eq_(self.vrid, vrrpv3.vrid)
|
||||
eq_(self.priority, vrrpv3.priority)
|
||||
eq_(self.count_ip, vrrpv3.count_ip)
|
||||
eq_(self.max_adver_int, vrrpv3.max_adver_int)
|
||||
eq_(self.checksum, vrrpv3.checksum)
|
||||
eq_(1, len(vrrpv3.ip_addresses))
|
||||
eq_(str, type(vrrpv3.ip_addresses[0]))
|
||||
eq_(self.ip_address, vrrpv3.ip_addresses[0])
|
||||
self.assertEqual(self.version, vrrpv3.version)
|
||||
self.assertEqual(self.type_, vrrpv3.type)
|
||||
self.assertEqual(self.vrid, vrrpv3.vrid)
|
||||
self.assertEqual(self.priority, vrrpv3.priority)
|
||||
self.assertEqual(self.count_ip, vrrpv3.count_ip)
|
||||
self.assertEqual(self.max_adver_int, vrrpv3.max_adver_int)
|
||||
self.assertEqual(self.checksum, vrrpv3.checksum)
|
||||
self.assertEqual(1, len(vrrpv3.ip_addresses))
|
||||
self.assertEqual(str, type(vrrpv3.ip_addresses[0]))
|
||||
self.assertEqual(self.ip_address, vrrpv3.ip_addresses[0])
|
||||
|
||||
def test_serialize(self):
|
||||
src_ip = '2001:db8:2000::1'
|
||||
@ -439,14 +434,14 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
pack_str = vrrp.vrrpv3._PACK_STR + '16s'
|
||||
pack_len = struct.calcsize(pack_str)
|
||||
res = struct.unpack(pack_str, six.binary_type(buf))
|
||||
eq_(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||
eq_(res[1], vrid)
|
||||
eq_(res[2], priority)
|
||||
eq_(res[3], len(ip_addresses))
|
||||
eq_(res[4], max_adver_int)
|
||||
self.assertEqual(res[0], vrrp.vrrp_to_version_type(vrrp.VRRP_VERSION_V3, type_))
|
||||
self.assertEqual(res[1], vrid)
|
||||
self.assertEqual(res[2], priority)
|
||||
self.assertEqual(res[3], len(ip_addresses))
|
||||
self.assertEqual(res[4], max_adver_int)
|
||||
# res[5] is checksum
|
||||
eq_(res[6], addrconv.ipv6.text_to_bin(ip_address))
|
||||
eq_(len(buf), pack_len)
|
||||
self.assertEqual(res[6], addrconv.ipv6.text_to_bin(ip_address))
|
||||
self.assertEqual(len(buf), pack_len)
|
||||
print(res)
|
||||
|
||||
# checksum
|
||||
@ -455,12 +450,11 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
addrconv.ipv6.text_to_bin(dst_ip),
|
||||
pack_len, inet.IPPROTO_VRRP)
|
||||
s = packet_utils.checksum(ph + buf)
|
||||
eq_(0, s)
|
||||
self.assertEqual(0, s)
|
||||
|
||||
@raises(Exception)
|
||||
def test_malformed_vrrpv3(self):
|
||||
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):
|
||||
primary_ip = '2001:db8:2000::3'
|
||||
@ -471,7 +465,7 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
p1.serialize()
|
||||
print(len(p0.data), p0.data)
|
||||
print(len(p1.data), p1.data)
|
||||
eq_(p0.data, p1.data)
|
||||
self.assertEqual(p0.data, p1.data)
|
||||
|
||||
def test_to_string(self):
|
||||
vrrpv3_values = {'version': self.version,
|
||||
@ -490,5 +484,5 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
|
||||
if k in vrrpv3_values])
|
||||
vrrpv3_str = '%s(%s)' % (vrrp.vrrpv3.__name__, _vrrpv3_str)
|
||||
|
||||
eq_(str(self.vrrpv3), vrrpv3_str)
|
||||
eq_(repr(self.vrrpv3), vrrpv3_str)
|
||||
self.assertEqual(str(self.vrrpv3), vrrpv3_str)
|
||||
self.assertEqual(repr(self.vrrpv3), vrrpv3_str)
|
||||
|
@ -16,9 +16,6 @@
|
||||
import logging
|
||||
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 vxlan
|
||||
|
||||
@ -45,38 +42,37 @@ class Test_vxlan(unittest.TestCase):
|
||||
}
|
||||
|
||||
def test_init(self):
|
||||
eq_(self.vni, self.pkt.vni)
|
||||
self.assertEqual(self.vni, self.pkt.vni)
|
||||
|
||||
def test_parser(self):
|
||||
parsed_pkt, next_proto_cls, rest_buf = vxlan.vxlan.parser(self.buf)
|
||||
eq_(self.vni, parsed_pkt.vni)
|
||||
eq_(ethernet.ethernet, next_proto_cls)
|
||||
eq_(b'test_payload', rest_buf)
|
||||
self.assertEqual(self.vni, parsed_pkt.vni)
|
||||
self.assertEqual(ethernet.ethernet, next_proto_cls)
|
||||
self.assertEqual(b'test_payload', rest_buf)
|
||||
|
||||
@raises(AssertionError)
|
||||
def test_invalid_flags(self):
|
||||
invalid_flags_bug = (
|
||||
b'\x00\x00\x00\x00' # all bits are set to zero
|
||||
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):
|
||||
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):
|
||||
pkt_from_json = vxlan.vxlan.from_jsondict(
|
||||
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):
|
||||
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):
|
||||
vni = vxlan.vni_from_bin(b'\x12\x34\x56')
|
||||
eq_(self.vni, vni)
|
||||
self.assertEqual(self.vni, vni)
|
||||
|
||||
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
|
||||
from unittest import mock
|
||||
|
||||
from nose.tools import eq_
|
||||
from nose.tools import ok_
|
||||
from nose.tools import raises
|
||||
import six
|
||||
|
||||
from os_ken.lib import pcaplib
|
||||
@ -45,8 +42,7 @@ class Test_zebra(unittest.TestCase):
|
||||
Test case for os_ken.lib.packet.zebra.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def _test_pcap_single(f):
|
||||
def _test_pcap_single(self, f):
|
||||
zebra_pcap_file = os.path.join(PCAP_DATA_DIR, f + '.pcap')
|
||||
# print('*** testing %s' % zebra_pcap_file)
|
||||
|
||||
@ -55,15 +51,15 @@ class Test_zebra(unittest.TestCase):
|
||||
pkt = packet.Packet(buf)
|
||||
zebra_pkts = pkt.get_protocols(zebra.ZebraMessage)
|
||||
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)
|
||||
ok_(not isinstance(pkt.protocols[-1],
|
||||
self.assertTrue(not isinstance(pkt.protocols[-1],
|
||||
(six.binary_type, bytearray)),
|
||||
'Some messages could not be parsed in %s: %s' % (f, pkt))
|
||||
|
||||
# Checks if Zebra message can be serialized as expected.
|
||||
pkt.serialize()
|
||||
eq_(binary_str(buf), binary_str(pkt.data))
|
||||
self.assertEqual(binary_str(buf), binary_str(pkt.data))
|
||||
|
||||
def test_pcap_quagga(self):
|
||||
files = [
|
||||
@ -87,19 +83,17 @@ class Test_zebra(unittest.TestCase):
|
||||
class TestZebraMessage(unittest.TestCase):
|
||||
|
||||
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))
|
||||
eq_(zebra.ZebraMessage.V1_HEADER_SIZE,
|
||||
self.assertEqual(zebra.ZebraMessage.V1_HEADER_SIZE,
|
||||
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))
|
||||
eq_(zebra.ZebraMessage.V3_HEADER_SIZE,
|
||||
self.assertEqual(zebra.ZebraMessage.V3_HEADER_SIZE,
|
||||
zebra.ZebraMessage.get_header_size(4))
|
||||
|
||||
@raises(ValueError)
|
||||
def test_get_header_size_invalid_version(self):
|
||||
eq_(zebra.ZebraMessage.V0_HEADER_SIZE,
|
||||
zebra.ZebraMessage.get_header_size(0xff))
|
||||
self.assertRaises(ValueError, zebra.ZebraMessage.get_header_size, 0xff)
|
||||
|
||||
|
||||
class TestZebraRedistributeAdd(unittest.TestCase):
|
||||
@ -111,11 +105,11 @@ class TestZebraRedistributeAdd(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
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)
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraIPv4ImportLookup(unittest.TestCase):
|
||||
@ -131,14 +125,14 @@ class TestZebraIPv4ImportLookup(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraIPv4ImportLookup.parse(self.buf)
|
||||
|
||||
eq_(self.prefix, body.prefix)
|
||||
eq_(self.metric, body.metric)
|
||||
eq_(self.nexthop_num, len(body.nexthops))
|
||||
eq_(self.from_zebra, body.from_zebra)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
self.assertEqual(self.metric, body.metric)
|
||||
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||
self.assertEqual(self.from_zebra, body.from_zebra)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraIPv4ImportLookupFromZebra(unittest.TestCase):
|
||||
@ -159,16 +153,16 @@ class TestZebraIPv4ImportLookupFromZebra(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraIPv4ImportLookup.parse_from_zebra(self.buf)
|
||||
|
||||
eq_(self.prefix, body.prefix)
|
||||
eq_(self.metric, body.metric)
|
||||
eq_(self.nexthop_num, len(body.nexthops))
|
||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
||||
eq_(self.from_zebra, body.from_zebra)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
self.assertEqual(self.metric, body.metric)
|
||||
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||
self.assertEqual(self.from_zebra, body.from_zebra)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraIPv4NexthopLookupMRib(unittest.TestCase):
|
||||
@ -183,14 +177,14 @@ class TestZebraIPv4NexthopLookupMRib(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
||||
|
||||
eq_(self.addr, body.addr)
|
||||
eq_(self.distance, body.distance)
|
||||
eq_(self.metric, body.metric)
|
||||
eq_(self.nexthop_num, len(body.nexthops))
|
||||
self.assertEqual(self.addr, body.addr)
|
||||
self.assertEqual(self.distance, body.distance)
|
||||
self.assertEqual(self.metric, body.metric)
|
||||
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraIPv4NexthopLookupMRibFromZebra(unittest.TestCase):
|
||||
@ -212,16 +206,16 @@ class TestZebraIPv4NexthopLookupMRibFromZebra(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraIPv4NexthopLookupMRib.parse(self.buf)
|
||||
|
||||
eq_(self.addr, body.addr)
|
||||
eq_(self.distance, body.distance)
|
||||
eq_(self.metric, body.metric)
|
||||
eq_(self.nexthop_num, len(body.nexthops))
|
||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
||||
self.assertEqual(self.addr, body.addr)
|
||||
self.assertEqual(self.distance, body.distance)
|
||||
self.assertEqual(self.metric, body.metric)
|
||||
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraNexthopUpdateIPv6(unittest.TestCase):
|
||||
@ -246,16 +240,16 @@ class TestZebraNexthopUpdateIPv6(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraNexthopUpdate.parse(self.buf)
|
||||
|
||||
eq_(self.family, body.family)
|
||||
eq_(self.prefix, body.prefix)
|
||||
eq_(self.metric, body.metric)
|
||||
eq_(self.nexthop_num, len(body.nexthops))
|
||||
eq_(self.nexthop_type, body.nexthops[0].type)
|
||||
eq_(self.ifindex, body.nexthops[0].ifindex)
|
||||
self.assertEqual(self.family, body.family)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
self.assertEqual(self.metric, body.metric)
|
||||
self.assertEqual(self.nexthop_num, len(body.nexthops))
|
||||
self.assertEqual(self.nexthop_type, body.nexthops[0].type)
|
||||
self.assertEqual(self.ifindex, body.nexthops[0].ifindex)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraInterfaceNbrAddressAdd(unittest.TestCase):
|
||||
@ -273,13 +267,13 @@ class TestZebraInterfaceNbrAddressAdd(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraInterfaceNbrAddressAdd.parse(self.buf)
|
||||
|
||||
eq_(self.ifindex, body.ifindex)
|
||||
eq_(self.family, body.family)
|
||||
eq_(self.prefix, body.prefix)
|
||||
self.assertEqual(self.ifindex, body.ifindex)
|
||||
self.assertEqual(self.family, body.family)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraInterfaceBfdDestinationUpdate(unittest.TestCase):
|
||||
@ -304,16 +298,16 @@ class TestZebraInterfaceBfdDestinationUpdate(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraInterfaceBfdDestinationUpdate.parse(self.buf)
|
||||
|
||||
eq_(self.ifindex, body.ifindex)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.status, body.status)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.ifindex, body.ifindex)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.status, body.status)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationRegisterMultiHopEnabled(unittest.TestCase):
|
||||
@ -345,21 +339,21 @@ class TestZebraBfdDestinationRegisterMultiHopEnabled(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
||||
eq_(self.detect_mult, body.detect_mult)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationRegisterMultiHopDisabled(unittest.TestCase):
|
||||
@ -392,21 +386,21 @@ class TestZebraBfdDestinationRegisterMultiHopDisabled(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
||||
eq_(self.detect_mult, body.detect_mult)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationRegisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||
@ -444,21 +438,21 @@ class TestZebraBfdDestinationRegisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationRegister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.min_rx_timer, body.min_rx_timer)
|
||||
eq_(self.min_tx_timer, body.min_tx_timer)
|
||||
eq_(self.detect_mult, body.detect_mult)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.min_rx_timer, body.min_rx_timer)
|
||||
self.assertEqual(self.min_tx_timer, body.min_tx_timer)
|
||||
self.assertEqual(self.detect_mult, body.detect_mult)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationDeregisterMultiHopEnabled(unittest.TestCase):
|
||||
@ -484,18 +478,18 @@ class TestZebraBfdDestinationDeregisterMultiHopEnabled(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationDeregisterMultiHopDisabled(unittest.TestCase):
|
||||
@ -522,18 +516,18 @@ class TestZebraBfdDestinationDeregisterMultiHopDisabled(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraBfdDestinationDeregisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||
@ -565,18 +559,18 @@ class TestZebraBfdDestinationDeregisterMultiHopEnabledIPv6(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraBfdDestinationDeregister.parse(self.buf)
|
||||
|
||||
eq_(self.pid, body.pid)
|
||||
eq_(self.dst_family, body.dst_family)
|
||||
eq_(self.dst_prefix, body.dst_prefix)
|
||||
eq_(self.multi_hop, body.multi_hop)
|
||||
eq_(self.src_family, body.src_family)
|
||||
eq_(self.src_prefix, body.src_prefix)
|
||||
eq_(self.multi_hop_count, body.multi_hop_count)
|
||||
eq_(self.ifname, body.ifname)
|
||||
self.assertEqual(self.pid, body.pid)
|
||||
self.assertEqual(self.dst_family, body.dst_family)
|
||||
self.assertEqual(self.dst_prefix, body.dst_prefix)
|
||||
self.assertEqual(self.multi_hop, body.multi_hop)
|
||||
self.assertEqual(self.src_family, body.src_family)
|
||||
self.assertEqual(self.src_prefix, body.src_prefix)
|
||||
self.assertEqual(self.multi_hop_count, body.multi_hop_count)
|
||||
self.assertEqual(self.ifname, body.ifname)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraVrfAdd(unittest.TestCase):
|
||||
@ -597,11 +591,11 @@ class TestZebraVrfAdd(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraVrfAdd.parse(self.buf)
|
||||
|
||||
eq_(self.vrf_name, body.vrf_name)
|
||||
self.assertEqual(self.vrf_name, body.vrf_name)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraInterfaceVrfUpdate(unittest.TestCase):
|
||||
@ -616,12 +610,12 @@ class TestZebraInterfaceVrfUpdate(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraInterfaceVrfUpdate.parse(self.buf)
|
||||
|
||||
eq_(self.ifindex, body.ifindex)
|
||||
eq_(self.vrf_id, body.vrf_id)
|
||||
self.assertEqual(self.ifindex, body.ifindex)
|
||||
self.assertEqual(self.vrf_id, body.vrf_id)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraInterfaceEnableRadv(unittest.TestCase):
|
||||
@ -636,12 +630,12 @@ class TestZebraInterfaceEnableRadv(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraInterfaceEnableRadv.parse(self.buf)
|
||||
|
||||
eq_(self.ifindex, body.ifindex)
|
||||
eq_(self.interval, body.interval)
|
||||
self.assertEqual(self.ifindex, body.ifindex)
|
||||
self.assertEqual(self.interval, body.interval)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraMplsLabelsAddIPv4(unittest.TestCase):
|
||||
@ -667,17 +661,17 @@ class TestZebraMplsLabelsAddIPv4(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
||||
|
||||
eq_(self.route_type, body.route_type)
|
||||
eq_(self.family, body.family)
|
||||
eq_(self.prefix, body.prefix)
|
||||
eq_(self.gate_addr, body.gate_addr)
|
||||
eq_(self.distance, body.distance)
|
||||
eq_(self.in_label, body.in_label)
|
||||
eq_(self.out_label, body.out_label)
|
||||
self.assertEqual(self.route_type, body.route_type)
|
||||
self.assertEqual(self.family, body.family)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
self.assertEqual(self.gate_addr, body.gate_addr)
|
||||
self.assertEqual(self.distance, body.distance)
|
||||
self.assertEqual(self.in_label, body.in_label)
|
||||
self.assertEqual(self.out_label, body.out_label)
|
||||
|
||||
buf = body.serialize()
|
||||
|
||||
eq_(binary_str(self.buf), binary_str(buf))
|
||||
self.assertEqual(binary_str(self.buf), binary_str(buf))
|
||||
|
||||
|
||||
class TestZebraMplsLabelsAddIPv6(unittest.TestCase):
|
||||
@ -709,14 +703,14 @@ class TestZebraMplsLabelsAddIPv6(unittest.TestCase):
|
||||
def test_parser(self):
|
||||
body = zebra.ZebraMplsLabelsAdd.parse(self.buf)
|
||||
|
||||
eq_(self.route_type, body.route_type)
|
||||
eq_(self.family, body.family)
|
||||
eq_(self.prefix, body.prefix)
|
||||
eq_(self.gate_addr, body.gate_addr)
|
||||
eq_(self.distance, body.distance)
|
||||
eq_(self.in_label, body.in_label)
|
||||
eq_(self.out_label, body.out_label)
|
||||
self.assertEqual(self.route_type, body.route_type)
|
||||
self.assertEqual(self.family, body.family)
|
||||
self.assertEqual(self.prefix, body.prefix)
|
||||
self.assertEqual(self.gate_addr, body.gate_addr)
|
||||
self.assertEqual(self.distance, body.distance)
|
||||
self.assertEqual(self.in_label, body.in_label)
|
||||
self.assertEqual(self.out_label, body.out_label)
|
||||
|
||||
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
|
||||
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 BGPPathAttributeAsPath
|
||||
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_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 IP6AddrPrefix
|
||||
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 EvpnMacIPAdvertisementNLRI
|
||||
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 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_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_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_IPV4_FLOWSPEC
|
||||
from os_ken.services.protocols.bgp.utils.bgp import create_v4flowspec_actions
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -81,17 +70,17 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
|
||||
# Check
|
||||
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]
|
||||
ok_(len(args) == 0) # no positional argument
|
||||
eq_(str(prefix_inst), str(kwargs['nlri']))
|
||||
eq_(is_withdraw, kwargs['is_withdraw'])
|
||||
self.assertTrue(len(args) == 0) # no positional argument
|
||||
self.assertEqual(str(prefix_inst), str(kwargs['nlri']))
|
||||
self.assertEqual(is_withdraw, kwargs['is_withdraw'])
|
||||
if is_withdraw:
|
||||
eq_(None, kwargs['next_hop'])
|
||||
eq_(False, kwargs['gen_lbl'])
|
||||
self.assertEqual(None, kwargs['next_hop'])
|
||||
self.assertEqual(False, kwargs['gen_lbl'])
|
||||
else:
|
||||
eq_(next_hop, kwargs['next_hop'])
|
||||
eq_(True, kwargs['gen_lbl'])
|
||||
self.assertEqual(next_hop, kwargs['next_hop'])
|
||||
self.assertEqual(True, kwargs['gen_lbl'])
|
||||
|
||||
def test_update_vrf_table_ipv4(self):
|
||||
# Prepare test data
|
||||
@ -233,13 +222,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
|
||||
# Check
|
||||
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]
|
||||
ok_(len(args) == 0) # no positional argument
|
||||
eq_(str(prefix_inst), str(kwargs['nlri']))
|
||||
eq_(next_hop, kwargs['next_hop'])
|
||||
eq_(False, kwargs['gen_lbl']) # should not generate MPLS labels
|
||||
eq_(tunnel_type, kwargs['tunnel_type'])
|
||||
self.assertTrue(len(args) == 0) # no positional argument
|
||||
self.assertEqual(str(prefix_inst), str(kwargs['nlri']))
|
||||
self.assertEqual(next_hop, kwargs['next_hop'])
|
||||
self.assertEqual(
|
||||
False, kwargs['gen_lbl']) # should not generate MPLS labels
|
||||
self.assertEqual(tunnel_type, kwargs['tunnel_type'])
|
||||
|
||||
def test_update_vrf_table_ipv4_withdraw(self):
|
||||
# Prepare test data
|
||||
@ -257,7 +248,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
next_hop, route_family, route_type,
|
||||
is_withdraw=True, **kwargs)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||
mock.MagicMock(return_value=None))
|
||||
@ -277,15 +267,11 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
tbl_mng._tables = {} # no table
|
||||
|
||||
# Test
|
||||
tbl_mng.update_vrf_table(
|
||||
route_dist=route_dist,
|
||||
prefix=prefix_str,
|
||||
next_hop=next_hop,
|
||||
route_family=route_family,
|
||||
route_type=route_type,
|
||||
**kwargs)
|
||||
self.assertRaises(BgpCoreError, tbl_mng.update_vrf_table,
|
||||
route_dist=route_dist, prefix=prefix_str,
|
||||
next_hop=next_hop, route_family=route_family,
|
||||
route_type=route_type, **kwargs)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_vrf_table_invalid_next_hop(self):
|
||||
# Prepare test data
|
||||
route_dist = '65000:100'
|
||||
@ -298,11 +284,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
route_type = None # should be ignored
|
||||
kwargs = {} # should be ignored
|
||||
|
||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
||||
next_hop, route_family, route_type,
|
||||
**kwargs)
|
||||
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||
prefix_inst, route_dist, prefix_str, next_hop,
|
||||
route_family, route_type, **kwargs)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_vrf_table_invalid_ipv4_prefix(self):
|
||||
# Prepare test data
|
||||
route_dist = '65000:100'
|
||||
@ -315,11 +300,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
route_type = None # should be ignored
|
||||
kwargs = {} # should be ignored
|
||||
|
||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
||||
next_hop, route_family, route_type,
|
||||
**kwargs)
|
||||
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||
prefix_inst, route_dist, prefix_str,
|
||||
next_hop, route_family, route_type, **kwargs)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_vrf_table_invalid_ipv6_prefix(self):
|
||||
# Prepare test data
|
||||
route_dist = '65000:100'
|
||||
@ -332,11 +316,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
route_type = None # should be ignored
|
||||
kwargs = {} # should be ignored
|
||||
|
||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
||||
next_hop, route_family, route_type,
|
||||
**kwargs)
|
||||
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||
prefix_inst, route_dist, prefix_str, next_hop,
|
||||
route_family, route_type, **kwargs)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_vrf_table_invalid_route_family(self):
|
||||
# Prepare test data
|
||||
route_dist = '65000:100'
|
||||
@ -349,9 +332,9 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
route_type = None # should be ignored
|
||||
kwargs = {} # should be ignored
|
||||
|
||||
self._test_update_vrf_table(prefix_inst, route_dist, prefix_str,
|
||||
next_hop, route_family, route_type,
|
||||
**kwargs)
|
||||
self.assertRaises(BgpCoreError, self._test_update_vrf_table,
|
||||
prefix_inst, route_dist, prefix_str, next_hop,
|
||||
route_family, route_type, **kwargs)
|
||||
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||
@ -380,15 +363,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
|
||||
# Check
|
||||
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]
|
||||
ok_(len(kwargs) == 0) # no keyword argument
|
||||
self.assertTrue(len(kwargs) == 0) # no keyword argument
|
||||
output_path = args[0]
|
||||
eq_(None, output_path.source)
|
||||
eq_(prefix, output_path.nlri.prefix)
|
||||
eq_(pathattrs, str(output_path.pathattr_map))
|
||||
eq_(expected_next_hop, output_path.nexthop)
|
||||
eq_(is_withdraw, output_path.is_withdraw)
|
||||
self.assertEqual(None, output_path.source)
|
||||
self.assertEqual(prefix, output_path.nlri.prefix)
|
||||
self.assertEqual(pathattrs, str(output_path.pathattr_map))
|
||||
self.assertEqual(expected_next_hop, output_path.nexthop)
|
||||
self.assertEqual(is_withdraw, output_path.is_withdraw)
|
||||
|
||||
def test_update_global_table_ipv4(self):
|
||||
self._test_update_global_table(
|
||||
@ -460,12 +443,12 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
|
||||
# Check
|
||||
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
|
||||
args, kwargs = call_args_list[0]
|
||||
ok_(len(args) == 0) # no positional argument
|
||||
eq_(prefix, kwargs['nlri'].prefix)
|
||||
eq_(is_withdraw, kwargs['is_withdraw'])
|
||||
self.assertTrue(len(args) == 0) # no positional argument
|
||||
self.assertEqual(prefix, kwargs['nlri'].prefix)
|
||||
self.assertEqual(is_withdraw, kwargs['is_withdraw'])
|
||||
|
||||
def test_update_flowspec_vrf_table_vpnv4(self):
|
||||
flowspec_family = 'vpnv4fs'
|
||||
@ -510,7 +493,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
is_withdraw=False,
|
||||
)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_vpnv4_invalid_actions(self):
|
||||
flowspec_family = 'vpnv4fs'
|
||||
route_family = 'ipv4fs'
|
||||
@ -525,17 +507,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_vpnv4_invalid_flowspec_family(self):
|
||||
flowspec_family = 'invalid'
|
||||
route_family = 'ipv4fs'
|
||||
@ -545,16 +525,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_vpnv4_invalid_route_family(self):
|
||||
flowspec_family = 'vpnv4fs'
|
||||
route_family = 'invalid'
|
||||
@ -564,14 +542,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:10.70.1.0/24)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False)
|
||||
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.core_managers.TableCoreManager.__init__',
|
||||
@ -594,14 +571,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
|
||||
# Check
|
||||
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]
|
||||
ok_(len(kwargs) == 0) # no keyword argument
|
||||
self.assertTrue(len(kwargs) == 0) # no keyword argument
|
||||
output_path = args[0]
|
||||
eq_(None, output_path.source)
|
||||
eq_(prefix, output_path.nlri.prefix)
|
||||
eq_(None, output_path.nexthop)
|
||||
eq_(is_withdraw, output_path.is_withdraw)
|
||||
self.assertEqual(None, output_path.source)
|
||||
self.assertEqual(prefix, output_path.nlri.prefix)
|
||||
self.assertEqual(None, output_path.nexthop)
|
||||
self.assertEqual(is_withdraw, output_path.is_withdraw)
|
||||
|
||||
def test_update_flowspec_global_table_ipv4(self):
|
||||
flowspec_family = 'ipv4fs'
|
||||
@ -638,7 +615,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
is_withdraw=False,
|
||||
)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_global_table_ipv4_invalid_actions(self):
|
||||
flowspec_family = 'ipv4fs'
|
||||
rules = {
|
||||
@ -651,15 +627,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
||||
|
||||
self._test_update_flowspec_global_table(
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError,
|
||||
self._test_update_flowspec_global_table,
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_global_table_ipv4_invalid_flowspec_family(self):
|
||||
flowspec_family = 'invalid'
|
||||
rules = {
|
||||
@ -673,13 +648,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:10.60.1.0/24)'
|
||||
|
||||
self._test_update_flowspec_global_table(
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError,
|
||||
self._test_update_flowspec_global_table,
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
def test_update_flowspec_global_table_ipv6(self):
|
||||
flowspec_family = 'ipv6fs'
|
||||
@ -716,7 +691,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
is_withdraw=False,
|
||||
)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_global_table_ipv6_invalid_actions(self):
|
||||
flowspec_family = 'ipv6fs'
|
||||
rules = {
|
||||
@ -729,15 +703,14 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||
|
||||
self._test_update_flowspec_global_table(
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError,
|
||||
self._test_update_flowspec_global_table,
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_global_table_ipv6_invalid_flowspec_family(self):
|
||||
flowspec_family = 'invalid'
|
||||
rules = {
|
||||
@ -751,13 +724,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||
|
||||
self._test_update_flowspec_global_table(
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError,
|
||||
self._test_update_flowspec_global_table,
|
||||
flowspec_family=flowspec_family,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
def test_update_flowspec_vrf_table_vpnv6(self):
|
||||
flowspec_family = 'vpnv6fs'
|
||||
@ -802,7 +775,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
is_withdraw=False,
|
||||
)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_vpnv6_invalid_actions(self):
|
||||
flowspec_family = 'vpnv6fs'
|
||||
route_family = 'ipv6fs'
|
||||
@ -817,17 +789,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv6fs(dst_prefix:2001::3/128/32)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_vpnv6_invalid_route_family(self):
|
||||
flowspec_family = 'vpnv6fs'
|
||||
route_family = 'invalid'
|
||||
@ -837,14 +807,13 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'ipv4fs(dst_prefix:2001::3/128/32)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False)
|
||||
|
||||
def test_update_flowspec_vrf_table_l2vpn(self):
|
||||
flowspec_family = 'l2vpnfs'
|
||||
@ -889,7 +858,6 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
is_withdraw=False,
|
||||
)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_l2vpn_invalid_actions(self):
|
||||
flowspec_family = 'l2vpnfs'
|
||||
route_family = 'l2vpnfs'
|
||||
@ -904,17 +872,15 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
actions=actions)
|
||||
|
||||
@raises(BgpCoreError)
|
||||
def test_update_flowspec_vrf_table_l2vpn_invalid_route_family(self):
|
||||
flowspec_family = 'l2vpnfs'
|
||||
route_family = 'invalid'
|
||||
@ -924,11 +890,10 @@ class Test_TableCoreManager(unittest.TestCase):
|
||||
}
|
||||
prefix = 'l2vpnfs(dst_mac:12:34:56:78:9a:bc)'
|
||||
|
||||
self._test_update_flowspec_vrf_table(
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False,
|
||||
)
|
||||
self.assertRaises(BgpCoreError, self._test_update_flowspec_vrf_table,
|
||||
flowspec_family=flowspec_family,
|
||||
route_family=route_family,
|
||||
route_dist=route_dist,
|
||||
rules=rules,
|
||||
prefix=prefix,
|
||||
is_withdraw=False)
|
||||
|
@ -17,8 +17,6 @@ import logging
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from nose.tools import raises
|
||||
|
||||
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 ESI_TYPE_LACP
|
||||
@ -392,7 +390,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.add_local', **expected_kwargs)
|
||||
|
||||
@raises(ValueError)
|
||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
mock.MagicMock(return_value=None))
|
||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
||||
@ -408,19 +405,14 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
|
||||
# Test
|
||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||
speaker.evpn_prefix_add(
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
esi=esi,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
mac_addr=mac_addr,
|
||||
ip_addr=ip_addr,
|
||||
next_hop=next_hop,
|
||||
)
|
||||
|
||||
# Check
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.add_local', 'Invalid arguments detected')
|
||||
self.assertRaises(ValueError, speaker.evpn_prefix_add,
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
esi=esi,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
mac_addr=mac_addr,
|
||||
ip_addr=ip_addr,
|
||||
next_hop=next_hop)
|
||||
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
@ -523,7 +515,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.delete_local', **expected_kwargs)
|
||||
|
||||
@raises(ValueError)
|
||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
mock.MagicMock(return_value=None))
|
||||
@mock.patch('os_ken.services.protocols.bgp.bgpspeaker.call')
|
||||
@ -538,18 +529,13 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
|
||||
# Test
|
||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||
speaker.evpn_prefix_del(
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
esi=esi,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
mac_addr=mac_addr,
|
||||
ip_addr=ip_addr,
|
||||
)
|
||||
|
||||
# Check
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.delete_local', 'Invalid arguments detected')
|
||||
self.assertRaises(ValueError, speaker.evpn_prefix_del,
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
esi=esi,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
mac_addr=mac_addr,
|
||||
ip_addr=ip_addr)
|
||||
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
@ -684,7 +670,6 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.add_local', **expected_kwargs)
|
||||
|
||||
@raises(ValueError)
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
mock.MagicMock(return_value=None))
|
||||
@ -700,17 +685,12 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
|
||||
# Test
|
||||
speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
|
||||
speaker.evpn_prefix_add(
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
ip_addr=ip_addr,
|
||||
pmsi_tunnel_type=pmsi_tunnel_type,
|
||||
)
|
||||
|
||||
# Check
|
||||
mock_call.assert_called_with(
|
||||
'evpn_prefix.add_local', 'Invalid arguments detected')
|
||||
self.assertRaises(ValueError, speaker.evpn_prefix_add,
|
||||
route_type=route_type,
|
||||
route_dist=route_dist,
|
||||
ethernet_tag_id=ethernet_tag_id,
|
||||
ip_addr=ip_addr,
|
||||
pmsi_tunnel_type=pmsi_tunnel_type)
|
||||
|
||||
@mock.patch(
|
||||
'os_ken.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
|
||||
|
@ -17,8 +17,6 @@ import logging
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from nose.tools import eq_
|
||||
|
||||
from os_ken.lib.packet import bgp
|
||||
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(
|
||||
input_as_path_attr, input_as4_path_attr)
|
||||
|
||||
eq_(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||
eq_(expected_as_path, output_as_path_attr.path_seg_list)
|
||||
self.assertEqual(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||
self.assertEqual(expected_as_path, output_as_path_attr.path_seg_list)
|
||||
|
||||
def test_construct_as_path_attr_sequence_only(self):
|
||||
# Test Data
|
||||
@ -154,8 +152,8 @@ class Test_Peer(unittest.TestCase):
|
||||
output_as_path_attr = _peer._construct_as_path_attr(
|
||||
input_as_path_attr, input_as4_path_attr)
|
||||
|
||||
eq_(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||
eq_(expected_as_path, output_as_path_attr.path_seg_list)
|
||||
self.assertEqual(bgp.BGP_ATTR_TYPE_AS_PATH, output_as_path_attr.type)
|
||||
self.assertEqual(expected_as_path, output_as_path_attr.path_seg_list)
|
||||
|
||||
@mock.patch.object(
|
||||
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
||||
@ -167,8 +165,8 @@ class Test_Peer(unittest.TestCase):
|
||||
# TEST
|
||||
output_as_path, output_as4_path = _peer._trans_as_path(input_as_path)
|
||||
|
||||
eq_(expected_as_path, output_as_path)
|
||||
eq_(expected_as4_path, output_as4_path)
|
||||
self.assertEqual(expected_as_path, output_as_path)
|
||||
self.assertEqual(expected_as4_path, output_as4_path)
|
||||
|
||||
@mock.patch.object(
|
||||
peer.Peer, 'is_four_octet_as_number_cap_valid',
|
||||
@ -234,11 +232,11 @@ class Test_Peer(unittest.TestCase):
|
||||
as4_aggregator_attr = umsg_pattrs.get(
|
||||
bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR, None)
|
||||
|
||||
eq_(ex_as_path_value, as_path_attr.value)
|
||||
eq_(None, as4_path_attr)
|
||||
eq_(ex_aggregator_as_number, aggregator_attr.as_number)
|
||||
eq_(ex_aggregator_addr, aggregator_attr.addr)
|
||||
eq_(None, as4_aggregator_attr)
|
||||
self.assertEqual(ex_as_path_value, as_path_attr.value)
|
||||
self.assertEqual(None, as4_path_attr)
|
||||
self.assertEqual(ex_aggregator_as_number, aggregator_attr.as_number)
|
||||
self.assertEqual(ex_aggregator_addr, aggregator_attr.addr)
|
||||
self.assertEqual(None, as4_aggregator_attr)
|
||||
|
||||
@mock.patch.object(
|
||||
peer.Peer, '__init__', mock.MagicMock(return_value=None))
|
||||
|
@ -17,8 +17,6 @@
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from nose.tools import eq_, raises
|
||||
|
||||
from os_ken.lib.packet.bgp import (
|
||||
BGPFlowSpecTrafficRateCommunity,
|
||||
BGPFlowSpecTrafficActionCommunity,
|
||||
@ -28,7 +26,6 @@ from os_ken.lib.packet.bgp import (
|
||||
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_v6flowspec_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)
|
||||
expected_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):
|
||||
actions = {
|
||||
@ -78,7 +75,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
expected_communities = []
|
||||
self._test_create_v4flowspec_actions(actions, expected_communities)
|
||||
|
||||
@raises(ValueError)
|
||||
def test_create_v4flowspec_actions_not_exist_actions(self):
|
||||
actions = {
|
||||
'traffic_test': {
|
||||
@ -86,13 +82,14 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
},
|
||||
}
|
||||
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):
|
||||
communities = create_v6flowspec_actions(actions)
|
||||
expected_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):
|
||||
actions = {
|
||||
@ -124,7 +121,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
expected_communities = []
|
||||
self._test_create_v6flowspec_actions(actions, expected_communities)
|
||||
|
||||
@raises(ValueError)
|
||||
def test_create_v6flowspec_actions_not_exist_actions(self):
|
||||
actions = {
|
||||
'traffic_test': {
|
||||
@ -132,13 +128,14 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
},
|
||||
}
|
||||
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):
|
||||
communities = create_l2vpnflowspec_actions(actions)
|
||||
expected_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):
|
||||
actions = {
|
||||
@ -200,7 +197,6 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
expected_communities = []
|
||||
self._test_create_l2vpnflowspec_actions(actions, expected_communities)
|
||||
|
||||
@raises(ValueError)
|
||||
def test_create_l2vpnflowspec_actions_not_exist_actions(self):
|
||||
actions = {
|
||||
'traffic_test': {
|
||||
@ -208,4 +204,5 @@ class Test_Utils_BGP(unittest.TestCase):
|
||||
},
|
||||
}
|
||||
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 unittest
|
||||
|
||||
from nose.tools import eq_, ok_
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
eq_(False,
|
||||
self.assertEqual(
|
||||
False,
|
||||
validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff'))
|
||||
|
||||
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):
|
||||
ok_(validation.is_valid_old_asn(65000))
|
||||
self.assertTrue(validation.is_valid_old_asn(65000))
|
||||
|
||||
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):
|
||||
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):
|
||||
ok_(validation.is_valid_asn(6553800))
|
||||
self.assertTrue(validation.is_valid_asn(6553800))
|
||||
|
||||
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):
|
||||
eq_(False, validation.is_valid_asn(-1))
|
||||
self.assertEqual(False, validation.is_valid_asn(-1))
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
ok_(validation.is_valid_vpnv6_prefix(
|
||||
self.assertTrue(validation.is_valid_vpnv6_prefix(
|
||||
'100:200:fe80::0011:aabb:ccdd:eeff/64'))
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
ok_(validation.is_valid_med(100))
|
||||
self.assertTrue(validation.is_valid_med(100))
|
||||
|
||||
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):
|
||||
eq_(False, validation.is_valid_med(-1))
|
||||
self.assertEqual(False, validation.is_valid_med(-1))
|
||||
|
||||
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):
|
||||
ok_(validation.is_valid_mpls_label(100))
|
||||
self.assertTrue(validation.is_valid_mpls_label(100))
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
ok_(validation.is_valid_esi(100))
|
||||
self.assertTrue(validation.is_valid_esi(100))
|
||||
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
ok_(validation.is_valid_vni(100))
|
||||
self.assertTrue(validation.is_valid_vni(100))
|
||||
|
||||
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):
|
||||
eq_(False, validation.is_valid_vni(-1))
|
||||
self.assertEqual(False, validation.is_valid_vni(-1))
|
||||
|
||||
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
|
||||
eventlet>=0.26.1 # MIT
|
||||
msgpack>=1.0.0 # RPC library, BGP speaker(net_cntl)
|
||||
ncclient>=0.6.13 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
oslo.config>=5.1.0
|
||||
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
|
||||
stestr>=1.0.0 # Apache-2.0
|
||||
testtools>=2.2.0 # MIT
|
||||
nose>=1.3.7 # LGPL
|
||||
pycodestyle>=2.0.0 # MIT
|
||||
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
|
||||
|
||||
[testenv]
|
||||
basepython = python3
|
||||
basepython = {env:TOX_PYTHON:python3}
|
||||
usedevelop = True
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
@ -17,10 +17,8 @@ deps =
|
||||
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
# TODO(hongbin): this is the way Ryu runs unit tests and we inherit
|
||||
# this approach as a start. In the future, we should migrate to stestr
|
||||
# for consistency with other OpenStack projects.
|
||||
commands = python ./os_ken/tests/run_tests.py {posargs}
|
||||
commands =
|
||||
stestr run {posargs}
|
||||
|
||||
[testenv:pep8]
|
||||
commands = flake8 {posargs}
|
||||
@ -87,6 +85,7 @@ show-source = True
|
||||
# H104: Files with no code shouldn't contain any license header nor comments
|
||||
# H105: Don't use author tags. We use version control instead.
|
||||
# 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 (*)
|
||||
# H306: Alphabetically order your imports by the full module path
|
||||
# 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.
|
||||
# H501: Do not use ``locals()`` or ``self.__dict__`` for formatting strings
|
||||
# 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 = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,os_ken/contrib
|
||||
|
Loading…
Reference in New Issue
Block a user