Friday, January 19, 2018

Cisco ATM / DSL setup and troubleshooting

Layers in the stack:

  • Layer 1 - DSL
  • Layer 2.1 - ATM
  • Layer 2.2 - RFC1483B
  • Layer 3 - IP

Point-to-Point / Multipoint Interfaces

Like Frame Relay, ATM supports two types of interface: point-to-point and multipoint. The one you choose determines whether you need to use the configuration commands that ensure IP-to-ATM mappings. After configuring the PVC itself, you must tell the router which PVC to use in order to reach a specific destination. Consider these options:
  1. Point-to-point subinterface - With point-to-point subinterfaces, each pair of routers has its own subnet. If you put the PVC on a point-to-point subinterface, the router assumes that there is only one point-to-point PVC configured on the subinterface. Therefore, any IP packets with a destination IP address in the same subnet are forwarded on this virtual circuit (VC). This is the simplest way to configure the mapping and is therefore the recommended method.
  2. Multipoint networks - Multipoint networks have three or more routers in the same subnet. If you put the PVC in a point-to-multipoint subinterface or in the main interface (which is multipoint by default), you need to either configure a static mapping or enable inverse Address Resolution Protocol (ARP) for dynamic mapping.

Inverse ARP on ATM Connections

On Ethernet networks, IP-based network devices use ARP when they know the destination layer 3 address and need to discover the destination MAC address. Layer 2 network devices use inverse ARP (InARP) when they know the destination MAC address and need to discover the destination layer 3 address.
On ATM networks, RFC 1577 (Classical IP and ARP over ATM), specifies mechanisms for address resolution and defines the Inverse ATM Address Resolution Protocol (InATMARP).
With InATMARP, the ATM interface knows the layer 2 address. This is the PVC’s virtual path identifier (VPI) or virtual channel identifier (VCI). However, it still needs to discover which IP address is reachable at the remote end of a connection. To do this, the router sends an InATMARP request over a virtual connection for the address of the other end.
Note: InATMARP is the same protocol as Ethernet InARP. This is defined in RFC 1293, with additional extensions to support ARP in an ATM network.

Neither a static mapping nor InARP are required on a point-to-point subinterface since there is a single VC (sh atm vc) and a single path for the traffic. The router simply consults the routing table and makes a forwarding decision: 
sh atm map # with P2P ATM interface output of this command is empty
show run int a2/0.3 
interface ATM2/0.3 point-to-point
  ip address 192.168.3.1 255.255.255.252 
  no ip route-cache 
  no ip mroute-cache pvc 0/300 !

InARP is enabled on multipoint links by default.

show atm map 
 Map list ATM1/1/0.100_ATM_INARP : DYNAMIC 
  ip 1.1.1.2 maps to VC 19, VPI 2, VCI 100, ATM1/1/0.100 
 Map list ATM1/1/0.200_ATM_INARP : DYNAMIC 
  ip 2.2.2.2 maps to VC 20, VPI 2, VCI 200, ATM1/1/0.200

The show atm map command displays the dynamic mapping through InATMARP, while the show arp and show atm arp commands do not.
 

Static IP to ATM VC Mappings

Static map lists are a Cisco IOS Software feature that offers an alternative to using the ATMARP and InATMARP mechanisms. Using static maps, you can associate a protocol address with an ATM address on a switched virtual circuit (SVC), or with a VPI or VCI on a PVC.
Note: Static map lists do not relate to RFC 1483 or RFC 1577 .

interface ATM1/1/0.200 multipoint 
  ip address 2.2.2.1 255.255.255.0 
  no ip directed-broadcast 
  pvc 2/200 
    inarp 5 
    protocol ip 2.2.2.2 broadcast

You can check the mapping using the show atm map command. As you can see, the mapping of layer 3 to layer 2 addresses is permanent rather than dynamic, as it was when you used InARP.

show atm map 
 Map list ATM1/1/0.100_ATM_INARP : DYNAMIC
ip 1.1.1.2 maps to VC 19, VPI 2, VCI 100, ATM1/1/0.100
Map list ATM1/1/0.200pvc20 : PERMANENT
ip 2.2.2.2 maps to VC 20, VPI 2, VCI 200, ATM1/1/0.200, broadcast


Using Point-to-point subinterface with LLC/SNAP RFC1483

LLC/SNAP RFC1483 sometimes called MER (MAC Address Encapsulation) or Enet encapsulation in some modems. To setup Bridging in Cisco Router:

interface ATM0
 no ip address
 atm ilmi-keepalive
interface ATM0.1 point-to-point
 description ===WAN===
 ip address 172.16.16.16 255.255.255.0
 no ip redirects
 no ip unreachables
 no ip proxy-arp
 ip verify unicast reverse-path
 atm route-bridged ip
 pvc 7/34
  encapsulation aal5snap
 !
end

To verify that router sees other end over ATM:
sh adjacency ATM0.1
Protocol Interface                 Address
IP       ATM0.1                    172.16.16.1(10)

Thursday, December 28, 2017

ATM (Asynchronous Transfer Mode)

Asynchronous Transfer Mode (ATM) is an International Telecommunication Union-Telecommunications Standards Section (ITU-T) standard for cell relay wherein information for multiple service types, such as voice, video, or data.  is transported in small, fixed-size packets/frames - cells. One cell is 53 bytes (48bytes is data and 5bytes is header). Such a small packet size allows to:
  1. send data with different latency requirements, using both channels with high and low bandwidth
  2. Integrate any type of data in one channel (data, voice, video etc.)
  3. Support point-to-point (p2p), point-to-multipoint (p2m) and multipoint-to-multipoint (m2m) connections.
ATM uses Asynchronous Time-Division Multiplexing (A-TDM).
ATM network is based on interconnected ATM switches. ATM network is hierarchy:
  • User's equipment connects to networks via User-Network Interface (UNI).
  • Connection between provided networks are made through Network-Network Interface (NNI).
To send data from sender to the receiver, ATM uses virtual circuits (VC). VC can be in 3 variations:
  1. PVC (Permanent VC) - created between two points and exists even if no data is transferred
  2. SVC (Switched VC) - created right before data transfer
  3. SPVC ( Soft PVC) - like PVC but VC is permanent only from customer equipment till the point-of-presence (POP) of the ATM provider, so that customers see connection as PVC, but provider can tear-down and reconnect VC between it's POP's as needed.
For packet routing  packet IDs are used (these are used in header):
  1. VPI (Virtual Path Identifier) - channel number.
  2. VCI (Virtual Channel Identifier) - connection number.

The Internet Protocol requires that hosts must be able to process IP data-grams of at least 576 bytes (for IPv4) or 1280 bytes (for IPv6). Because of its fixed 48-byte cell payload, ATM is not suitable as a data link layer directly underlying IP. So that ATM uses Segmentation and Reassembly (SAR) - an incoming packet from another protocol to be transmitted across the ATM network is chopped up into segments that fit into 48-byte chunks carried as ATM cell payloads. At the far end, these chunks are fitted back together to restore the original packet.

Since different types of data are encapsulated in different ways, the details of the segmentation process vary according to the type of data being handled. There are several different schemes (different types of services), referred to as ATM Adaptation Layer (AAL). Standardized AAL include:
  1. AAL1 -  used for constant bit rate (CBR) services and circuit emulation. Synchronization is also maintained at AAL1.  Can be used in E1/T1.
  2. AAL2 through AAL4 are used for variable bit rate (VBR) services. Can be used for voice, video, data sending
  3. AAL5 used for data with unspecified bit rate (UBR), it doesn't use synchronization and connection establishing (it's supposed that is such a case upper layers will control sync and connection issues). Can be used for IP.
Which AAL is in use for a given cell is not encoded in the cell. Instead, it is negotiated by or configured at the endpoints on a per-virtual-connection basis.

Because of SAR performance, ATM is not so good on high-speed links (ATM max speed can be 10Gbits/s). On slower or congested links (622 Mbit/s and below), ATM does make sense, and for this reason most ADSL systems use ATM as an intermediate layer between the physical link layer and a Layer 2 protocol(like PPP or Ethernet). (ATM is used between customer modem & provider DSLAM (DSL Access Multiplexer)).

AAL5-LLC/SNAP or AAL5-MUX

The AAL5 trailer does not include a type field. Thus, an AAL5 frame does not identify its content. This means that either the two hosts at the ends of a virtual circuit must agree a priori that the circuit will be used for one specific protocol (e.g., the circuit will only be used to send IP datagrams), or the two hosts at the ends of a virtual circuit must agree a priori that some octets of the data area will be reserved for use as a type field to distinguish packets containing one protocol's data from packets containing another protocol's data.
AAL5-LLC/SNAP encapsulation uses  LLC Encapsulation (RFC 2684 [formerly RFC1483] - Multiprotocol Encapsulation over ATM) followed by a SNAP (Subnetwork Access Protocol header if necessary (can present as "LLC" in modems):
  • LLC (IEEE 802.2 LLC) - is the upper sublayer of the data link layer (layer 2) of the OSI. The LLC sublayer provides multiplexing mechanisms (using SNAP) that make it possible for several network protocols to coexist within a multipoint network and to be transported over the same network medium. The LLC sublayer acts as an interface between the MAC sublayer and the network layer.
  • SNAP - carries protocol identifier in each packet (1byte), so that each packet can be sent to the proper driver on the receiving side. Multiple protocols can be sent over one VC.
 AAL5-MUX encapsulation uses VC-MUX (can present as "VC" in modems):
  • VC-MUX (VC Multiplexing) - each VC used only for carrying a single high-level protocol. 

PPPoA, PPPoE, RFC1483, IP over ATM

RFC1483B (Bridged) - Used to encapsulate bridged protocols inside ATM and carries Ethernet frame. Using the bridge mode allows to use another router (maybe with more features) to terminate the connection with something like Cisco's Dialer interface.
RFC1483R (Routed) - Used to encapsulate routed protocols inside ATM and doesn't carry Ethernet frame. If you are not receiving Ethernet frames from the provider, modem must be in routed mode.

With regards to LLC or VC-MUX, it will again depend on what your service provider is using to encapsulate its frames in ATM: AAL5MUX (VC-MUX) or AAL5SNAP (LLC)
  1. IP over ATM stack:
    1. IP
    2. RFC1483R
    3. AAL5
    4. ATM
  2. RFC1483 stack:
    1. IP, IPX etc.
    2. MAC
    3. RFC1483B
    4. AAL5
    5. ATM
  3. PPPoA stack:
    1. IP, IPX etc.
    2. PPP
    3. RFC2364 (PPP over AAL5)
    4. AAL5
    5. ATM
  4. PPPoE stack:
    1. IP, IPX etc.
    2. PPP
    3. PPPoE (Ethernet)
    4. MAC
    5. RFC1483B
    6. AAL5
    7. ATM

Friday, December 22, 2017

Java Euclidean algorithm (finding GCD / HCF)


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution {
    public static void main(String[] args) throws Exception {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try
        {
            int i1 = Integer.parseInt(bufferedReader.readLine());
            i1 = Math.abs(i1);
            int i2 = Integer.parseInt(bufferedReader.readLine());
            i2 = Math.abs(i2);
            int gcd = 0;
            while (true)
            {
                if (i1 > i2)
                {
                    if (i1 % i2 == 0)
                    {
                        gcd = i2;
                        break;
                    } else {
                        i1 = i1 % i2;
                    }
                }
                else if (i2 > i1)
                {
                    if (i2 % i1 == 0)
                    {
                        gcd = i1;
                        break;
                    } else {
                        i2 = i2 % i1;
                    }
                }
                System.out.println("i1 = " + i1 + " / i2 = " + i2);
            }
            System.out.println(gcd);
        } catch (Exception e)
        {
            throw e;
        }
    }
}

Tuesday, December 19, 2017

Java access modifiers keywords

Visibility Keyword Access
own class own package successor class all classes
Closed private YES NO NO NO
Package --- YES YES NO NO
Protected protected YES YES YES NO
Open public YES YES YES YES

vi / vim most used by me

vy or yl ("y" and lower case "L") - copy single character on which the cursor rests (to insert yanked/copied  character use p - will insert copied to the right of the cursor's current position).

Thursday, December 14, 2017

Java reading from console, reading from file

to read from console:

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String line = bufferedReader.readLine();
Integer number = Integer.parseInt(line);
bufferedReader.close();


to read from file:

String fileName = "/path/to/a/file"
FileInputStream fileInputStream = new FileInputStream(fileName);
fileInputStream.available(); // byte count of a file
int byteValue = fileInputStream.read(); //reads bit from a file
char charValue = (char) byteValue; // convert byteValue to an actual symbol
Integer number = Character.getNumericValue(charValue);

while (fileInputStream.available() > 0)
{
System.out.println((char) fileInputStream.read());
}

fileInputStream.close()

Wednesday, December 13, 2017

Using Selenium with Python & Firefox (geckodriver) CentOS

I'm going to use Python 2.7.5 installed by default.

Install Selenium:

sudo yum install python-pip -y
sudo pip install --upgrade pip
sudo pip install selenium
 

Install geckodriver:

tar xzvf  geckodriver-needed-version
mv geckodriver /usr/local/bin

Install Firefox Nightly:

As geckodriver Supported Firefoxen states:
geckodriver is not yet feature complete. This means that it does not yet offer full conformance with the WebDriver standard or complete compatibility with Selenium ....  Some features will only be available in the most recent Firefox versions, and we strongly advise using the latest Firefox Nightly with geckodriver....
Go to https://www.mozilla.org/en-US/firefox/58.0a1/releasenotes/ and download Firefox Nightly. It doesn't need installation or compiling, just "tar xjvf" tar.bz2  file in desired directory (/home , /opt etc.) the same directory will be used in the Python code in the below section.

Python code to test WebDriver:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver as wbdr

binary = wbdr.
firefox.firefox_binary.FirefoxBinary('/opt/firefox/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
browser.get("http://google.com")
browser.quit()
 
Newer versions of Selenium will not be supporting FirefoxBinary (some versions will give you Deprecation warning). Use below instead of FirefoxBinary:

opts = wbdr.firefox.options.Options()
opts.binary_location = '/home/admino/firefox/firefox'
srvc = wbdr.firefox.service.Service('/usr/local/bin/geckodriver')
browser = wbdr.Firefox(service=srvc, options=opts)