<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Egor Krivosheev on Medium]]></title>
        <description><![CDATA[Stories by Egor Krivosheev on Medium]]></description>
        <link>https://medium.com/@Vasya4k?source=rss-4b8e478e9967------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FcesSAVGAAOsVxTD8tTYew.jpeg</url>
            <title>Stories by Egor Krivosheev on Medium</title>
            <link>https://medium.com/@Vasya4k?source=rss-4b8e478e9967------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:51:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Vasya4k/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Go Streaming Telemetry]]></title>
            <link>https://medium.com/@Vasya4k/go-streaming-telemetry-6f03fbd6db62?source=rss-4b8e478e9967------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f03fbd6db62</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[telemetry]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[network-automation]]></category>
            <category><![CDATA[grpc]]></category>
            <dc:creator><![CDATA[Egor Krivosheev]]></dc:creator>
            <pubDate>Thu, 20 Dec 2018 23:07:59 GMT</pubDate>
            <atom:updated>2024-01-06T05:28:00.660Z</atom:updated>
            <content:encoded><![CDATA[<h3>Go OpenConfig Streaming Telemetry</h3><p>Streaming telemetry has been a hot topic in the networking industry for some time. However, there are still not many tools and examples around, and I hope this post will close the gap. Data models and YANG are intentionally left out and will be a part of future posts.</p><p>I have been using streaming telemetry for quite some time already and can provide useful examples to others. As in my previous posts, I will be using the Go programming language.</p><p>Let’s look at how this differs from what we had before. I am talking about protocols such as SNMP and collecting data via SSH screen scraping. The most significant difference is that we used to use a poll model where a script on an application polls a device for some data. In the case of SNMP, which works over UDP, there is no reliability built in, so we never know when data is lost, not to mention that it is almost impossible to get poll intervals shorter than five minutes. Using SSH screen scraping is another story, as CLIs were never designed for machine-to-machine communication; hence, it is challenging to parse out the required information. There are many more drawbacks associated with the protocols mentioned above, but I am not going to get into details as they have been discussed so many times already.</p><p>There are multiple implementations of streaming telemetry around. The first approach from vendors like Juniper, Cisco, and Arista was to stream data over UPD using binary formats like BSON, Protocol Buffers, and Apache Thrift. It was simple. You turn it on, and a device starts streaming packets containing telemetry data. The collector needed to have the schema provided by the vendors, and then it could decode the data. The downside of the first implementation was that it was not very flexible, as the collector could not manipulate the subscription. In other words, one could not tell a device what data to stream and how often. On the other hand, achieving a sub-second data frequency was possible, which is very useful for some environments.</p><p>After that, some vendors decided to use NETCONF and implement streaming telemetry using XML RPC over it. I have written several posts about NETCONF and how to use<a href="https://medium.com/@Vasya4k/netconf-how-to-get-going-fe632b1325b7"> it.</a> Cisco uses this approach in IOS XE and Huawei in some of their enterprise routers and switches. Typically, a client opens a NETCONF session over SSH and makes an XML RPC call. After that, a device starts periodically sending XML-encoded messages containing metrics. One of the downsides of this implementation is that XML is not a very efficient encoding format, as it takes more resources to encode than binary formats and takes more bits on the wire. One of the pros, however, is that it is human-readable(sort of).</p><p>Finally, there was Open Config Streaming Telemetry over gRPC, and it has two different protocol specifications. One would reasonably ask why there were two different specifications. Well, the first one only supports telemetry subscriptions, but then people decided they wanted to manage device configuration using gRPC, so there was a second one. Again, what about NETCONF? Is it not what we are supposed to use for configuration management? The answer to that is maybe, and it depends on your favourite vendor and what is available in the software they provide. Even though gRPC is a binary protocol that uses Protocol Buffers as message encoding, the telemetry data that comes inside those messages can be in different formats such as JSON document, XML, plain text, or binary. I have been working with telcos and service providers for some time now, and gRPC is becoming a standard when it comes to streaming telemetry. That is why I used it for my example.</p><p>Today, I will take you through a little app I wrote to illustrate how one would implement a gRPC collector. I use the Go programming language for most of the things I write nowadays, and it is a perfect match for a project like this.</p><p>Here are some moving parts of the project running each inside a Docker container.</p><ul><li>A gRPC Streaming Telemetry collector with a RESTful API</li><li>A WEB Interface served by Ngnix</li><li><a href="https://grafana.com/">Grafana</a></li><li><a href="https://www.influxdata.com/">Influx DB</a></li></ul><p>I am using docker-compose to make it easy for anyone to try streaming telemetry out using my collector, for the same reason I added a web interface. When a new device gets added or deleted, reloading a service is unnecessary, which is a must-have feature for any collector these days. Adding or removing devices on the fly is useful from the convenience point of view and because we do not want to have data loss. There is no time for the service to reload as the data stream frequency is high.</p><p>The repository for the project is <a href="https://github.com/vasya4k/sticoll">here</a>. To try it out, you only need to clone the repo, go inside the directory, and run.</p><p>docker-compose -f “docker/docker-compose.yml” up -d — build</p><p>As of today, only Juniper devices are supported and here is the <a href="https://www.juniper.net/documentation/en_US/junos/topics/concept/open-config-grpc-junos-telemetry-interface-understanding.html">documentation page</a> describing how to configure streaming telemetry. Now you can go to <a href="http://localhost:8080/">http://localhost:8080</a> in your browser and should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMb8PMK9IDjSRjk0BFxWpA.png" /><figcaption>WEB Interface Overview</figcaption></figure><p>When you add a new device, the collector is going to subscribe to the /interfacespath. The data is received as OpenConfig Data protobuf messages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db33505e42f7fd1f7d674076f5e49037/href">https://medium.com/media/db33505e42f7fd1f7d674076f5e49037/href</a></iframe><p>The data is in the KeyValue array, and if we were to print the data, it would look like this:</p><pre>Path: /interfaces/ key is __prefix__ and value is &amp;{/interfaces/interface[name=&#39;pfe-0/0/0&#39;]/}<br>Path: /interfaces/ key is name and value is &amp;{pfe-0/0/0}<br>Path: /interfaces/ key is state/type and value is &amp;{other}<br>Path: /interfaces/ key is state/mtu and value is &amp;{%!s(uint64=0)}<br>Path: /interfaces/ key is state/name and value is &amp;{pfe-0/0/0}<br>Path: /interfaces/ key is state/description and value is &amp;{}<br>Path: /interfaces/ key is state/enabled and value is &amp;{%!s(bool=true)}<br>Path: /interfaces/ key is state/ifindex and value is &amp;{%!s(uint64=514)}<br>Path: /interfaces/ key is state/admin-status and value is &amp;{UP}<br>Path: /interfaces/ key is state/oper-status and value is &amp;{UP}<br>subinterfaces/subinterface[index=&#39;16383&#39;]/state/admin-status and value is &amp;{UP}<br>Path: /interfaces/ key is subinterfaces/subinterface[index=&#39;16383&#39;]/state/oper-status and value is &amp;{UP}<br>Path: /interfaces/ key is subinterfaces/subinterface[index=&#39;16383&#39;]/state/last-change and value is &amp;{%!s(uint64=1005)}<br>Path: /interfaces/ key is __prefix__ and value is &amp;{/interfaces/interface[name=&#39;ge-0/0/0&#39;]/}</pre><p>We could dump the data into Influx DB as is, but I wanted to have a complete dataset for a component in a structure to be able to encode it in different formats, for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69dd7ae87dec204b01bbb28605cdd1ef/href">https://medium.com/media/69dd7ae87dec204b01bbb28605cdd1ef/href</a></iframe><p>Before storing the metrics in Influx DB, they need to be parsed, and here is how that works:</p><ul><li>A device streams KV pairs in portions of data contained inside OpenConfigData PB messages</li><li>KV pairs belonging to a single entity, say a physical interface, are separated by a __prefix__ key</li><li>There can be multiple occurrences of different metrics which belong to the same interface even within one OpenConfigData packet, meaning we can receive interface metrics multiple times, so we need to wait until we receive all of them.</li></ul><p>For example, we get the interface state in one message, and then we get the counters. Say you want to get all the available information about the physical interface: counters, queue stats, state, description. To get that data, you need to collect it from three different telemetry packets, and they do not necessarily arrive one after another.</p><p>The simplest part of this is saving data into Influx DB. All we need is to decide what data is used as field values and what data is used as tag values. Here is what I came up with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5f59fec1673a040e669118a654e1d79/href">https://medium.com/media/a5f59fec1673a040e669118a654e1d79/href</a></iframe><p>The project structure is as follows: <br>├── auth Protobuf defenitions for gRCP auth <br>├── cmd Collector itself <br>├── docker Docker compose files<br>├── Gopkg.lock Go dependency tool fie<br>├── Gopkg.toml Go dependency tool fie <br>├── README<br>├── rest API as package for the cmd<br>├── telemetry Openconfig streaming telemetry Protobuf defenitions<br>├── ui WEB Interface <br>└── vendor Go vendor for dependency management</p><p>The cmd directory contains the most interesting bits:</p><p>├── cmd<br>│ ├── aux.go<br>│ ├── compress.go<br>│ ├── grpc_stats.go<br>│ ├── influx.go<br>│ ├── interface_stats.go<br>│ ├── main.go<br>│ ├── my.db a DB with all device details, created on startup<br>│ ├── README<br>│ ├── sticol.toml config file for Influx DB and HTTP server<br>│ ├── subscribe.go<br>│ └── test.txt</p><p>I am using <a href="http://github.com/coreos/bbolt">BoltDB</a> key-value storage for device information such as IP address, port, username, and password. I recommend using structured <a href="http://github.com/sirupsen/logrus">logging</a> as it makes operating your code much easier.</p><p>Here are some parts of main.go such as application startup and goroutine management.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb5ca3b6d71fb549a4e7346cab5ff3bf/href">https://medium.com/media/bb5ca3b6d71fb549a4e7346cab5ff3bf/href</a></iframe><p>Here is a part of subscribe.go where we get new data, you can easily extend it by adding your data type and handler methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc04d911eee5d67ad890226bf2430a2f/href">https://medium.com/media/dc04d911eee5d67ad890226bf2430a2f/href</a></iframe><p>One of the main reasons why I did not use any of the existing tools is the output format. Most of the tools out there dump key-value pairs from<br>gRPC into some database. I, however, want to have structured data as it makes it easier to use by other developers who might not be familiar with networking at all. I use Apache Kafka between Influx and my collector application in the real world. Coming soon are data pipelines in networking.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f03fbd6db62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NETCONF how to get Going]]></title>
            <link>https://medium.com/@Vasya4k/netconf-how-to-get-going-fe632b1325b7?source=rss-4b8e478e9967------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe632b1325b7</guid>
            <category><![CDATA[network-automation]]></category>
            <category><![CDATA[netconf]]></category>
            <category><![CDATA[juniper]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Egor Krivosheev]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 09:51:55 GMT</pubDate>
            <atom:updated>2018-04-22T09:57:07.588Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is an example of how to get started with NETCONF, Go and JunOS. Most of networking vendors including Cisco, Juniper and Nokia support NETCONF in their operating systems.</p><p>In my previous post, I was showing how to get data from a networking device using SSH via terminal. But CLIs were created for humans, not programs so in most cases you need to deal with unstructured data. NETCONF, on the other hand, is an XML based protocol and was specifically designed for machine to machine communication.</p><p>Today I am going to be collecting information about the number of routes in each routing table on a Juniper router. I will also show how to sort using Go`s sort package. What we need first are the data structures where we will be unmarshalling our XML to from Juniper routers. Here are the ones for route summary information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41b37a25bdf70c1c53c934b09faaf748/href">https://medium.com/media/41b37a25bdf70c1c53c934b09faaf748/href</a></iframe><p>I have also included the original XML document which can be converted to Go structs using a tool called Chidley I have mentioned it before <a href="https://medium.com/@Vasya4k/golang-netconf-and-junos-1-8f7e52b270a">here</a>.</p><p>Once we have the structures, it is easy to connect and get routing information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bb1b1027fea9a8f8e25c5de287ced4a/href">https://medium.com/media/4bb1b1027fea9a8f8e25c5de287ced4a/href</a></iframe><p>You can see me using a NECONF library from Juniper, but it works for other vendors too as long as their NETCONF implementation complies with the RFC. Here are the steps the program performs to get the data.</p><p>If no username is provided as a flag, we get current from the environment var.</p><pre><br>if len(os.Args) &gt; 3 {<br> user = os.Args[3]<br>} else {<br> user = os.Getenv(&quot;LOGNAME&quot;)<br>}</pre><p>After that, the program connects to a device, executes “get-route-summary-information” method and unmarshals data into the variable of a custom struct type which I created earlier. Then, the program sorts the results by total route count and prints the results.</p><p>Please leave comments if you would like to see some specific examples. In my next posts, I will show how to make configuration changes using NETCONF.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe632b1325b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go and SSH for network devices]]></title>
            <link>https://medium.com/@Vasya4k/go-and-ssh-for-network-devices-128937852ccb?source=rss-4b8e478e9967------2</link>
            <guid isPermaLink="false">https://medium.com/p/128937852ccb</guid>
            <category><![CDATA[network-automation]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Egor Krivosheev]]></dc:creator>
            <pubDate>Sat, 21 Apr 2018 03:30:33 GMT</pubDate>
            <atom:updated>2018-04-21T03:30:33.055Z</atom:updated>
            <content:encoded><![CDATA[<p>It is nice that a lot of network devices have APIs now. But what if you need to work with some older ones which do not. The answer to this is good old screen scraping, and yes it is used a lot because there is an endless amount of devices which can only show you some essential data via CLI and not any other way. Code for this post is here <a href="https://github.com/vasya4k/runcmd">https://github.com/vasya4k/runcmd</a></p><p>Today I am going to show you an example of how to SSH almost any number of devices execute multiple commands and get output using Go programming language. There is a lot of other approaches out there, but I think this is the use case where Go shines because it has goroutines and these are lightweight threads each takes only 2 Kb of memory. Using Go, we can connect to hundreds or even thousands devices simultaneously.</p><p>Let`s start by importing the required libraries.</p><pre>import (<br> &quot;bufio&quot;<br> &quot;fmt&quot;<br> &quot;io&quot;<br> &quot;log&quot;<br> &quot;os&quot;<br> &quot;strings&quot;<br> &quot;time&quot;</pre><pre>&quot;github.com/howeyc/gopass&quot;<br> &quot;golang.org/x/crypto/ssh&quot;<br>)</pre><pre>)</pre><p>As you can see we are going to mainly use Go`s standard library with one exception for a secure password entry. We need to know the names of the devices we are connecting to so we need to read them from file.</p><pre>func readHosts(hostFile string) []string {<br> var hosts []string<br> file, err := os.Open(hostFile)<br> if err != nil {<br>  log.Fatal(err)<br> }<br> defer file.Close()<br> scanner := bufio.NewScanner(file)<br> for scanner.Scan() {<br>  hosts = append(hosts, strings.TrimSpace(scanner.Text()))<br> }<br> return hosts<br>}</pre><p>Now when we know the device names we need to prepare a SSH config.</p><pre>config := &amp;ssh.ClientConfig{<br>  User:            User,<br>  HostKeyCallback: ssh.InsecureIgnoreHostKey(),<br>  Auth: []ssh.AuthMethod{<br>   ssh.Password(passwd),<br>  },<br> }</pre><p>The InsecureIgnoreHostKey tells the SSH library to skip finger print verification. You should probably remove this when running production.</p><p>Now let`s move into the most interesting part of code, where we connect to a device and run some commands.</p><pre>func executeCmd(hostname string, cmds []string, config *ssh.ClientConfig) *[]string {<br> // Need pseudo terminal if we want to have an SSH session<br> // similar to what you have when you use SSH client<br> modes := ssh.TerminalModes{<br>  ssh.ECHO:          0,     // disable echoing<br>  ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud<br>  ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud<br> }<br> conn, err := ssh.Dial(&quot;tcp&quot;, hostname+&quot;:22&quot;, config)<br> if err != nil {<br>  log.Println(err)<br>  return &amp;[]string{1: hostname}<br> }<br> session, err := conn.NewSession()<br> if err != nil {<br>  log.Fatal(err)<br> }<br> // You can use session.Run() here but that only works<br> // if you need a run a single command or you commands<br> // are independent of each other.<br> err = session.RequestPty(&quot;xterm&quot;, 80, 40, modes)<br> if err != nil {<br>  log.Fatalf(&quot;request for pseudo terminal failed: %s&quot;, err)<br> }<br> stdBuf, err := session.StdoutPipe()<br> if err != nil {<br>  log.Fatalf(&quot;request for stdout pipe failed: %s&quot;, err)<br> }<br> stdinBuf, err := session.StdinPipe()<br> if err != nil {<br>  log.Fatalf(&quot;request for stdin pipe failed: %s&quot;, err)<br> }<br> err = session.Shell()<br> if err != nil {<br>  log.Fatalf(&quot;failed to start shell: %s&quot;, err)<br> }</pre><pre>for _, cmd := range cmds {<br>  stdinBuf.Write([]byte(cmd + &quot;\n&quot;))<br> }<br> res := make([]string, 0)<br> return readStdBuf(stdBuf, &amp;res)<br>}</pre><p>Please note that there are several ways of running commands via SSH, you could send a single command and get a response without pseudo-terminal allocation. However, this method does not allow to execute multiple related commands. If you want to configure something on a Cisco device you need to go into the config mode first and then a run configuration statements. Without PTY you won`t be able to do this as the “conf terminal” command will be executed independently of your next command.</p><p>What happens next is:</p><ol><li>SSH Dial call to connect to a device and get the transport layer up</li><li>Get a new session which allows us to request a PTY or a subsystem</li><li>A pseudo terminal request that gives you the interface you interact with when you connect to a device with an SSH client</li><li>Setup stdin and stdout pipes, I am intentionally missing a stderr pipe I leave it as exercise for a reader</li><li>Send commands to stdin</li><li>Recursively read from stdout until an empty prompt is seen</li></ol><p>One last note I wanted to add is how the empty prompt detection works. We wait for 100 milliseconds then read from the buffer then repeat until we see an empty prompt. In my opinion, a hundred milliseconds is an acceptable amount of time to wait during the last detection cycle. Also, the empty prompt itself can be a royal pain as some devices can add different prefixes or suffixes depending on command mode or active routing engine/control board/routing processor.</p><p>Code: <a href="https://github.com/vasya4k/runcmd">https://github.com/vasya4k/runcmd</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=128937852ccb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang, NETCONF and Junos #2]]></title>
            <link>https://medium.com/@Vasya4k/golang-netconf-and-junos-2-9f8fd2155b27?source=rss-4b8e478e9967------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f8fd2155b27</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[netconf]]></category>
            <category><![CDATA[network-au]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[juno]]></category>
            <dc:creator><![CDATA[Egor Krivosheev]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 09:01:23 GMT</pubDate>
            <atom:updated>2018-04-20T09:01:23.081Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I will be adding a web interface to the API which I created in my last post. I am going to be using <a href="https://vuejs.org/">Vue.js</a> as frontend framework and <a href="http://coreui.io/">CoreUI</a> as bootstrap admin template.</p><p>But before I start talking about the interface itself I want to talk about motivation.</p><p>First is the amount of sessions, you could probably deal with a hundred manually, but when it starts getting closer to a thousand (or much more in my case), it will get out of control. I need to be able to see how many of them are down, how long they have been down for and what is the reason why they are down. I do not want to ssh into hundreds of boxes trying to get all the information I need. All I want is to have a look and make a decision about what to do with the session.</p><p>The second reason is that having this interfaces allows moving responsibilities to a different team as it becomes a more straightforward task and requires less time and skill level.</p><p>The third one is statistics and data visualisation. In my opinion, it is sometimes hard to grasp the trends or even crucial insights from twenty console windows. It is however much easier to see them represented as graphs or counters on a web page.</p><p>Now let’s talk about the web frontend itself. I have chosen VueJS and CoreUI because of their ease of use. I have written couple of things in AngularJS 1.x before, but it seems like the web industry has moved on, so I decided to try something modern.</p><p>All you need to start you own CoreUI project with VueJS is to clone a GitHub <a href="https://github.com/mrholek/CoreUI-Free-Bootstrap-Admin-Template">repo</a>. There are two directories in that repo which are of your interest Vue_Full_Projectand Vue_Starter. First one has the code of the live <a href="http://coreui.io/demo/Vue_Demo/#/dashboard">demo</a> and the second one is so-called seed repo.</p><p>After you have cloned the repo, you need to have NodeJS and NPM installed on your Linux, Mac or Windows machine. I use Linux and <a href="https://code.visualstudio.com/">Visual Studio Code</a> as my code editor. It has great support for all the languages I use: Go, Python and Java Script. You can start writing you frontend in minutes following <a href="http://coreui.io/docs/getting-started/vue-js-version/">CoreUI guide</a>.</p><p>By default, VueJS does not have a library to work with HTTP you will need to find one yourself. The most popular one seems to be Axios npm install axios. Here is how I use it in my code</p><pre>.get(&#39;http://&#39; + window.location.hostname + &#39;:8888/bgpnei&#39;)<br>      .then(response =&gt; {<br>        // JSON responses are automatically parsed.<br>        var sessions = response.data<br>        for (var hidx = sessions.length - 1; hidx &gt;= 0; hidx--) {<br>          if (sessions[hidx][&#39;bgp-peer&#39;] !== null) {<br>            for (var nidx = sessions[hidx][&#39;bgp-peer&#39;].length - 1; nidx &gt;= 0; nidx--) {<br>              var nei = sessions[hidx][&#39;bgp-peer&#39;][nidx]<br>              nei.host = sessions[hidx].host<br>              this.sessions.push(nei)<br>            }<br>          } else if (sessions[hidx].err !== &#39;&#39;) {<br>            this.sessions.push(sessions[hidx])<br>          }<br>        }<br>      })<br>      .catch(err =&gt; {<br>        this.errors.push(err)<br>        console.log(err)<br>      })<br></pre><p>For someone who is just trying to develop his or her first web interface, it might look complicated as the starter directory has so many files from the beginning. At least it seemed complicated to me when I was starting up. The truth is that you do not need to understand every single feature of a package to be able to write a simple app.</p><p>For this example, I have only edited two files one inside src/views called Dashboard.vue and another one in src/router called index.js. Both JavaScript and HTML code go in the same file in Vue, and there are plugins for popular editors like Sublime, Atom, Web Storm and VS Code to help you with code formatting and so on. You can see in my code that I am using a template language called pug &lt;template lang=&quot;pug&quot;&gt; it looks like this:</p><pre>&lt;template lang=&quot;pug&quot;&gt;<br>  div.animated.fadeIn<br>    b-row<br>        b-col(md=&#39;12&#39;)<br>            b-card(header=&#39;BGP Sessions&#39;)<br>              b-row<br>                b-col(sm=&#39;12&#39;)<br>                  b-row<br>                    b-col(sm=&#39;3&#39;)<br>                        small.text-muted Total Sessions<br>                        br<br>                        |<br>                        strong.h4 {{ sessions.length }}<br>                        |<br>                        .chart-wrapper</pre><p>Vue will convert the above code into HTML. I think Pug is much easier to work with rather than plain HTML. You can read more about Pug <a href="https://pugjs.org/api/getting-started.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nMiUHoBt9Vv6FcA4.png" /></figure><p>As you can see on the screenshot it has a few counters like total session established sessions and others. It also has an edit box where you can enter filter criteria it currently supports only peer address and hostname, but you can extend it to any other field returned by a router.</p><p>This little app is just an example of what you can achieve by using NECONF on routers. It does not have any auth mechanism although one can add a Ngnix based reverse proxy with basic auth in front of it.</p><p>In the next part, I will be adding several features to the app such as an ability to delete, deactivate or activate a session with one button. And if I have time I will also add a feature to add a BGP session from a template.</p><p>It is also possible to add support for Nokia/Alu SR7750s and Cisco IOS-XR devices. I do have experience with them as well, but I am not sure if anyone from the audience will be interested.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f8fd2155b27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang, NETCONF and Junos #1]]></title>
            <link>https://medium.com/@Vasya4k/golang-netconf-and-junos-1-8f7e52b270a?source=rss-4b8e478e9967------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f7e52b270a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[juniper]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Egor Krivosheev]]></dc:creator>
            <pubDate>Thu, 04 Jan 2018 00:08:38 GMT</pubDate>
            <atom:updated>2018-01-04T00:08:38.372Z</atom:updated>
            <content:encoded><![CDATA[<p>The purpose of this post is to show how easy it is nowadays to use APIs on networking devices.</p><p>It is expected that people trying to understand and use my code have some basic knowledge of Go programing language.</p><p>I have decided to start with Network Configuration Protocol (NETCONF), Junos and BGP. The hope is that a lot more people are interested in getting something out of BGP rather than say RSVP-TE. The code is always available at <a href="https://github.com/vasya4k">https://github.com/vasya4k</a>.</p><p>Let’s talk about tools in general and the specific ones we are going to be using today. My programming language of choice is Go, but I will be trying to show examples in Python as I do understand that a lot more people are familiar with it. I will be using AngularJS &gt; 1.5.x on the frontend side when required.</p><p>Today I am going to be using Go, to retrieve “show bgp neighbour” information using NETCONF.</p><p>Here are some Go libraries I am going to use.</p><pre>import (<br>    // Structured logging <br>    &quot;github.com/Sirupsen/logrus&quot;<br>    // Modern CLI <br>    &quot;github.com/urfave/cli&quot;<br>    // Config files written in TOML<br>    &quot;github.com/spf13/viper&quot;<br>    // WEB framework lightwight and popular <br>    &quot;gopkg.in/gin-gonic/gin.v1&quot;    <br>    // Golang NETCONF lib from Juniper Networks<br>    &quot;github.com/Juniper/go-netconf/netconf&quot;<br>)</pre><p>Now I will describe how my little application is going to work. On startup, it will read it’s config and a list of devices. After that, it will be waiting for an HTTP GET to ip:port/bgpnei endpoint. When it receives a request, it will open concurrent connections to all routers from the list to collect BGP state for each neighbour. Then it will transform the data and return it as a JSON object. The data received from our API can then be used by a front-end application or by any other tool. The API does not add much value if you only have one vendor but imagine if you have three or more. You can provide a universal way for your monitoring system to talk to routers.</p><p>The big part of getting data from a router via NETCONF is parsing it into a struct known as unmarshaling. It looks like below in Go<br>err := xml.Unmarshal([]byte(reply.Data), &amp;bgpInfo)<br>where &amp;bgpInfo is a pointer to a struct. The struct must fully describe an XML schema for this to work. A structure can have more fields than XML document does but not less.</p><p>Some of you might already know that XML document describing “show bgp neighbour” is gigantic. It might take you the whole day just trying to create a Go struct describing it. Juniper currently supplies YANG models which should help a lot, but I was not yet able to find a working compiler to transform models into structs. Instead, I am using a tool called Chidley <a href="https://github.com/gnewton/chidley">https://github.com/gnewton/chidley</a> it converts an XML document into Go structs. You still need to do some manual work to bring it to the desired state, but it is not even remotely comparable to manually doing the whole thing.</p><p>You can find the code here <a href="https://github.com/vasya4k/gojun">https://github.com/vasya4k/gojun</a> . This post is the first in a series, and I will be adding more functionality to my app in each post. The intention is to build a small but complete app for network automation. The app will have most of the modern tech out there like gRPC, open config, streaming telemetry.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f7e52b270a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>