Welcome to the third part of the Programming 101 for Network Engineers series. This is likely to be the most ‘straight up’ piece so far; all fact and almost no fun (but learning is right?). Sorry, but for now the comment and opinion need to be put aside as we get into some nitty-gritty. The following overview of programming language elements and those found in part four will provide a good foundation that can be built upon as we move into other topics and the detail of specific languages later in the series.
If you understand what these common elements and concepts are and when, where and why they are used, it’ll be easier to pick up a language and possibly understand the foundation of some of the new products available on the market. As with any field, there’s a fair bit of jargon to deal with, and understanding it is always useful.
This can’t just be a straight list or easily ordered; all these elements are interconnected in some way and explaining one often requires knowledge of another (sometimes you’ll need to walk and chew gum). I’ve tried to choose an order that starts with the simplest elements and works up, but that doesn’t always make sense. Rather than make this article too long, I’ve split it into two. The second should be out very soon.
Onto the elements and concepts that make up most languages. Let’s dive in!
The more Events that are available to you, the greater your control and capabilities, and the more granularity and sophistication you can bring to bear. I’ll deal with this in more detail in the upcoming Structure and Flow article.
I know it’s obvious, but since it’s also central, let’s be clear: the Value of something is the true known form of something at a particular point in time. So, the Value of the Expression 1 + 1 is 2 and nothing else; it can’t be changed or change unless we do something to change it. The value of the Command [[HTTP::uri]] is not [[HTTP::uri]]. It is unknown when we create our code, but the output (the returned or Substituted Value) of the Command (/test/index.html for example) is its Value. We may manipulate the URI in our programme, but at the point in time we received the request it can only have one Value.
A List is a Data Type (of sorts) and simply that – a linear list of Strings or other Data Types separated by spaces or some other delimiter. It may help to think of a List as a single row (and only a single row) of Values in an Excel spreadsheet or an interface range specification at the Cisco CLI . Here’s an example:
An Array is a Data Type and structure that maps Keys to Values, or to put it another way, holds one or more Key Value Pairs (KVPs). Think of an Array as a simple two column table of Variables (see next), the Value in the left column of each row is the Key (aka Index or name) and the Value in the right column is the associated actual Value. Here’s an example;
1=one 2=two 3=three
An Array is also known as a Hash, Map, Dictionary or Associative Array.
I like to think of a Variable as a bucket. It has a name (err, lets say ‘bucket’), but it can contain anything: water, wine, pasta, a four pack of Stella, whatever you like. It’s Data Type will likely be determined automatically (see later). It’s up to you to assign a Value to a Variable; otherwise, it will be empty. Typically, there are a number of Variable types available – for instance, global or connection specific. It’s good practise to confirm a Variable isn’t empty before you try and use it.
In most cases Arrays, Lists and Variables need to be Declared: specifically named and created (and possibly also assigned a Value) prior to being used or referenced. Not creating them in advance usually breaks things.
Substitution (aka Expansion)
As briefly demonstrated in Values above, when a programme or some piece of code within it is actually run, Commands that return a Value, Variable names and other elements are Substituted with the actual results of the Command, the Variable Value or whatever prior to execution (this is sometimes known as Evaluation).
if x+y == 9
if 1+3 == 9
after Substitution; the if Command itself is only run once this Substitution has occurred.
The State of something, like yourself, is the combination of all the possible Data and relevant Values associated with that ‘thing’ at any point in time. Think of this as your bank balance and related data at the end of the day; you’re 2500.25 in credit, 200 went in, 539 went out and you’ve received 0.001% interest of 0.25. That is the State of your bank account that evening when you go online and check it.
Where SDN and a network is concerned, State could consist of a connection table on a single device or perhaps a controller, a collection of known flows across the network, and/or a whole host of other pieces of data as they stand at a specific point in time. Within a programme State could be all of the things I’ve already mentioned, but at a more discreet level it’s the current Value of all the elements that actually hold a Value, be they Variables, Lists or something else. The point of an SDN controller would be to make decisions based on a full understanding of the State of the entire network under its control.
The grown up version of animal, mineral or vegetable. Programming (and computing itself) is all about data: ones and zeros, text, numbers, metadata, statistics, counters, measures and so on, although sometimes it’s forgotten. A network protocol itself is simply data structured and transmitted in a specific way (and Event order) in order to achieve a result – a functionality of some kind. It’s far more obvious in programming, but it’s the same old thing you do all the time. It’s also a fair deal of what your job is based on now I’d imagine.
There are a fair few Data Types, and each language may have its own name. But, this gives you the idea:
- String/Text – one or more alphanumeric characters (including numbers) such an IP address or URL
- Boolean – a zero or one
- Integer – a whole number such as: 11
- Floating Point – a number including a decimal point fraction such as: 1.1
- Enumerated – one of a restricted number of possible Values, such as days of the week. The Boolean, Date and Time Data Types are typically ‘built-in’ Enumerated Data Types
- List (literal Array)
- Object or Key Value Pair (KVP)
The type data definition is more important than may be immediately apparent. You may think 1 + 1 = 2, but if the Data Type is String, the actual result will be 11.
A Pattern is a sequence of (normally alphanumeric) characters, as defined by a Glob search pattern or Regular Expression: take *.log or *.log for example. In an SDN world (and even in the current networking domain where security and other functions are concerned), patterns are used to identify (or match against) the good, the bad, the dangerous, the priority and the cha-ching ba-bling high value of flows (or the Data within) which can then be dealt with accordingly.
I’m not a programmer by trade and far from an expert; I’m still in the process of learning myself. I see this as a plus; hopefully my journey will make yours that little bit easier. However, if you think I could have explained things better, or something is just plain wrong, do let me know.
Other articles in the series;