~ubuntu-branches/ubuntu/utopic/exabgp/utopic

« back to all changes in this revision

Viewing changes to lib/exabgp/bgp/message/notification.py

  • Committer: Package Import Robot
  • Author(s): Henry-Nicolas Tourneur
  • Date: 2014-03-08 19:07:00 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140308190700-xjbibpg1g6001c9x
Tags: 3.3.1-1
* New upstream release
* Bump python minimal required version (2.7)
* Closes: #726066 Debian packaging improvements proposed by Vincent Bernat
* Closes: #703774 not existent rundir (/var/run/exabgp) after reboot

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
Copyright (c) 2009-2013 Exa Networks. All rights reserved.
7
7
"""
8
8
 
9
 
from exabgp.bgp.message import Failure, Message
 
9
from exabgp.bgp.message import Message
10
10
 
11
11
# =================================================================== Notification
12
12
# A Notification received from our peer.
13
13
# RFC 4271 Section 4.5
14
14
 
15
 
class Notification (Message,Failure):
16
 
        TYPE = chr(0x03)
 
15
# 0                   1                   2                   3
 
16
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 
17
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
18
# | Error code    | Error subcode |   Data (variable)             |
 
19
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
20
 
 
21
 
 
22
class Notification (Message):
 
23
        TYPE = chr(Message.Type.NOTIFICATION)
17
24
 
18
25
        _str_code = {
19
26
                1 : "Message header error",
76
83
                (6,6) : "Other Configuration Change",
77
84
                (6,7) : "Connection Collision Resolution",
78
85
                (6,8) : "Out of Resources",
 
86
                # draft-keyur-bgp-enhanced-route-refresh-00
 
87
                (7,1) : "Invalid Message Length",
 
88
                (7,2) : "Malformed Message Subtype",
79
89
        }
80
90
 
81
 
        def new (self,code,subcode,data=''):
 
91
        def __init__ (self,code,subcode,data=''):
82
92
                self.code = code
83
93
                self.subcode = subcode
84
94
                self.data = data
85
 
                return self
86
 
 
87
 
        def factory (self,data):
88
 
                return self.new(ord(data[0]),ord(data[1]),data[2:])
89
95
 
90
96
        def __str__ (self):
91
97
                return "%s / %s%s" % (
95
101
                )
96
102
 
97
103
 
 
104
def NotificationFactory (data):
 
105
        return Notification(ord(data[0]),ord(data[1]),data[2:])
 
106
 
 
107
 
 
108
 
98
109
# =================================================================== Notify
99
110
# A Notification we need to inform our peer of.
100
111
 
101
112
class Notify (Notification):
102
 
        def __init__ (self,code,subcode,data=''):
103
 
                Notification.__init__(self)
104
 
                self.new(code,subcode,data)
 
113
        def __init__ (self,code,subcode,data=None):
 
114
                if data is None:
 
115
                        data = self._str_subcode.get((code,subcode),'unknown notification type')
 
116
                Notification.__init__(self,code,subcode,data)
105
117
 
106
118
        def message (self):
107
 
                return self._message("%s%s%s" % (chr(self.code),chr(self.subcode),self.data))
 
119
                return self._message("%s%s%s" % (
 
120
                        chr(self.code),
 
121
                        chr(self.subcode),
 
122
                        self.data
 
123
                ))