snaproute Go BGP Code Dive (1)

I often tell network engineers they need to learn to code—and they sometimes take my advice and run off to buy a book, or start an online program (which reminds me, I’m way, way behind in my own studies about right now). But learning to code, and being able to use that skill for anything are actually two different things. In fact, my major problem with my coding skills is finding projects I can undertake where I don’t feel like I’m wasting my time. Anyone want to write the world’s 25 millionth implementation of inserting the date and time into a document? No, I didn’t really think so.

So what can you do with coding skills? One thing you can do is <em?read the source. Thus, I’m starting an entirely new feature here at ‘net Work. Every now and again (which means I don’t know how often), I’m going to poke at some routing or control plane code or another, and try to figure out what it actually does. Why not just go through a single protocol line by line? Because—honestly—it’s not a useful way to approach a protocol in code. Rather—here is my first bit of advice—you want to learn how to ask a particular code base a specific question, or set of questions, and get a reasonable answer. Once you have this skill down, it might, or might not, be useful to become a full on coder. But a lot of people start at the wrong end of the stick, and end up with some basic coding skills and no real idea how to apply them.

To kick this series off, I’m going to start with something really basic, and unrelated to coding—the mechanics of actually getting a clone of an open source routing protocol repository on your local computer. These repositories aren’t large, so they won’t cost you a lot to carry around. Why not just access the respository remotely? I’ve found it’s just easier to understand code if I have a local copy, and a local (even if it’s skinny) tool set to work with. So let’s start with this simple bit, and see where it goes.

First, I want to find an open source code base to clone and start looking at. It might be natural to start with something in quagga, but I’m going to take a slightly different tack for this first look through code—I’m going to clone an opensource version of BGP written in Go. The specific version I’m going to clone is part of SnapRoute, who happens to be (like Cumulus) an open source routing stack company. I do intend to work with quagga in the future (in C, which is kindof my native language), but I thought I’d start someplace different for the moment.

A first note—I know nothing about Go as a language. I do know it’s a programming language of some sort, and I know it runs in a virtual machine, rather than being compiled into native processing code for any particular processor. This means Go is a compiled language, just like C. Python, for instance, is an interpreted language. Compiled languages are run through a compiler, and converted into actual machine code to run on a particular processor/etc. I’m not going to get into all the differences here, other than to note there is a difference. But the point is that if I can figure out what BGP in Go is doing, you can too. First lesson: language should never be a barrier to reading the source.

Now, to go get BGP in Go.

First things first, you need a GitHub account. So go to in another tab and create one. worry, I’ll wait.

Once you have your account, go to the SnapRoute l3 repository, which you will find here ( On the right side, you’ll see a green button:


Once you’ve clicked there, you’re going to see a secondary box pop up that looks like this:


Now click on “open in desktop.” If you don’t have a desktop version of Git installed, this is going to direct you to a page that will give you the right downloads and stuff to get it installed. Once you’re done with all of that, you’re going to get to a window that is going to ask you where to clone this repository. I have a git directory that’s off my main data files directory, which makes it easy for me to find the files once they’re cloned to my laptop. I would suggest you do the same thing, because you are going to want to be able to find these files easily from a command line.

Now, you might ask—why not just download a copy, rather than kicking up desktop Git and cloning the repository? The simple reason is this: if you clone the repository, you’re going to get updates to the code as folks make changes. If you just download the .zip file and push it into a directly, you’re not. It’s more useful to have the synchronized clone in the long term, because you’ll always be working with the latest code (in the main line, anyway—as people pull branches and the like, you might need to move to another branch or project, but I’ll leave these for some other day.”

When you’re done, you will have a new directory with the actual source of SnapRoute’s implementation of BGP, OSPF, and a few other layer 3 odds and ends in a directory on your hard drive. It should look something like this:


You can click on it to see a larger image. Yes, I use Windows. I know, I’m a throwback to the stone ages or something like that, but—honestly, I’ve used everything from a CoCo II through a Xerox Star through a Sun Workstation to a few dozen Apple boxes to DR-DOS boxes to WFWG 3.11 to… Well, whatever. It’s a tool, get over it.

This post has gone a bit long, so I’ll leave the next step—glomming on to a good set of editing tools and doing some basic recon—for the next post (whenever that might be).


  1. fredhsu on 27 June 2016 at 1:52 pm

    Hi Russ, quick correction on Go.. it is a compiled language not interpreted. It does have the ability to cross compile really easily, but does not run in a virtual machine. Really looking forward to this series!

    • Russ on 27 June 2016 at 8:07 pm

      You are correct — that’s what I get for writing about a language I know nothing about. 🙂 I’ve corrected the article.