Archive

‘Programmer’ 分类存档

How to get correct Yang configuration on ASR9k

Now some customer test netconf-yang on our XR platform. And frequency to check how to get correct yang config(XML), then they test the yang config by their controller to touch with our devices. Now there are several ways to achieve that, summed up to facilitate review:

Commit follow cmd:

netconf-yang agent ssh
ssh server v2
ssh server rate-limit 300
ssh server netconf vrf default
ssh server logging

Generate key:

#crypto key generate dsa
—————————————————

 

  • We can ssh 830 to asr9k paltform, then get the configuration, that should correct yang config, you can reference attachment at test-xml-by-ssh.txt
ssh [email protected] -p 830 -s netconf
  • We can build Netconf NED by pioneer in NSO, then sync-from devices, and “devices device 9001-A compare-config outformat xml”, that should correct yang config
  • After install NSO, we can use follow tools to achieve that function too
netconf-console -u cisco -p cisco --host 10.75.49.53 --port 831 --get-config

 

Btw, please attention “-” and “–” that maybe cause command issue.

Auto check share memory utilization for IOX by Python

Introduction

In some scenario, we need to monitor some data in router/switch by automation. This article will show example that how to check share memory utilization. And you can easy to change the script base on your requirement/scenario.

Prepare

Due to “telnetlib” couldn’t exactly check expect messages by read_until() function (that couldn’t control exactly time when the info return to buffer), so I change to “expect”. And follow Bo’s example Python Expect Demo, and there is a good documents for expect demo from IBM too: 探索 Pexpect,第 2 部分:Pexpect 的实例分析
完整阅读

INSTALL CISCO WAE 6.4.5

Introduction

After installed Centos 6.7 for CISCO WAE, I found python version is 2.6 that is much older, and I need ansible1.9, but Centos default upgrade to ansible2.2… in order to easy management ansible1.9 that is python package, I plan to install PIP. From official website, suggest not use 2.6 under pip, so I need to upgrade python to 2.7 too.

But I found WAE use 2.6 after I succeed upgrade python to 2.7…Summarized the totally steps that will help me review in future.

Upgrade Python

After checked from follow link, python 2.7.9 integrate pip, so install this version 🙂
https://pip.pypa.io/en/latest/installing/

1. Install some package that require by python

python have multi dependencie

[root@wae ~]# yum install gcc
[root@wae ~]# yum install openssl-devel

2. Install python 2.7.9

[root@wae ~]# wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tgz
[root@wae ~]# mv Python-2.7.9.tgz /opt/
[root@wae ~]# cd /opt/
[root@wae opt]# tar -xvf Python-2.7.9.tgz 
[root@wae opt]# cd Python-2.7.9
[root@wae Python-2.7.9]# ./configure --prefix=/usr/local/python2.7
[root@wae Python-2.7.9]# make
[root@wae Python-2.7.9]# make install

完整阅读

Do action by EEM+TCL after the log happen X Times in Y LC/RSP at ASR9k

Problem:

We can do more automated action by EEM + TCL on Cisco router, and have more trigger way for syslog pattern trigger, OID trigger, CPU Threshold trigger and so on. That will match IOS platform, no any issue. But in XR platform, each LC/RSP have separate alarm, we maybe have special requirement, e.g:

Some alarms frequency happen, I want to restart the process (base on pid) if the alarm happen 3 times in 5min on each LC, how to do that?

0/3/cpu0: alarm report "C", Pid = zzz
0/1/cpu0: alarm report "A", Pid = xxx
0/2/cpu0: alarm report "B", pid = yyy
0/3/cpu0: alarm report "C", pid = zzz
0/1/cpu0: alarm report "A", pid = xxx
0/1/cpu0: alarm report "A", pid = xxx

Solution:

We can do interactive script by TCL I/O, create a file in Harddisk/disk which has the history/count of syslog for Lcs. We can read this file using the script whenever the syslog is observed. Based on the number of syslogs the script can take the required action.

The steps will be like this, please check attachment and script flow chart for detail script, in my example, I only dump arp process for testing, please change script base on your requirement, in order to test script, you can add flag to test that, e.g “action_syslog priority info msg “a””: 完整阅读

JAVA FileInputStream 和 FileReader的区别

在写检索文件的函数时,发现读取文件有两种方式,一种是FileInputStream,另一种是FileReader。它们的本质区别就是FileReader读取的是字符数据,而FileInputStream读取的是字节数据,举个简单的例子就知道了,另外下面两篇文章讲这个不错,详细可以点进去看:

java读取文件
Java FileInputStream与FileReader的区别
[Java]读取文件方法大全

package pkg;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;

public class ReadFile {
    public static void main(String args[]) {
 
        // 例1 – 使用FileInputStream 读取文件内容
        try (FileInputStream fis = new FileInputStream("test.log")) {
            int da = fis.read(); //读取流中的第一个字节数据
            while (da != -1) { //未到达流的末尾
                System.out.print(Integer.toHexString(da)+" ");
                da = fis.read(); //读取第二个字节数据
            }
            System.out.println();
        } catch (IOException e) {
            System.out.println("Failed to read binary data from File");
            e.printStackTrace();
        }
 
        // 例2 – Java中使用FileReader 读取文件数据
        try (FileReader reader = new FileReader("test.log")) {
            int ch = reader.read();
            while (ch != -1) {
                System.out.print((char) ch);
                ch = reader.read();
            }
        } catch (IOException io) {
            System.out.println("Failed to read character data from File");
            io.printStackTrace();
        }
    }
}

输出结果:

ef bb bf 68 65 6c 6c 6f 21 
hello!
blonde teen swallows load.xxx videos