Marc Bruyere | 31 Jul 10:54 2014
Picon
Picon

Rest API questions

Hi,

I am trying to add a couple of flows using ofctl_rest.py with curl like 
that one :

curl -X POST -d '{"cookie": "1","dpid": 0x9b9de89a8ffbc388,"priority": 
"23999","match": {"in_port": 
"1"},"actions":[{"type":"OUTPUT","port":"1"}]}' 
http://127.0.0.1:8080/stats/flowentry/add

I am not sure if the ofctl_rest is the right ryu app for that.
I have tried to find more information in the doc without luck.

Thx for your help

/mb

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Hiroshi Yokoi | 31 Jul 07:59 2014
Picon

[PATCH 1/3] bgp: add parameter for site_of_origins to neighbor_add and vrf_add method

Fujita-san,
thank you for your comment and finding the bug that causes test case failure.
I fixed the second and resend the whole patch.

The first is the addition of site_of_origins parameter to neighbor_add and
vrf_add method and fixes to some import error.

Signed-off-by: Hiroshi Yokoi <yokoi.hiroshi@...>
---
 ryu/services/protocols/bgp/bgpspeaker.py    | 13 ++++++++++++-
 ryu/services/protocols/bgp/info_base/vrf.py |  2 +-
 ryu/services/protocols/bgp/peer.py          |  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index cc6d122..01c4a2d 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
 <at>  <at>  -48,6 +48,7  <at>  <at>  from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_IPV6
 from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV4
 from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV6
 from ryu.services.protocols.bgp.rtconf.base import MULTI_EXIT_DISC
+from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_IPV4
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV4
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV6
 <at>  <at>  -175,7 +176,8  <at>  <at>  class BGPSpeaker(object):
                      enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
                      enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                      enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
(Continue reading)

Digambar Patil | 30 Jul 19:04 2014
Picon

BGP implementation & openstack contribution

Hi FUJITA,

         I am also reading BGP protocol for SDN & interested here to contribute to RYU BGP implementation.
         Please let me know about task - How tasks will be assigned in RYU, where should I start in BGP support for RYU . Any task you can assign me on BGP support side.

       
 As I am already working on openstack, at neutron side I can also contribute on the blueprints
        As YAMAMOTO already started this blueprint, should I contribute here. If you allow me then I can sync up with YAMAMOTO.

      Waiting for your reply.

Thanks,
Digambar
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
Ryu-devel@...
https://lists.sourceforge.net/lists/listinfo/ryu-devel
Hiroshi Yokoi | 30 Jul 11:27 2014
Picon

[PATCH 1/3] bgp: add parameter for site_of_origins to neighbor_add and vrf_add method

added parameter for site_of_origins to neighbor_add and vrf_add method,
and fixed some import error.

Signed-off-by: Hiroshi Yokoi <yokoi.hiroshi@...>
---
 ryu/services/protocols/bgp/bgpspeaker.py    | 13 ++++++++++++-
 ryu/services/protocols/bgp/info_base/vrf.py |  2 +-
 ryu/services/protocols/bgp/peer.py          |  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py
index 7625295..3996f88 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
 <at>  <at>  -48,6 +48,7  <at>  <at>  from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_IPV6
 from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV4
 from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV6
 from ryu.services.protocols.bgp.rtconf.base import MULTI_EXIT_DISC
+from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_IPV4
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV4
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV6
 <at>  <at>  -175,7 +176,8  <at>  <at>  class BGPSpeaker(object):
                      enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
                      enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                      enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
-                     next_hop=None, password=None, multi_exit_disc=None):
+                     next_hop=None, password=None, multi_exit_disc=None,
+                     site_of_origins=None):
         """ This method registers a new neighbor. The BGP speaker tries to
         establish a bgp session with the peer (accepts a connection
         from the peer and also tries to connect to it).
 <at>  <at>  -206,6 +208,8  <at>  <at>  class BGPSpeaker(object):
         The default is None and if not specified, MED value is
         not sent to the neighbor. It must be an integer.

+        ``site_of_origins`` specifies site_of_origin values.
+        This parameter must be a list of string.
         """
         bgp_neighbor = {}
         bgp_neighbor[neighbors.IP_ADDRESS] = address
 <at>  <at>  -230,6 +234,9  <at>  <at>  class BGPSpeaker(object):
         if multi_exit_disc:
             bgp_neighbor[MULTI_EXIT_DISC] = multi_exit_disc

+        if site_of_origins:
+            bgp_neighbor[SITE_OF_ORIGINS] = site_of_origins
+
         call('neighbor.create', **bgp_neighbor)

     def neighbor_del(self, address):
 <at>  <at>  -332,12 +339,16  <at>  <at>  class BGPSpeaker(object):

         ``export_rts`` specifies route targets to be exported.

+        ``site_of_origins`` specifies site_of_origin values.
+        This parameter must be a list of string.
+
         """

         vrf = {}
         vrf[vrfs.ROUTE_DISTINGUISHER] = route_dist
         vrf[vrfs.IMPORT_RTS] = import_rts
         vrf[vrfs.EXPORT_RTS] = export_rts
+        vrf[vrfs.SITE_OF_ORIGINS] = site_of_origins
         call('vrf.create', **vrf)

     def vrf_del(self, route_dist):
diff --git a/ryu/services/protocols/bgp/info_base/vrf.py b/ryu/services/protocols/bgp/info_base/vrf.py
index 85a0399..35c85cb 100644
--- a/ryu/services/protocols/bgp/info_base/vrf.py
+++ b/ryu/services/protocols/bgp/info_base/vrf.py
 <at>  <at>  -222,7 +222,7  <at>  <at>  class VrfTable(Table):
                                    local_administrator=int(local_admin),
                                    subtype=subtype))
             for soo in vrf_conf.soo_list:
-                as_num, local_admin = rt.split(':')
+                as_num, local_admin = soo.split(':')
                 subtype = 3
                 communities.append(BGPTwoOctetAsSpecificExtendedCommunity(
                                    as_number=int(as_num),
diff --git a/ryu/services/protocols/bgp/peer.py b/ryu/services/protocols/bgp/peer.py
index b2b4217..32244de 100644
--- a/ryu/services/protocols/bgp/peer.py
+++ b/ryu/services/protocols/bgp/peer.py
 <at>  <at>  -79,6 +79,9  <at>  <at>  from ryu.lib.packet.bgp import BGP_ATTR_TYPE_MULTI_EXIT_DISC
 from ryu.lib.packet.bgp import BGP_ATTR_TYPE_COMMUNITIES
 from ryu.lib.packet.bgp import BGP_ATTR_TYPE_EXTENDED_COMMUNITIES

+from ryu.lib.packet.bgp import BGPTwoOctetAsSpecificExtendedCommunity
+from ryu.lib.packet.bgp import BGPIPv4AddressSpecificExtendedCommunity
+
 LOG = logging.getLogger('bgpspeaker.peer')

 
--

-- 
1.8.5.2 (Apple Git-48)

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
ISHIDA Wataru | 30 Jul 09:03 2014
Picon

[PATCH 1/5] packet lib: add bmp(BGP Monitoring Protocol)

implements I-D grow-bmp-07

Signed-off-by: ISHIDA Wataru <ishida.wataru@...>
---
 ryu/lib/packet/bmp.py |  746 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 746 insertions(+)
 create mode 100644 ryu/lib/packet/bmp.py

diff --git a/ryu/lib/packet/bmp.py b/ryu/lib/packet/bmp.py
new file mode 100644
index 0000000..207ded8
--- /dev/null
+++ b/ryu/lib/packet/bmp.py
 <at>  <at>  -0,0 +1,746  <at>  <at> 
+# 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.
+
+"""
+BGP Monitoring Protocol draft-ietf-grow-bmp-07
+"""
+
+from ryu.lib.packet import packet_base
+from ryu.lib.packet import stream_parser
+from ryu.lib.packet.bgp import BGPMessage
+from ryu.lib import addrconv
+import struct
+
+VERSION = 3
+
+BMP_MSG_ROUTE_MONITORING = 0
+BMP_MSG_STATISTICS_REPORT = 1
+BMP_MSG_PEER_DOWN_NOTIFICATION = 2
+BMP_MSG_PEER_UP_NOTIFICATION = 3
+BMP_MSG_INITIATION = 4
+BMP_MSG_TERMINATION = 5
+
+BMP_PEER_TYPE_GLOBAL = 0
+BMP_PEER_TYPE_L3VPN = 1
+
+BMP_INIT_TYPE_STRING = 0
+BMP_INIT_TYPE_SYSDESCR = 1
+BMP_INIT_TYPE_SYSNAME = 2
+
+BMP_TERM_TYPE_STRING = 0
+BMP_TERM_TYPE_REASON = 1
+
+BMP_TERM_REASON_ADMIN = 0
+BMP_TERM_REASON_UNSPEC = 1
+BMP_TERM_REASON_OUT_OF_RESOURCE = 2
+BMP_TERM_REASON_REDUNDANT_CONNECTION = 3
+
+BMP_STAT_TYPE_REJECTED = 0
+BMP_STAT_TYPE_DUPLICATE_PREFIX = 1
+BMP_STAT_TYPE_DUPLICATE_WITHDRAW = 2
+BMP_STAT_TYPE_INV_UPDATE_DUE_TO_CLUSTER_LIST_LOOP = 3
+BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_PATH_LOOP = 4
+BMP_STAT_TYPE_INV_UPDATE_DUE_TO_ORIGINATOR_ID = 5
+BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_CONFED_LOOP = 6
+BMP_STAT_TYPE_ADJ_RIB_IN = 7
+BMP_STAT_TYPE_LOC_RIB = 8
+
+BMP_PEER_DOWN_REASON_UNKNOWN = 0
+BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION = 1
+BMP_PEER_DOWN_REASON_LOCAL_NO_NOTIFICATION = 2
+BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION = 3
+BMP_PEER_DOWN_REASON_REMOTE_NO_NOTIFICATION = 3
+
+
+class _TypeDisp(object):
+    _TYPES = {}
+    _REV_TYPES = None
+    _UNKNOWN_TYPE = None
+
+     <at> classmethod
+    def register_unknown_type(cls):
+        def _register_type(subcls):
+            cls._UNKNOWN_TYPE = subcls
+            return subcls
+        return _register_type
+
+     <at> classmethod
+    def register_type(cls, type_):
+        cls._TYPES = cls._TYPES.copy()
+
+        def _register_type(subcls):
+            cls._TYPES[type_] = subcls
+            cls._REV_TYPES = None
+            return subcls
+        return _register_type
+
+     <at> classmethod
+    def _lookup_type(cls, type_):
+        try:
+            return cls._TYPES[type_]
+        except KeyError:
+            return cls._UNKNOWN_TYPE
+
+     <at> classmethod
+    def _rev_lookup_type(cls, targ_cls):
+        if cls._REV_TYPES is None:
+            rev = dict((v, k) for k, v in cls._TYPES.iteritems())
+            cls._REV_TYPES = rev
+        return cls._REV_TYPES[targ_cls]
+
+
+class BMPMessage(packet_base.PacketBase, _TypeDisp):
+    """Base class for BGP Monitoring Protocol messages.
+
+    An instance has the following attributes at least.
+    Most of them are same to the on-wire counterparts but in host byte
+    order.
+    __init__ takes the corresponding args in this order.
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    ========================== ===============================================
+    """
+
+    _HDR_PACK_STR = '!BIB'  # version, padding, len, type, padding
+    _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
+
+    def __init__(self, type_, len_=None, version=VERSION):
+        self.version = version
+        self.len = len_
+        self.type = type_
+
+     <at> classmethod
+    def parse_header(cls, buf):
+        if len(buf) < cls._HDR_LEN:
+            raise stream_parser.StreamParser.TooSmallException(
+                '%d < %d' % (len(buf), cls._HDR_LEN))
+        (version, len_, type_) = struct.unpack_from(cls._HDR_PACK_STR,
+                                                    buffer(buf))
+
+        return version, len_, type_
+
+     <at> classmethod
+    def parser(cls, buf):
+        version, msglen, type_ = cls.parse_header(buf)
+
+        if version != VERSION:
+            raise ValueError("not supportted bmp version: %d" % version)
+
+        if len(buf) < msglen:
+            raise stream_parser.StreamParser.TooSmallException(
+                '%d < %d' % (len(buf), msglen))
+
+        binmsg = buf[cls._HDR_LEN:msglen]
+        rest = buf[msglen:]
+        subcls = cls._lookup_type(type_)
+
+        if subcls == cls._UNKNOWN_TYPE:
+            raise ValueError("unknown bmp type: %d" % type_)
+
+        kwargs = subcls.parser(binmsg)
+        return subcls(len_=msglen,
+                      type_=type_, version=version, **kwargs), rest
+
+    def serialize(self):
+        # fixup
+        tail = self.serialize_tail()
+        self.len = self._HDR_LEN + len(tail)
+
+        hdr = bytearray(struct.pack(self._HDR_PACK_STR, self.version,
+                                    self.len, self.type))
+        return hdr + tail
+
+    def __len__(self):
+        # XXX destructive
+        buf = self.serialize()
+        return len(buf)
+
+
+class BMPPeerMessage(BMPMessage):
+    """BMP Message with Per Peer Header
+
+    Following BMP Messages contain Per Peer Header after Common BMP Header.
+
+    - BMP_MSG_TYPE_ROUTE_MONITRING
+    - BMP_MSG_TYPE_STATISTICS_REPORT
+    - BMP_MSG_PEER_UP_NOTIFICATION
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    peer_type                  The type of the peer.
+    is_post_policy             Indicate the message reflects the post-policy
+                               Adj-RIB-In
+    peer_distinguisher         Use for L3VPN router which can have multiple
+                               instance.
+    peer_address               The remote IP address associated with the TCP
+                               session.
+    peer_as                    The Autonomous System number of the peer.
+    peer_bgp_id                The BGP Identifier of the peer
+    timestamp                  The time when the encapsulated routes were
+                               received.
+    ========================== ===============================================
+    """
+
+    _PEER_HDR_PACK_STR = '!BBQ16sI4sII'
+    _TYPE = {
+        'ascii': [
+            'peer_address',
+            'peer_bgp_id'
+        ]
+    }
+
+    def __init__(self, peer_type, is_post_policy, peer_distinguisher,
+                 peer_address, peer_as, peer_bgp_id, timestamp,
+                 version=VERSION, type_=None, len_=None):
+        super(BMPPeerMessage, self).__init__(version=version,
+                                             len_=len_,
+                                             type_=type_)
+        self.peer_type = peer_type
+        self.is_post_policy = is_post_policy
+        self.peer_distinguisher = peer_distinguisher
+        self.peer_address = peer_address
+        self.peer_as = peer_as
+        self.peer_bgp_id = peer_bgp_id
+        self.timestamp = timestamp
+
+     <at> classmethod
+    def parser(cls, buf):
+        (peer_type, peer_flags, peer_distinguisher,
+         peer_address, peer_as, peer_bgp_id,
+         timestamp1, timestamp2) = struct.unpack_from(cls._PEER_HDR_PACK_STR,
+                                                      buffer(buf))
+
+        rest = buf[struct.calcsize(cls._PEER_HDR_PACK_STR):]
+
+        if peer_flags & (1 << 6):
+            is_post_policy = True
+        else:
+            is_post_policy = False
+
+        if peer_flags & (1 << 7):
+            peer_address = addrconv.ipv6.bin_to_text(buffer(peer_address))
+        else:
+            peer_address = addrconv.ipv4.bin_to_text(buffer(peer_address[:4]))
+
+        peer_bgp_id = addrconv.ipv4.bin_to_text(buffer(peer_bgp_id))
+
+        timestamp = float(timestamp1) + timestamp2 * (10 ** -6)
+
+        return {
+            "peer_type": peer_type,
+            "is_post_policy": is_post_policy,
+            "peer_distinguisher": peer_distinguisher,
+            "peer_address": peer_address,
+            "peer_as": peer_as,
+            "peer_bgp_id": peer_bgp_id,
+            "timestamp": timestamp
+        }, rest
+
+    def serialize_tail(self):
+        flags = 0
+
+        if self.is_post_policy:
+            flags |= (1 << 6)
+
+        if ':' in self.peer_address:
+            flags |= (1 << 7)
+            peer_address = addrconv.ipv6.text_to_bin(self.peer_address)
+        else:
+            peer_address = addrconv.ipv4.text_to_bin(self.peer_address)
+
+        peer_bgp_id = addrconv.ipv4.text_to_bin(self.peer_bgp_id)
+
+        t1, t2 = [int(t) for t in ("%.6f" % self.timestamp).split('.')]
+
+        msg = bytearray(struct.pack(self._PEER_HDR_PACK_STR, self.peer_type,
+                                    flags, self.peer_distinguisher,
+                                    peer_address, self.peer_as,
+                                    peer_bgp_id, t1, t2))
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_ROUTE_MONITORING)
+class BMPRouteMonitoring(BMPPeerMessage):
+    """BMP Route Monitoring Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    peer_type                  The type of the peer.
+    peer_flags                 Provide more information about the peer.
+    peer_distinguisher         Use for L3VPN router which can have multiple
+                               instance.
+    peer_address               The remote IP address associated with the TCP
+                               session.
+    peer_as                    The Autonomous System number of the peer.
+    peer_bgp_id                The BGP Identifier of the peer
+    timestamp                  The time when the encapsulated routes were
+                               received.
+    bgp_update                 BGP Update PDU
+    ========================== ===============================================
+    """
+
+    def __init__(self, bgp_update, peer_type, is_post_policy,
+                 peer_distinguisher, peer_address, peer_as, peer_bgp_id,
+                 timestamp, version=VERSION, type_=BMP_MSG_ROUTE_MONITORING,
+                 len_=None):
+        super(BMPRouteMonitoring,
+              self).__init__(peer_type=peer_type,
+                             is_post_policy=is_post_policy,
+                             peer_distinguisher=peer_distinguisher,
+                             peer_address=peer_address,
+                             peer_as=peer_as,
+                             peer_bgp_id=peer_bgp_id,
+                             timestamp=timestamp,
+                             len_=len_,
+                             type_=type_,
+                             version=version)
+        self.bgp_update = bgp_update
+
+     <at> classmethod
+    def parser(cls, buf):
+        kwargs, buf = super(BMPRouteMonitoring, cls).parser(buf)
+
+        bgp_update, buf = BGPMessage.parser(buf)
+
+        kwargs['bgp_update'] = bgp_update
+
+        return kwargs
+
+    def serialize_tail(self):
+        msg = super(BMPRouteMonitoring, self).serialize_tail()
+        msg += self.bgp_update.serialize()
+
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_STATISTICS_REPORT)
+class BMPStatisticsReport(BMPPeerMessage):
+    """BMP Statistics Report Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    peer_type                  The type of the peer.
+    peer_flags                 Provide more information about the peer.
+    peer_distinguisher         Use for L3VPN router which can have multiple
+                               instance.
+    peer_address               The remote IP address associated with the TCP
+                               session.
+    peer_as                    The Autonomous System number of the peer.
+    peer_bgp_id                The BGP Identifier of the peer
+    timestamp                  The time when the encapsulated routes were
+                               received.
+    stats                      Statistics (one or more stats encoded as a TLV)
+    ========================== ===============================================
+    """
+
+    _TLV_PACK_STR = '!HH'
+    _MIN_LEN = struct.calcsize(_TLV_PACK_STR)
+
+    def __init__(self, stats, peer_type, is_post_policy, peer_distinguisher,
+                 peer_address, peer_as, peer_bgp_id, timestamp,
+                 version=VERSION, type_=BMP_MSG_STATISTICS_REPORT, len_=None):
+        super(BMPStatisticsReport,
+              self).__init__(peer_type=peer_type,
+                             is_post_policy=is_post_policy,
+                             peer_distinguisher=peer_distinguisher,
+                             peer_address=peer_address,
+                             peer_as=peer_as,
+                             peer_bgp_id=peer_bgp_id,
+                             timestamp=timestamp,
+                             len_=len_,
+                             type_=type_,
+                             version=version)
+        self.stats = stats
+
+     <at> classmethod
+    def parser(cls, buf):
+        kwargs, rest = super(BMPStatisticsReport, cls).parser(buf)
+
+        stats_count, = struct.unpack_from('!I', buffer(rest))
+
+        buf = rest[struct.calcsize('!I'):]
+
+        stats = []
+
+        while len(buf):
+            if len(buf) < cls._MIN_LEN:
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN))
+            (type_, len_) = struct.unpack_from(cls._TLV_PACK_STR, buffer(buf))
+
+            if len(buf) < (cls._MIN_LEN + len_):
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN + len_))
+
+            value = buf[cls._MIN_LEN:cls._MIN_LEN + len_]
+
+            if type_ == BMP_STAT_TYPE_REJECTED or \
+               type_ == BMP_STAT_TYPE_DUPLICATE_PREFIX or \
+               type_ == BMP_STAT_TYPE_DUPLICATE_WITHDRAW or \
+               type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_CLUSTER_LIST_LOOP or \
+               type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_PATH_LOOP or \
+               type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_ORIGINATOR_ID or \
+               type_ == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_CONFED_LOOP:
+                value, = struct.unpack_from('!I', buffer(value))
+            elif type_ == BMP_STAT_TYPE_ADJ_RIB_IN or \
+                    type_ == BMP_STAT_TYPE_LOC_RIB:
+                value, = struct.unpack_from('!Q', buffer(value))
+
+            buf = buf[cls._MIN_LEN + len_:]
+
+            stats.append({'type': type_, 'len': len_, 'value': value})
+
+        kwargs['stats'] = stats
+
+        return kwargs
+
+    def serialize_tail(self):
+        msg = super(BMPStatisticsReport, self).serialize_tail()
+
+        stats_count = len(self.stats)
+
+        msg += bytearray(struct.pack('!I', stats_count))
+
+        for v in self.stats:
+            t = v['type']
+            if t == BMP_STAT_TYPE_REJECTED or \
+               t == BMP_STAT_TYPE_DUPLICATE_PREFIX or \
+               t == BMP_STAT_TYPE_DUPLICATE_WITHDRAW or \
+               t == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_CLUSTER_LIST_LOOP or \
+               t == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_PATH_LOOP or \
+               t == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_ORIGINATOR_ID or \
+               t == BMP_STAT_TYPE_INV_UPDATE_DUE_TO_AS_CONFED_LOOP:
+                valuepackstr = 'I'
+            elif t == BMP_STAT_TYPE_ADJ_RIB_IN or \
+                    t == BMP_STAT_TYPE_LOC_RIB:
+                valuepackstr = 'Q'
+            else:
+                continue
+
+            v['len'] = struct.calcsize(valuepackstr)
+            msg += bytearray(struct.pack(self._TLV_PACK_STR + valuepackstr,
+                                         t, v['len'], v['value']))
+
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_PEER_DOWN_NOTIFICATION)
+class BMPPeerDownNotification(BMPMessage):
+    """BMP Peer Down Notification Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    reason                     Reason indicates why the session was closed.
+    data                       vary by the reason.
+    ========================== ===============================================
+    """
+
+    def __init__(self, reason, data, type_=BMP_MSG_PEER_DOWN_NOTIFICATION,
+                 len_=None, version=VERSION):
+        super(BMPPeerDownNotification, self).__init__(type_, len_, version)
+        self.reason = reason
+        self.data = data
+
+     <at> classmethod
+    def parser(cls, buf):
+        reason, = struct.unpack_from('!B', buffer(buf))
+        buf = buf[struct.calcsize('!B'):]
+
+        if reason == BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION:
+            data, rest = BGPMessage.parser(buf)
+        elif reason == BMP_PEER_DOWN_REASON_LOCAL_NO_NOTIFICATION:
+            data = struct.unpack_from('!H', buffer(buf))
+        elif reason == BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION:
+            data, rest = BGPMessage.parser(buf)
+        elif reason == BMP_PEER_DOWN_REASON_REMOTE_NO_NOTIFICATION:
+            data = None
+        else:
+            reason = BMP_PEER_DOWN_REASON_UNKNOWN
+            data = buf
+
+        kwargs = {}
+        kwargs['reason'] = reason
+        kwargs['data'] = data
+
+        return kwargs
+
+    def serialize_tail(self):
+        msg = struct.pack('!B', self.reason)
+
+        if self.reason == BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION:
+            msg += self.data.serialize()
+        elif self.reason == BMP_PEER_DOWN_REASON_LOCAL_NO_NOTIFICATION:
+            msg += struct.pack('!H', self.data)
+        elif self.reason == BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION:
+            msg += self.data.serialize()
+        elif self.reason == BMP_PEER_DOWN_REASON_UNKNOWN:
+            msg += str(self.data)
+
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_PEER_UP_NOTIFICATION)
+class BMPPeerUpNotification(BMPPeerMessage):
+    """BMP Peer Up Notification Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    peer_type                  The type of the peer.
+    peer_flags                 Provide more information about the peer.
+    peer_distinguisher         Use for L3VPN router which can have multiple
+                               instance.
+    peer_address               The remote IP address associated with the TCP
+                               session.
+    peer_as                    The Autonomous System number of the peer.
+    peer_bgp_id                The BGP Identifier of the peer
+    timestamp                  The time when the encapsulated routes were
+                               received.
+    local_address              The local IP address associated with the
+                               peering TCP session.
+    local_port                 The local port number associated with the
+                               peering TCP session.
+    remote_port                The remote port number associated with the
+                               peering TCP session.
+    sent_open_message          The full OPEN message transmitted by the
+                               monitored router to its peer.
+    received_open_message      The full OPEN message received by the monitored
+                               router from its peer.
+    ========================== ===============================================
+    """
+
+    _PACK_STR = '!16sHH'
+    _MIN_LEN = struct.calcsize(_PACK_STR)
+
+    def __init__(self, local_address, local_port, remote_port,
+                 sent_open_message, received_open_message,
+                 peer_type, is_post_policy, peer_distinguisher,
+                 peer_address, peer_as, peer_bgp_id, timestamp,
+                 version=VERSION, type_=BMP_MSG_PEER_UP_NOTIFICATION,
+                 len_=None):
+        super(BMPPeerUpNotification,
+              self).__init__(peer_type=peer_type,
+                             is_post_policy=is_post_policy,
+                             peer_distinguisher=peer_distinguisher,
+                             peer_address=peer_address,
+                             peer_as=peer_as,
+                             peer_bgp_id=peer_bgp_id,
+                             timestamp=timestamp,
+                             len_=len_,
+                             type_=type_,
+                             version=version)
+        self.local_address = local_address
+        self.local_port = local_port
+        self.remote_port = remote_port
+        self.sent_open_message = sent_open_message
+        self.received_open_message = received_open_message
+
+     <at> classmethod
+    def parser(cls, buf):
+        kwargs, rest = super(BMPPeerUpNotification, cls).parser(buf)
+
+        (local_address, local_port,
+         remote_port) = struct.unpack_from(cls._PACK_STR, buffer(rest))
+
+        local_address = buffer(local_address)
+
+        if '.' in kwargs['peer_address']:
+            local_address = addrconv.ipv4.bin_to_text(local_address[:4])
+        elif ':' in kwargs['peer_address']:
+            local_address = addrconv.ipv6.bin_to_text(local_address)
+        else:
+            raise ValueError("invalid local_address: %s" % local_address)
+
+        kwargs['local_address'] = local_address
+        kwargs['local_port'] = local_port
+        kwargs['remote_port'] = remote_port
+
+        rest = rest[cls._MIN_LEN:]
+
+        sent_open_msg, rest = BGPMessage.parser(rest)
+        received_open_msg, rest = BGPMessage.parser(rest)
+
+        kwargs['sent_open_message'] = sent_open_msg
+        kwargs['received_open_message'] = received_open_msg
+
+        return kwargs
+
+    def serialize_tail(self):
+        msg = super(BMPPeerUpNotification, self).serialize_tail()
+
+        if '.' in self.local_address:
+            local_address = addrconv.ipv4.text_to_bin(self.local_address)
+        elif ':' in self.local_address:
+            local_address = addrconv.ipv6.text_to_bin(self.local_address)
+        else:
+            raise ValueError("invalid local_address: %s" % self.local_address)
+
+        msg += struct.pack(self._PACK_STR, local_address,
+                           self.local_port, self.remote_port)
+
+        msg += self.sent_open_message.serialize()
+        msg += self.received_open_message.serialize()
+
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_INITIATION)
+class BMPInitiation(BMPMessage):
+    """BMP Initiation Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    info                       One or more piece of information encoded as a
+                               TLV
+    ========================== ===============================================
+    """
+
+    _TLV_PACK_STR = '!HH'
+    _MIN_LEN = struct.calcsize(_TLV_PACK_STR)
+
+    def __init__(self, info, type_=BMP_MSG_INITIATION, len_=None,
+                 version=VERSION):
+        super(BMPInitiation, self).__init__(type_, len_, version)
+        self.info = info
+
+     <at> classmethod
+    def parser(cls, buf):
+        info = []
+        while len(buf):
+            if len(buf) < cls._MIN_LEN:
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN))
+            (type_, len_) = struct.unpack_from(cls._TLV_PACK_STR, buffer(buf))
+
+            if len(buf) < (cls._MIN_LEN + len_):
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN + len_))
+
+            value = buf[cls._MIN_LEN:cls._MIN_LEN + len_]
+
+            if type_ == BMP_INIT_TYPE_STRING:
+                value = value.decode('utf-8')
+
+            buf = buf[cls._MIN_LEN + len_:]
+
+            info.append({'type': type_, 'len': len_, 'value': value})
+
+        return {'info': info}
+
+    def serialize_tail(self):
+        msg = bytearray()
+
+        for v in self.info:
+            if v['type'] == BMP_INIT_TYPE_STRING:
+                value = v['value'].encode('utf-8')
+            else:
+                value = v['value']
+
+            v['len'] = len(value)
+            msg += struct.pack(self._TLV_PACK_STR, v['type'], v['len'])
+            msg += value
+
+        return msg
+
+
+ <at> BMPMessage.register_type(BMP_MSG_TERMINATION)
+class BMPTermination(BMPMessage):
+    """BMP Termination Message
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    version                    Version. this packet lib defines BMP ver. 3
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  one of BMP\_MSG\_ constants.
+    info                       One or more piece of information encoded as a
+                               TLV
+    ========================== ===============================================
+    """
+
+    _TLV_PACK_STR = '!HH'
+    _MIN_LEN = struct.calcsize(_TLV_PACK_STR)
+
+    def __init__(self, info, type_=BMP_MSG_TERMINATION, len_=None,
+                 version=VERSION):
+        super(BMPTermination, self).__init__(type_, len_, version)
+        self.info = info
+
+     <at> classmethod
+    def parser(cls, buf):
+        info = []
+        while len(buf):
+            if len(buf) < cls._MIN_LEN:
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN))
+            (type_, len_) = struct.unpack_from(cls._TLV_PACK_STR, buffer(buf))
+
+            if len(buf) < (cls._MIN_LEN + len_):
+                raise stream_parser.StreamParser.TooSmallException(
+                    '%d < %d' % (len(buf), cls._MIN_LEN + len_))
+
+            value = buf[cls._MIN_LEN:cls._MIN_LEN + len_]
+            if type_ == BMP_TERM_TYPE_STRING:
+                value = value.decode('utf-8')
+            elif type_ == BMP_TERM_TYPE_REASON:
+                value, = struct.unpack_from('!H', buffer(value))
+
+            buf = buf[cls._MIN_LEN + len_:]
+
+            info.append({'type': type_, 'len': len_, 'value': value})
+
+        return {'info': info}
+
+    def serialize_tail(self):
+        msg = bytearray()
+
+        for v in self.info:
+            if v['type'] == BMP_TERM_TYPE_STRING:
+                value = v['value'].encode('utf-8')
+            elif v['type'] == BMP_TERM_TYPE_REASON:
+                value = struct.pack('!H', v['value'])
+            v['len'] = len(value)
+            msg += struct.pack(self._TLV_PACK_STR, v['type'], v['len'])
+            msg += value
+
+        return msg
--

-- 
1.7.10.4

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
林哲緯 | 30 Jul 08:42 2014
Picon

About snort integration

Hi, Everyone,

I saw that ryu controller pulished a project that integrates the snort for IDS
on The following mailing list:

http://sourceforge.net/p/ryu/mailman/ryu-devel/thread/1364197166-9889-3-git-send-email-ohmura.kei-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org/

The Snort-Integration project link : https://github.com/osrg/ryu/wiki/Snort-Integration

This is an excellent integration project, but it's seems to be close or missing?

Will the Ryu(3.11 or later) controller
develop snort integration in the near future?

Thank you for any help you can provide.


John Lin
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
Ryu-devel@...
https://lists.sourceforge.net/lists/listinfo/ryu-devel
Minoru TAKAHASHI | 30 Jul 07:33 2014
Picon

[PATCH 5/5] packet lib: sctp: fix default arguments

Reported-by: Arne Goetje <arne_goetje@...>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@...>
---
 ryu/lib/packet/sctp.py               |  2 +-
 ryu/tests/unit/packet/test_packet.py | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/ryu/lib/packet/sctp.py b/ryu/lib/packet/sctp.py
index 8dfc28a..1806e37 100644
--- a/ryu/lib/packet/sctp.py
+++ b/ryu/lib/packet/sctp.py
 <at>  <at>  -99,7 +99,7  <at>  <at>  class sctp(packet_base.PacketBase):
             return cls
         return _register_chunk_type(args[0])

-    def __init__(self, src_port=0, dst_port=0, vtag=0, csum=0, chunks=None):
+    def __init__(self, src_port=1, dst_port=1, vtag=0, csum=0, chunks=None):
         super(sctp, self).__init__()
         self.src_port = src_port
         self.dst_port = dst_port
diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py
index 12929cb..16a5c9d 100644
--- a/ryu/tests/unit/packet/test_packet.py
+++ b/ryu/tests/unit/packet/test_packet.py
 <at>  <at>  -638,8 +638,8  <at>  <at>  class TestPacket(unittest.TestCase):

         # sctp
         ok_(p_sctp)
-        eq_(0, p_sctp.src_port)
-        eq_(0, p_sctp.dst_port)
+        eq_(1, p_sctp.src_port)
+        eq_(1, p_sctp.dst_port)
         eq_(0, p_sctp.vtag)
         assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
         eq_(0, p_sctp.chunks[0]._type)
 <at>  <at>  -694,8 +694,8  <at>  <at>  class TestPacket(unittest.TestCase):
                              for k in sorted(data_values.keys())])
         data_str = '[%s(%s)]' % (sctp.chunk_data.__name__, _data_str)

-        sctp_values = {'src_port': 0,
-                       'dst_port': 0,
+        sctp_values = {'src_port': 1,
+                       'dst_port': 1,
                        'vtag': 0,
                        'csum': p_sctp.csum,
                        'chunks': data_str}
 <at>  <at>  -1178,8 +1178,8  <at>  <at>  class TestPacket(unittest.TestCase):

         # sctp
         ok_(p_sctp)
-        eq_(0, p_sctp.src_port)
-        eq_(0, p_sctp.dst_port)
+        eq_(1, p_sctp.src_port)
+        eq_(1, p_sctp.dst_port)
         eq_(0, p_sctp.vtag)
         assert isinstance(p_sctp.chunks[0], sctp.chunk_data)
         eq_(0, p_sctp.chunks[0]._type)
 <at>  <at>  -1230,8 +1230,8  <at>  <at>  class TestPacket(unittest.TestCase):
                              for k in sorted(data_values.keys())])
         data_str = '[%s(%s)]' % (sctp.chunk_data.__name__, _data_str)

-        sctp_values = {'src_port': 0,
-                       'dst_port': 0,
+        sctp_values = {'src_port': 1,
+                       'dst_port': 1,
                        'vtag': 0,
                        'csum': p_sctp.csum,
                        'chunks': data_str}
--

-- 
1.9.1

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Minoru TAKAHASHI | 30 Jul 07:32 2014
Picon

[PATCH 4/5] packet lib: udp: fix default arguments

Reported-by: Arne Goetje <arne_goetje@...>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@...>
---
 ryu/lib/packet/udp.py                |  2 +-
 ryu/tests/unit/packet/test_packet.py | 14 +++++++-------
 ryu/tests/unit/packet/test_udp.py    |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py
index a960886..a80e101 100644
--- a/ryu/lib/packet/udp.py
+++ b/ryu/lib/packet/udp.py
 <at>  <at>  -41,7 +41,7  <at>  <at>  class udp(packet_base.PacketBase):
     _PACK_STR = '!HHHH'
     _MIN_LEN = struct.calcsize(_PACK_STR)

-    def __init__(self, src_port=0, dst_port=0, total_length=0, csum=0):
+    def __init__(self, src_port=1, dst_port=1, total_length=0, csum=0):
         super(udp, self).__init__()
         self.src_port = src_port
         self.dst_port = dst_port
diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py
index 9c9ceff..12929cb 100644
--- a/ryu/tests/unit/packet/test_packet.py
+++ b/ryu/tests/unit/packet/test_packet.py
 <at>  <at>  -911,16 +911,16  <at>  <at>  class TestPacket(unittest.TestCase):

         # udp
         ok_(p_udp)
-        eq_(0, p_udp.src_port)
-        eq_(0, p_udp.dst_port)
+        eq_(1, p_udp.src_port)
+        eq_(1, p_udp.dst_port)
         eq_(len(u_buf) + len(self.payload), p_udp.total_length)
-        eq_(0x2B62, p_udp.csum)
+        eq_(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), 0x60)
+        eq_(packet_utils.checksum(t), 0x62)

         # payload
         ok_('payload' in protocols)
 <at>  <at>  -949,10 +949,10  <at>  <at>  class TestPacket(unittest.TestCase):
                               if k in ipv6_values])
         ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)

-        udp_values = {'src_port': 0,
-                      'dst_port': 0,
+        udp_values = {'src_port': 1,
+                      'dst_port': 1,
                       'total_length': len(u_buf) + len(self.payload),
-                      'csum': 0x2B62}
+                      'csum': 0x2B60}
         _udp_str = ','.join(['%s=%s' % (k, repr(udp_values[k]))
                              for k, v in inspect.getmembers(p_udp)
                              if k in udp_values])
diff --git a/ryu/tests/unit/packet/test_udp.py b/ryu/tests/unit/packet/test_udp.py
index 51221c9..c8b3e48 100644
--- a/ryu/tests/unit/packet/test_udp.py
+++ b/ryu/tests/unit/packet/test_udp.py
 <at>  <at>  -101,8 +101,8  <at>  <at>  class Test_udp(unittest.TestCase):
         buf = u.serialize(bytearray(), prev)
         res = struct.unpack(udp._PACK_STR, buf)

-        eq_(res[0], 0)
-        eq_(res[1], 0)
+        eq_(res[0], 1)
+        eq_(res[1], 1)
         eq_(res[2], udp._MIN_LEN)

     def test_json(self):
--

-- 
1.9.1

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Minoru TAKAHASHI | 30 Jul 07:32 2014
Picon

[PATCH 3/5] packet lib: tcp: fix default arguments

Reported-by: Arne Goetje <arne_goetje@...>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@...>
---
 ryu/lib/packet/tcp.py                |  2 +-
 ryu/tests/unit/packet/test_packet.py | 10 +++++-----
 ryu/tests/unit/packet/test_tcp.py    | 12 ++++++------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py
index a6f0167..f0e8645 100644
--- a/ryu/lib/packet/tcp.py
+++ b/ryu/lib/packet/tcp.py
 <at>  <at>  -48,7 +48,7  <at>  <at>  class tcp(packet_base.PacketBase):
     _PACK_STR = '!HHIIBBHHH'
     _MIN_LEN = struct.calcsize(_PACK_STR)

-    def __init__(self, src_port=0, dst_port=0, seq=0, ack=0, offset=0,
+    def __init__(self, src_port=1, dst_port=1, seq=0, ack=0, offset=0,
                  bits=0, window_size=0, csum=0, urgent=0, option=None):
         super(tcp, self).__init__()
         self.src_port = src_port
diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py
index 09bb307..9c9ceff 100644
--- a/ryu/tests/unit/packet/test_packet.py
+++ b/ryu/tests/unit/packet/test_packet.py
 <at>  <at>  -1038,8 +1038,8  <at>  <at>  class TestPacket(unittest.TestCase):

         # tcp
         ok_(p_tcp)
-        eq_(0, p_tcp.src_port)
-        eq_(0, p_tcp.dst_port)
+        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)
 <at>  <at>  -1052,7 +1052,7  <at>  <at>  class TestPacket(unittest.TestCase):
         ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
                          len(t_buf) + len(self.payload), 6)
         t = ph + t + self.payload
-        eq_(packet_utils.checksum(t), 0x60)
+        eq_(packet_utils.checksum(t), 0x62)

         # payload
         ok_('payload' in protocols)
 <at>  <at>  -1081,8 +1081,8  <at>  <at>  class TestPacket(unittest.TestCase):
                               if k in ipv6_values])
         ipv6_str = '%s(%s)' % (ipv6.ipv6.__name__, _ipv6_str)

-        tcp_values = {'src_port': 0,
-                      'dst_port': 0,
+        tcp_values = {'src_port': 1,
+                      'dst_port': 1,
                       'seq': 0,
                       'ack': 0,
                       'offset': 6,
diff --git a/ryu/tests/unit/packet/test_tcp.py b/ryu/tests/unit/packet/test_tcp.py
index 900d420..3cc5777 100644
--- a/ryu/tests/unit/packet/test_tcp.py
+++ b/ryu/tests/unit/packet/test_tcp.py
 <at>  <at>  -145,8 +145,8  <at>  <at>  class Test_tcp(unittest.TestCase):
         buf = t.serialize(bytearray(), prev)
         res = struct.unpack(tcp._PACK_STR, buf)

-        eq_(res[0], 0)
-        eq_(res[1], 0)
+        eq_(res[0], 1)
+        eq_(res[1], 1)
         eq_(res[2], 0)
         eq_(res[3], 0)
         eq_(res[4], 5 << 4)
 <at>  <at>  -159,8 +159,8  <at>  <at>  class Test_tcp(unittest.TestCase):
         buf = t.serialize(bytearray(), prev)
         res = struct.unpack(tcp._PACK_STR + '4s', buf)

-        eq_(res[0], 0)
-        eq_(res[1], 0)
+        eq_(res[0], 1)
+        eq_(res[1], 1)
         eq_(res[2], 0)
         eq_(res[3], 0)
         eq_(res[4], 6 << 4)
 <at>  <at>  -174,8 +174,8  <at>  <at>  class Test_tcp(unittest.TestCase):
         buf = t.serialize(bytearray(), prev)
         res = struct.unpack(tcp._PACK_STR + '8s', buf)

-        eq_(res[0], 0)
-        eq_(res[1], 0)
+        eq_(res[0], 1)
+        eq_(res[1], 1)
         eq_(res[2], 0)
         eq_(res[3], 0)
         eq_(res[4], 7 << 4)
--

-- 
1.9.1

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Minoru TAKAHASHI | 30 Jul 07:32 2014
Picon

[PATCH 2/5] packet lib: ipv6: fix default arguments

Reported-by: Arne Goetje <arne_goetje@...>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@...>
---
 ryu/lib/packet/ipv6.py               |  2 +-
 ryu/tests/unit/packet/test_ipv6.py   |  8 +++----
 ryu/tests/unit/packet/test_packet.py | 42 ++++++++++++++++++------------------
 3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py
index 4be42c7..8f5fea7 100644
--- a/ryu/lib/packet/ipv6.py
+++ b/ryu/lib/packet/ipv6.py
 <at>  <at>  -76,7 +76,7  <at>  <at>  class ipv6(packet_base.PacketBase):

     def __init__(self, version=6, traffic_class=0, flow_label=0,
                  payload_length=0, nxt=inet.IPPROTO_TCP, hop_limit=255,
-                 src='::', dst='::', ext_hdrs=None):
+                 src='10::10', dst='20::20', ext_hdrs=None):
         super(ipv6, self).__init__()
         self.version = version
         self.traffic_class = traffic_class
diff --git a/ryu/tests/unit/packet/test_ipv6.py b/ryu/tests/unit/packet/test_ipv6.py
index 211df48..6615f9d 100644
--- a/ryu/tests/unit/packet/test_ipv6.py
+++ b/ryu/tests/unit/packet/test_ipv6.py
 <at>  <at>  -455,8 +455,8  <at>  <at>  class Test_ipv6(unittest.TestCase):
         eq_(res[1], 0)
         eq_(res[2], 6)
         eq_(res[3], 255)
-        eq_(res[4], addrconv.ipv6.text_to_bin('::'))
-        eq_(res[5], addrconv.ipv6.text_to_bin('::'))
+        eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
+        eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))

         # with extension header
         ip = ipv6.ipv6(
 <at>  <at>  -471,8 +471,8  <at>  <at>  class Test_ipv6(unittest.TestCase):
         eq_(res[1], 8)
         eq_(res[2], 0)
         eq_(res[3], 255)
-        eq_(res[4], addrconv.ipv6.text_to_bin('::'))
-        eq_(res[5], addrconv.ipv6.text_to_bin('::'))
+        eq_(res[4], addrconv.ipv6.text_to_bin('10::10'))
+        eq_(res[5], addrconv.ipv6.text_to_bin('20::20'))
         eq_(res[6], '\x3a\x00\x05\x02\x00\x00\x01\x00')

     def test_json(self):
diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py
index 891cbf1..09bb307 100644
--- a/ryu/tests/unit/packet/test_packet.py
+++ b/ryu/tests/unit/packet/test_packet.py
 <at>  <at>  -906,21 +906,21  <at>  <at>  class TestPacket(unittest.TestCase):
         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_('::', p_ipv6.src)
-        eq_('::', p_ipv6.dst)
+        eq_('10::10', p_ipv6.src)
+        eq_('20::20', p_ipv6.dst)

         # udp
         ok_(p_udp)
         eq_(0, p_udp.src_port)
         eq_(0, p_udp.dst_port)
         eq_(len(u_buf) + len(self.payload), p_udp.total_length)
-        eq_(0x2bc2, p_udp.csum)
+        eq_(0x2B62, 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), 0)
+        eq_(packet_utils.checksum(t), 0x60)

         # payload
         ok_('payload' in protocols)
 <at>  <at>  -941,8 +941,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'payload_length': len(u_buf) + len(self.payload),
                        'nxt': inet.IPPROTO_UDP,
                        'hop_limit': 255,
-                       'src': '::',
-                       'dst': '::',
+                       'src': '10::10',
+                       'dst': '20::20',
                        'ext_hdrs': []}
         _ipv6_str = ','.join(['%s=%s' % (k, repr(ipv6_values[k]))
                               for k, v in inspect.getmembers(p_ipv6)
 <at>  <at>  -952,7 +952,7  <at>  <at>  class TestPacket(unittest.TestCase):
         udp_values = {'src_port': 0,
                       'dst_port': 0,
                       'total_length': len(u_buf) + len(self.payload),
-                      'csum': 0x2bc2}
+                      'csum': 0x2B62}
         _udp_str = ','.join(['%s=%s' % (k, repr(udp_values[k]))
                              for k, v in inspect.getmembers(p_udp)
                              if k in udp_values])
 <at>  <at>  -1033,8 +1033,8  <at>  <at>  class TestPacket(unittest.TestCase):
         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_('::', p_ipv6.src)
-        eq_('::', p_ipv6.dst)
+        eq_('10::10', p_ipv6.src)
+        eq_('20::20', p_ipv6.dst)

         # tcp
         ok_(p_tcp)
 <at>  <at>  -1052,7 +1052,7  <at>  <at>  class TestPacket(unittest.TestCase):
         ph = struct.pack('!16s16sI3xB', ipaddr, ipaddr,
                          len(t_buf) + len(self.payload), 6)
         t = ph + t + self.payload
-        eq_(packet_utils.checksum(t), 0)
+        eq_(packet_utils.checksum(t), 0x60)

         # payload
         ok_('payload' in protocols)
 <at>  <at>  -1073,8 +1073,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'payload_length': len(t_buf) + len(self.payload),
                        'nxt': inet.IPPROTO_TCP,
                        'hop_limit': 255,
-                       'src': '::',
-                       'dst': '::',
+                       'src': '10::10',
+                       'dst': '20::20',
                        'ext_hdrs': []}
         _ipv6_str = ','.join(['%s=%s' % (k, repr(ipv6_values[k]))
                               for k, v in inspect.getmembers(p_ipv6)
 <at>  <at>  -1173,8 +1173,8  <at>  <at>  class TestPacket(unittest.TestCase):
         eq_(len(s_buf), p_ipv6.payload_length)
         eq_(inet.IPPROTO_SCTP, p_ipv6.nxt)
         eq_(255, p_ipv6.hop_limit)
-        eq_('::', p_ipv6.src)
-        eq_('::', p_ipv6.dst)
+        eq_('10::10', p_ipv6.src)
+        eq_('20::20', p_ipv6.dst)

         # sctp
         ok_(p_sctp)
 <at>  <at>  -1209,8 +1209,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'payload_length': len(s_buf),
                        'nxt': inet.IPPROTO_SCTP,
                        'hop_limit': 255,
-                       'src': '::',
-                       'dst': '::',
+                       'src': '10::10',
+                       'dst': '20::20',
                        'ext_hdrs': []}
         _ipv6_str = ','.join(['%s=%s' % (k, repr(ipv6_values[k]))
                               for k, v in inspect.getmembers(p_ipv6)
 <at>  <at>  -1307,8 +1307,8  <at>  <at>  class TestPacket(unittest.TestCase):
         eq_(len(ic_buf), p_ipv6.payload_length)
         eq_(inet.IPPROTO_ICMPV6, p_ipv6.nxt)
         eq_(255, p_ipv6.hop_limit)
-        eq_('::', p_ipv6.src)
-        eq_('::', p_ipv6.dst)
+        eq_('10::10', p_ipv6.src)
+        eq_('20::20', p_ipv6.dst)

         # icmpv6
         ok_(p_icmpv6)
 <at>  <at>  -1319,7 +1319,7  <at>  <at>  class TestPacket(unittest.TestCase):
         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), 0)
+        eq_(packet_utils.checksum(t), 0x60)

         # to string
         eth_values = {'dst': 'ff:ff:ff:ff:ff:ff',
 <at>  <at>  -1336,8 +1336,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'payload_length': len(ic_buf),
                        'nxt': inet.IPPROTO_ICMPV6,
                        'hop_limit': 255,
-                       'src': '::',
-                       'dst': '::',
+                       'src': '10::10',
+                       'dst': '20::20',
                        'ext_hdrs': []}
         _ipv6_str = ','.join(['%s=%s' % (k, repr(ipv6_values[k]))
                               for k, _ in inspect.getmembers(p_ipv6)
--

-- 
1.9.1

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
Minoru TAKAHASHI | 30 Jul 07:31 2014
Picon

[PATCH 1/5] packet lib: ipv4: fix default arguments

Reported-by: Arne Goetje <arne_goetje@...>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@...>
---
 ryu/lib/packet/ipv4.py               |  4 ++--
 ryu/tests/unit/packet/test_packet.py | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py
index a252c70..4da0bcc 100644
--- a/ryu/lib/packet/ipv4.py
+++ b/ryu/lib/packet/ipv4.py
 <at>  <at>  -79,8 +79,8  <at>  <at>  class ipv4(packet_base.PacketBase):
     def __init__(self, version=4, header_length=5, tos=0,
                  total_length=0, identification=0, flags=0,
                  offset=0, ttl=255, proto=0, csum=0,
-                 src='0.0.0.0',
-                 dst='0.0.0.0',
+                 src='10.0.0.1',
+                 dst='10.0.0.2',
                  option=None):
         super(ipv4, self).__init__()
         self.version = version
diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py
index b4eacd6..891cbf1 100644
--- a/ryu/tests/unit/packet/test_packet.py
+++ b/ryu/tests/unit/packet/test_packet.py
 <at>  <at>  -630,11 +630,11  <at>  <at>  class TestPacket(unittest.TestCase):
         eq_(0, p_ipv4.flags)
         eq_(255, p_ipv4.ttl)
         eq_(inet.IPPROTO_SCTP, p_ipv4.proto)
-        eq_('0.0.0.0', p_ipv4.src)
-        eq_('0.0.0.0', p_ipv4.dst)
+        eq_('10.0.0.1', p_ipv4.src)
+        eq_('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), 0)
+        eq_(packet_utils.checksum(t), 0x1403)

         # sctp
         ok_(p_sctp)
 <at>  <at>  -673,8 +673,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'ttl': 255,
                        'proto': inet.IPPROTO_SCTP,
                        'csum': p_ipv4.csum,
-                       'src': '0.0.0.0',
-                       'dst': '0.0.0.0',
+                       'src': '10.0.0.1',
+                       'dst': '10.0.0.2',
                        'option': None}
         _ipv4_str = ','.join(['%s=%s' % (k, repr(ipv4_values[k]))
                               for k, v in inspect.getmembers(p_ipv4)
 <at>  <at>  -779,11 +779,11  <at>  <at>  class TestPacket(unittest.TestCase):
         eq_(0, p_ipv4.flags)
         eq_(255, p_ipv4.ttl)
         eq_(inet.IPPROTO_ICMP, p_ipv4.proto)
-        eq_('0.0.0.0', p_ipv4.src)
-        eq_('0.0.0.0', p_ipv4.dst)
+        eq_('10.0.0.1', p_ipv4.src)
+        eq_('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), 0)
+        eq_(packet_utils.checksum(t), 0x1403)

         # icmp
         ok_(p_icmp)
 <at>  <at>  -815,8 +815,8  <at>  <at>  class TestPacket(unittest.TestCase):
                        'ttl': 255,
                        'proto': inet.IPPROTO_ICMP,
                        'csum': p_ipv4.csum,
-                       'src': '0.0.0.0',
-                       'dst': '0.0.0.0',
+                       'src': '10.0.0.1',
+                       'dst': '10.0.0.2',
                        'option': None}
         _ipv4_str = ','.join(['%s=%s' % (k, repr(ipv4_values[k]))
                               for k, _ in inspect.getmembers(p_ipv4)
--

-- 
1.9.1

------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk

Gmane