Code Duplication    Length = 35-35 lines in 4 locations

lib/exabgp/configuration/announce/ip.py 1 location

@@ 146-180 (lines=35) @@
143
		return True
144
145
146
def ip (tokeniser,afi,safi):
147
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
148
	ipmask = prefix(tokeniser)
149
150
	nlri = INET(afi, safi, action)
151
	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
152
153
	change = Change(
154
		nlri,
155
		Attributes()
156
	)
157
158
	while True:
159
		command = tokeniser()
160
161
		if not command:
162
			break
163
164
		action = AnnounceIP.action.get(command,'')
165
166
		if action == 'attribute-add':
167
			change.attributes.add(AnnounceIP.known[command](tokeniser))
168
		elif action == 'nlri-set':
169
			change.nlri.assign(AnnounceIP.assign[command],AnnounceIP.known[command](tokeniser))
170
		elif action == 'nexthop-and-attribute':
171
			nexthop,attribute = AnnounceIP.known[command](tokeniser)
172
			change.nlri.nexthop = nexthop
173
			change.attributes.add(attribute)
174
		else:
175
			raise ValueError('unknown command "%s"' % command)
176
177
	if not AnnounceIP.check(change,afi):
178
		raise ValueError('invalid announcement (missing next-hop ?)')
179
180
	return [change]
181
182
183
def ip_multicast (tokeniser,afi,safi):

lib/exabgp/configuration/announce/vpn.py 1 location

@@ 75-109 (lines=35) @@
72
		return True
73
74
75
def ip_vpn (tokeniser,afi,safi):
76
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
77
	ipmask = prefix(tokeniser)
78
79
	nlri = IPVPN(afi, safi, action)
80
	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
81
82
	change = Change(
83
		nlri,
84
		Attributes()
85
	)
86
87
	while True:
88
		command = tokeniser()
89
90
		if not command:
91
			break
92
93
		action = AnnounceVPN.action.get(command,'')
94
95
		if action == 'attribute-add':
96
			change.attributes.add(AnnounceVPN.known[command](tokeniser))
97
		elif action == 'nlri-set':
98
			change.nlri.assign(AnnounceVPN.assign[command],AnnounceVPN.known[command](tokeniser))
99
		elif action == 'nexthop-and-attribute':
100
			nexthop,attribute = AnnounceVPN.known[command](tokeniser)
101
			change.nlri.nexthop = nexthop
102
			change.attributes.add(attribute)
103
		else:
104
			raise ValueError('unknown command "%s"' % command)
105
106
	if not AnnounceVPN.check(change,afi):
107
		raise ValueError('invalid announcement (missing next-hop, label or rd ?)')
108
109
	return [change]
110
111
112
@ParseAnnounce.register('mpls-vpn','extend-name','ipv4')

lib/exabgp/configuration/announce/label.py 1 location

@@ 75-109 (lines=35) @@
72
		return True
73
74
75
def ip_label (tokeniser,afi,safi):
76
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
77
	ipmask = prefix(tokeniser)
78
79
	nlri = Label(afi, safi, action)
80
	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
81
82
	change = Change(
83
		nlri,
84
		Attributes()
85
	)
86
87
	while True:
88
		command = tokeniser()
89
90
		if not command:
91
			break
92
93
		action = AnnounceLabel.action.get(command,'')
94
95
		if action == 'attribute-add':
96
			change.attributes.add(AnnounceLabel.known[command](tokeniser))
97
		elif action == 'nlri-set':
98
			change.nlri.assign(AnnounceLabel.assign[command],AnnounceLabel.known[command](tokeniser))
99
		elif action == 'nexthop-and-attribute':
100
			nexthop,attribute = AnnounceLabel.known[command](tokeniser)
101
			change.nlri.nexthop = nexthop
102
			change.attributes.add(attribute)
103
		else:
104
			raise ValueError('unknown command "%s"' % command)
105
106
	if not AnnounceLabel.check(change,afi):
107
		raise ValueError('invalid announcement (missing next-hop or label ?)')
108
109
	return [change]
110
111
112
@ParseAnnounce.register('nlri-mpls','extend-name','ipv4')

lib/exabgp/configuration/announce/path.py 1 location

@@ 69-103 (lines=35) @@
66
		return True
67
68
69
def ip_unicast (tokeniser,afi,safi):
70
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
71
	ipmask = prefix(tokeniser)
72
73
	nlri = INET(afi, safi, action)
74
	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
75
76
	change = Change(
77
		nlri,
78
		Attributes()
79
	)
80
81
	while True:
82
		command = tokeniser()
83
84
		if not command:
85
			break
86
87
		action = AnnouncePath.action.get(command,'')
88
89
		if action == 'attribute-add':
90
			change.attributes.add(AnnouncePath.known[command](tokeniser))
91
		elif action == 'nlri-set':
92
			change.nlri.assign(AnnouncePath.assign[command],AnnouncePath.known[command](tokeniser))
93
		elif action == 'nexthop-and-attribute':
94
			nexthop,attribute = AnnouncePath.known[command](tokeniser)
95
			change.nlri.nexthop = nexthop
96
			change.attributes.add(attribute)
97
		else:
98
			raise ValueError('unknown command "%s"' % command)
99
100
	if not AnnouncePath.check(change,afi):
101
		raise ValueError('invalid announcement (missing next-hop ?)')
102
103
	return [change]
104
105
106
@ParseAnnounce.register('unicast','extend-name','ipv4')