BGP AIGP and BGP churn

I have read BGP churn before, I find the meaning and then forget about it until next time.

BGP churn = the rate of routing updates that BGP routers must process.

And I can’t really find a straight definition.

As well, I didnt know the actual meaning of churn was. So it s a machine to produce butter and the amount of customer stopping using a product.


I read at work something about AIGP from a different department. I searched and found that is a new BGP optional non-transitive path attribute and the BGP decision process is updated for that. And this is from 2015!!! So I am 6 years behind…. And there is a RFC7311

Note: BGP routers that do not support the optional non-transitive attributes (e.g. AIGP) must delete such attributes and must not pass them to other BGP peers.

So it seems a good feature if you run a big AS and want BGP to take into account the IGP cost.

grep multiline

I want to count the number of interfaces that have some specific configuration in my router. I want to use the most basic tools found in linux (so dont have to assume anything else is installed) and I want to use as less commands as possible.

So this is my config:

frr version 7.5
frr defaults traditional
hostname R2
log syslog informational
no ipv6 forwarding
service integrated-vtysh-config
!
interface ens6
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo1
 ip router isis ISIS 
 isis passive
!
interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo2
 ip router isis ISIS 
 isis passive
!
mpls ldp
 router-id 172.20.15.2
 !
 address-family ipv4
  discovery transport-address 172.20.15.2
  !
  interface ens6
  !
  interface ens7
  !
 exit-address-family
 !
!
router isis ISIS 
 net 49.0001.1720.2001.5002.00
!
line vty
!

And I want to count the number of interfaces that have “isis network point-to-point” regardless of any other config.

In this example, we have just two interfaces.

interface ens6
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point

interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point

The pseudo-pattern should be something like:

^interface ens.*point-to-point$

So something that starts with “interface ens”, it can have anything after that and then it ends with “point-to-point”

Ideally I want to use just “grep” and it is a standard and common tool

But grep mainly works in one line each time. And my pattern covers multiple lines.

So I searched for some help and found this that uses “perl compatible regular expressions” (PCRE). I have no idea about perl but let’s give it a go:

$ grep -Pz '(?s)interface ens.*point-to-point\n' r5.txt
frr version 7.5
frr defaults traditional
hostname R2
log syslog informational
no ipv6 forwarding
service integrated-vtysh-config
!
interface ens6
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo1
 ip router isis ISIS 
 isis passive
!
interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo2
 ip router isis ISIS 
 isis passive
!
mpls ldp
 router-id 172.20.15.2
 !
 address-family ipv4
  discovery transport-address 172.20.15.2
  !
  interface ens6
  !
  interface ens7
  !
 exit-address-family
 !
!
router isis ISIS 
 net 49.0001.1720.2001.5002.00
!
line vty
!

Let’s explain the parameters provided to grep so far:

  • -P: Use perl compatible regular expressions (PCRE).
  • -z: Treat the input as a set of lines, each terminated by a zero byte instead of a newline. i.e. grep treats the input as a one big line.
  • (?s): activate PCRE_DOTALL, which means that ‘.’ matches any character or newline.

But if I count, we dont have the expected answer of 2:

$ grep -Pzc '(?s)interface ens.*point-to-point\n' r5.txt
1

The “z” parameter is treating the file as a single line so for grep, there is one match only. The initial command shows in bold just one block.

We notice that the pattern is matching “interface lo1” and that is not what we want, it should be ignored.

So our pattern should match the smallest string. So we want a non-greedy matching regex. So searching again, found this. It seems for Perl regex, we need to use ? after *

$ grep -Pz '(?s)interface ens.*?point-to-point\n' r5.txt
frr version 7.5
frr defaults traditiona
hostname R2
log syslog informational
no ipv6 forwarding
service integrated-vtysh-config
!
interface ens6
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo1
 ip router isis ISIS 
 isis passive
!
interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
!
interface lo2
 ip router isis ISIS 
 isis passive
!
mpls ldp
 router-id 172.20.15.2
 !
 address-family ipv4
  discovery transport-address 172.20.15.2
  !
  interface ens6
  !
  interface ens7
  !
 exit-address-family
 !
!
router isis ISIS 
 net 49.0001.1720.2001.5002.00
!
line vty
!

So now, we can see two blocks highlighted. So now let’s print only the matched strings using -o:

$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt
interface ens6
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point

So this looks correct but still counting (-c) doesnt work properly because -z is treating the entry as one big line.

I haven’t been able to find the solution with just one command so at the end, I have to pipe another grep. The initial grep matches the pattern, so the second one should just count a specific pattern like “point”. It should be that simple:

$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt | grep point
grep: (standard input): binary file matches

Weird, I thought this was pure text but seems the ouput of the first grep has some binary data:

$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt > r55.txt
$ vim r55.txt
interface ens6
 ip router isis ISIS
 isis circuit-type level-2-only
 isis network point-to-point
^@interface ens7
 ip router isis ISIS 
 isis circuit-type level-2-only
 isis network point-to-point
^@

But we can tell grep to read binary data too using -a as per this blog and then count.

$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt | grep -a point
 isis network point-to-point
 isis network point-to-point
$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt | grep -ac point
2

Funny enough, if I just want to count, I dont need -a:

$ grep -Pzo '(?s)interface ens.*?point-to-point\n' r5.txt | grep -c point
2

So not sure if this is the best solution but it took me a bit to find it. It seems to work:

grep -Pzo ‘(?s)interface ens.*?point-to-point\n’ r5.txt | grep -ac point

Veggie Lasagne

Last week I fancied a lasagne but I didnt have mince meat so I decided to try a veggie version based on a vegan dish I cooked for a friend in Christmas. You replace the mince meat with shredded mushrooms.

Ingredients:

  • 500gr of chestnut mushrooms
  • garlic + 1 onion, oregano.
  • tomato sauce, splash of read wine
  • roasting veggies: 1 onions, 1 red pepper, 1 green pepper, 1 courgette, 1 potato
  • milk, flour and butter for the white sauce. Nutmeg
  • lasagne sheets (3 layers, 9 sheets in my case)
  • grated cheese
  • olive oil, salt, pepper

Process:

  • Pre-heat oven at 180C. Chop all roasting veggies, coat with a bit of olive oil and a pinch of pepper/salt. Put in the oven.
  • In a food processor, put all mushrooms and whizz until shredded.
  • In a pan, add olive oil, once hot, and the garlic. Cook for a minute, then add the onion, cook for a couple of minutes, then add the mushrooms. Cook for a bit, then add the tomato sauce. Pinch of salt/pepper to taste. Add some oregano and splash of red wine.
  • Once the mix thickens up, remove from the heat.
  • Check the roasting veggies.
  • Prepare the white sauce. In a saucepan at medium heat, put a big know of butter. Once melted, add 3 big tsp of flour. Mix until all combine. Then start pouring some milk, and whisk. Then keep adding milk bit by bit until you have a smooth, not very thick sauce. Add nutmeg, salt, pepper. Taste.
  • Veggies should be ready.
  • Time to assemble everything.
  • In ovenproof glass dish, spread a bit of the white sauce (or butter) in the bottom. Then add a layer of lasagne sheets. Then add half of the mushroom mix, add half of the roasting veggines, add some white sauce. Add a new layer of lasagne sheets, the rest of the mushrooms mix and veggies, add a bit of white sauce. Finally the last layer of lasagne sheets. Pour all the white sauce and spread the grated cheese.
  • Put the lasagne in the already hot oven for 30 minutes or until cheese is crispy.

Really happy with the result!

Ginger, Date and Oats loaf

This cake doesnt have a specific name. I found it in a magazine from my supermarket. I have a pile of recipes collected over the years and rarely try them. But I fancied cooking something related to ginger and this cake looked ideal.

Ingredients:

  • 125g butter, softened
  • 50g of peeled ginger. Then grate it
  • 150g pitted dates (if they are hard, put them in boiling water for 30 minutes until soft)
  • 100g plain wholemeal flour
  • 75g oats
  • 4 eggs
  • 2 tsp baking powder
  • 3 tsp honey or agave sirup
  • 150g soft cheese
  • 1 lime zested

Process:

  • Preheat oven at 180C. Prepare a loaf tin with non-stick paper or spread some butter.
  • In food processor. Cream the butter, then add the grated ginger, dates, flour and oats. Once all combined (pieces of date are ok), add eggs, baking powder and honey.
  • Pour the mix into the tin. Bake it for 1h. Cover with foil for the last 10-15 minutes if it browns to much. Remove from the oven once you insert a knife and comes out clean
  • While it rests, whisk the soft cheese, 1 tsp honey and the lime zest. Give a taste, it should have a hint of lime, no too strong.
  • The spread the mix on top of the cake. Ready to eat!

It doesnt taste too sweet (most sugar comes from the dates). And the ginger taste is not very strong neither. Having the soft cheese with lime I think it balances. Maybe I should have added more lime but for the first time, it was good!

A Solas

A very good friend recommend me this book. And I actually needed to read something about it. Being alone is normal for me. It is one of the reasons I can do all I want at the end of the day. But still, I am a human being and you need some interaction. The last months have been tough because work, lockdown and my lack of communication skills. But mainly work.

This book has been a reminder from others books I have read from Rafael Santandreu that really changed a lot of thing about me. It was really helpful. It got me to my next stage in life.

But again, sometimes you have to remember why you believe in what you believe. Being alone, being solitary in general is seen as something bad/negative by society directly or indirectly (family, friends, books, movies, music, etc) And then we add our own judgement.

I need to recognize my main reason to be alone is the fear of rejection. Mainly with girls.

But in the last years I learned to love myself as I am, to be happy as I am, to be comfortable as I am, to be content with my life, to be content to be alone.

I have read in many places that if you are not happy with yourself, how you can be happy with somebody else? I truly believe in that.

And once those concepts took hold me, I felt better and even managed to find a girlfriend and live together! Difficult to believe some time ago, but happened. And it happened because I was comfortable being alone, I was enjoying my life. Again, I am not the most sociable person, and I used to punish me for that. But I accepted that is nothing wrong with that, you remove a lot of negative from you. Then you walk lighter.

And this book’s focus in being alone and relationships. And for me it is very clear that I prefer to be alone that in bad company. But I need to make the effort to open up, not being afraid.

So it is a question of balance, extremes are rarely good.

And this is the book all about: find the pleasure being alone, love yourself and whatever comes, it comes.

Stock Operator

This book was recommended by last employer CEO. It is based on the life of a stock trader Jesse Livermore from the early XX century.

One of the first shocking things in the book is in the introduction. This is a book about speculation.

That tells you a lot what was the market before, and what is today.

He made millions trading, lost them, recover, and at the end commit suicide. Still the book has good points for a trader point of view. I will never be a trader, because long term, very few, win.

I like his beginning in the trading world. He was very good at the bucket shops and he was forbidden to trade once he beat the house each time. Like in a casino.

One thing I realised about his trading in bucket shops is, his actions didn’t have impact in the market so it was a very reliable technique. But when he moved to the real market, he struggled. It is like the Schrodinger’s cat, until you dont trade, dont know if the stock is going to go up or down. And the other one, is the execution time. Low latency in those times were via telegraph lines, and they were critical. It is seems Western Union started in that business. If you have to buy many shares, very likely you will not buy all of them at the same price (it will go up, so it will be more expensive for you) and it will take some time. So for that period of execution, you are a bit at the mercy of the “market”.

There are many references to other early grate traders, scandals, crisis, etc. It was interesting how the American Civil War was financed by selling bonds to the European markets and then how during the WWI, all Europe gold came back to USA to finance all the arms needed for the war.

War is business. And then, they tell you is patriotic.

Another curious thing, is the trade of cane sugar. There was so much sugar that it was needed a market for it so it wouldn’t crash… then it was invented our “sugary breakfasts” and the chocolate bars!

At the end, I noticed that the whole trading experience could be repeated in our days without much difference. Maybe without the excess like the Wolf of Wall Stree movie/book.

Decorators

Trying to make a small change to a python program in my job, I came across something I didnt know in python and only after reading this article (a couple of times) I managed to understand (ask me again in 3 weeks 🙂 The best definition I could find was actually from other blog reference and actually I think it was more clear to me.

“A decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.”

1 – Function returning a function:

In [7]: def greet(name): 
   ...:     return f"Hello, {name}!" 
   ...: def simon(func): 
   ...:     return func("Simon") 
   ...:                                                                                                                       

In [8]: simon(greet)                                                                                                          
Out[8]: 'Hello, Simon!'

simon is a function that has a function as argument, and calls that function with the argument “Simon”. So the function greet is receiving the argument “Simon” and returns a string with that name.

2 – Functions inside other functions:

In [9]: def respect(maybe): 
   ...:     def congrats(): 
   ...:         return "Congrats, bro!" 
   ...:     def insult(): 
   ...:         return "You're silly!" 
   ...:     if maybe == "yes": 
   ...:         return congrats 
   ...:     else: 
   ...:         return insult 
   ...:                                                                                                                       

In [10]: respect("hola")()                                                                                                    
Out[10]: "You're silly!"

In this case, to execute the returned function you need to use “()” at the end (because respect(“hola”) it is a function!): respect(“hola”)()

Keep in mind you return the function “congrats” and it is not executed. If you return “congrats()” then yes, you get the result of executing congrats.

3 – A function that takes another function and defines a function:

In [1]: def startstop(func): 
   ...:     def wrapper(): 
   ...:         print("Starting...") 
   ...:         func() 
   ...:         print("Finished!") 
   ...:     return wrapper 
   ...: def roll(): 
   ...:     print("Rolling on the floor laughing XD") 
   ...: roll = startstop(roll)                                                                                                

In [2]: roll()                                                                                                                
Starting...
Rolling on the floor laughing XD
Finished!

In [3]:        

This case is the same as before, need to use “()” to “execute” roll because it is a function.

4 – With decorator:

In [3]: def startstop(func): 
   ...:     def wrapper(): 
   ...:         print("Starting...") 
   ...:         func() 
   ...:         print("Finished!") 
   ...:     return wrapper 
   ...: @startstop 
   ...: def roll(): 
   ...:     print("Rolling on the floor laughing XD") 
   ...:                                                                                                                       

In [4]: roll()                                                                                                                
Starting...
Rolling on the floor laughing XD
Finished!

In [5]:          

So adding the decorator we avoid writing a line with nested functions. That in a more advanced case, it would make the code easier to read.

You can nest decorators and add arguments too.

Katmer

I love bread and I watch a lot of videos about cooking that come up randomly. And this one is something that caught my attention. This looks like it is a typical fried bread or pancake in central Asia. The video shows the Turkish version so I decided to give it a go:

Ingredients:

  • 2 glass of plain flour
  • 3/4 glass of water
  • 1 tsp of salt
  • 1/2 tsp of sugar
  • 75g butter melted
  • 1/4 glass vegetable oil

Process:

  • Mix salt and sugar in water. Add the water the flour and mix all well together.
  • Knead for 5 minutes. Let it rest and then knead again for a couple of minutes. Rest again for 15 minutes.
  • Knock the dough and form a rounded ball. Cut in four pieces and then each piece in two. In total you will have eight pieces. You can make it bigger though.
  • Round each dough ball and let is rest in a floured surface.
  • Mix the butter and vegetable oil.
  • This is the difficult part and is better to watch the video a couple of times. Be sure you have your surface properly floured (I am not used to) for the next step.
  • Using a rolling pin, try to make the thinnest layer you can, if rectangle shape, the better. Then spread some butter mix on it. Fold one third from the right side, spread some oil, fold the other third on top of the oiled one. Oil again. You should have a rectangle. Fold a third from the bottom, oil and fold finally from the top. You should have like a handkerchief .
  • In a medium/hot pan, with just a bit of oil, fry each unit until golden/crispy each side. If you are good, it will bubble up! (just a bit in my case)

It took me a bit and I struggled with rolling pin as I am not used to this kind of dough. But the result was good, very crispy! (I need much practice to reach the level of the video)