Time-based BGP policy routing
Petr Lapukhov describes an interesting scenarion in his post BGP Time-Based Policy Routing: a multi-homed customer that uses one upstream link (for example, more reliable but slower one) during the work hours, switching to the other upstream link (faster, less reliable) after that.
He uses BGP communities to achieve the switch (perfect solution if your ISP supports them) and time-based ACL in a route-map to set the community based on time-of-day. As Cisco changed the way BGP imports local routes in IOS release 12.3T, he then devises an ingenious solution based on reliable static routing to trigger a change in the IP routing table.
The optimum solution is way simpler: you just configure two EEM applets to perform clear ip route network command at appropriate times. Here is a tested configuration that changes BGP community of a locally sourced route one minute after the time-range changes state:
He uses BGP communities to achieve the switch (perfect solution if your ISP supports them) and time-based ACL in a route-map to set the community based on time-of-day. As Cisco changed the way BGP imports local routes in IOS release 12.3T, he then devises an ingenious solution based on reliable static routing to trigger a change in the IP routing table.
The optimum solution is way simpler: you just configure two EEM applets to perform clear ip route network command at appropriate times. Here is a tested configuration that changes BGP community of a locally sourced route one minute after the time-range changes state:
router bgp 65001
network 172.18.1.0 mask 255.255.255.0 route-map TimeBasedCommunity
!
ip access-list extended MatchWorkingHours
permit ip any any time-range WorkDay
!
time-range WorkDay
periodic weekdays 9:00 to 16:59
!
route-map TimeBasedCommunity permit 10
match ip address MatchWorkingHours
set community 10:25 additive
!
route-map TimeBasedCommunity permit 15
!
event manager applet WeekdayStart
event timer cron name "WeekdayStart" cron-entry "1 9 * * 1-5"
action 1.0 cli command "enable"
action 2.0 cli command "clear ip route 172.18.1.0"
!
event manager applet WeekdayEnd
event timer cron name "WeekdayEnd" cron-entry "1 17 * * 1-5"
action 1.0 cli command "enable"
action 2.0 cli command "clear ip route 172.18.1.0"
The cron-entry parameter in the event timer cron command specifies that the applet is run one minute after 9AM or 5PM (the reverse time/date order makes it particularly confusing) on every day of every month (the two asterisks) but only on weekdays (the 1-5 parameter for the day-of-week).
I've decided to create two EEM applets to be able to perform different actions on the start/stop events. If you don't need that functionality, just merge them into a single applet; the cron-entry then becomes "1 9,17 * * 1-5".
Yep, i've been told about the EEM solution a number of times already ;) It really is nice! However, to me, EEM is an "imperative language like" feature, that "tells" router exactly what to do and how to do it.
The beauty of (overall creepy :) reliable static routes solution is its "declarative" (descriptive) behavior, so very much native to IOS configuration style :)
EEM is powerful - I just like to find solutions that are built around IOS internal logic :) For real world, obviously, anyone should prefer the most simple way to do things :)
--
Petr Lapukhov
PS
Yes, i'm a declarative languages fan :) At least, i've been for quite some time in the past.
I agree with your definition of imperative vs. declarative languages ;) and I also like XSLT (and worked with Prolog in my academic days), but in most cases ease-of-implementation and (even more important) ease-of-maintenance wins over my personal preferences :)
Keep up the good work!
Ivan