Skip to content

Commit e03da44

Browse files
Alex Le HeuxGIC-de
authored andcommitted
Add MED attribute to bgpupdate using --med XXX
1 parent 816fde0 commit e03da44

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

code/bgpupdate

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ MPLS_LABEL_MAX = 1048575
4444

4545
BGP_UPDATE_MIN_LEN = 34
4646
BGP_LOCAL_PREF_LEN = 7
47+
BGP_MED_LEN = 7
4748
BGP_MP_REACH_IPV4_FIXED_HDR_LEN = 14
4849
BGP_MP_REACH_IPV6_FIXED_HDR_LEN = 26
4950

@@ -177,6 +178,7 @@ def main():
177178
parser.add_argument('-f', '--file', type=str, default="out.bgp", help='output file')
178179
parser.add_argument('-w', '--withdraw', action="store_true", help="withdraw prefixes")
179180
parser.add_argument('-s', '--streams', type=str, help="generate BNG Blaster traffic stream file")
181+
parser.add_argument('--med', type=int, help="MED")
180182
parser.add_argument('--stream-tx-label', metavar='LABEL', type=label_type, help="stream TX outer label")
181183
parser.add_argument('--stream-tx-inner-label', metavar='LABEL', type=label_type, help="stream TX inner label")
182184
parser.add_argument('--stream-rx-label', metavar='LABEL', type=label_type, help="stream RX label")
@@ -358,6 +360,9 @@ def main():
358360
if args.local_pref is not None:
359361
local_pref_attr = BGPPathAttr(type_flags=64, type_code="LOCAL_PREF", attribute=BGPPALocalPref(local_pref=args.local_pref))
360362

363+
if args.med is not None:
364+
med_attr = BGPPathAttr(type_flags="Optional", type_code="MULTI_EXIT_DISC", attribute=BGPPAMultiExitDisc(med=args.med))
365+
361366
while len(prefixes):
362367
for nh_index in list(prefixes.keys()):
363368
prefix_list = prefixes[nh_index]
@@ -373,6 +378,10 @@ def main():
373378
remaining -= BGP_LOCAL_PREF_LEN
374379
path_attr.append(local_pref_attr)
375380

381+
if args.med is not None:
382+
remaining -= BGP_MED_LEN
383+
path_attr.append(med_attr)
384+
376385
if ip_version == 4:
377386
if labeled:
378387
remaining -= BGP_MP_REACH_IPV4_FIXED_HDR_LEN

0 commit comments

Comments
 (0)