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)

Tuesday, December 12, 2017

Cluster 1. HP DL380p Gen8 initial setup using Intelligent Provisioning: iLO4 & other firmware upgrade, host system (CentOS7) installation.

Minimum requirements concerning hardware servers:
  • Two servers with the following;
  • Two network switches - also you can interconnect network cables between both servers.
Technologies We Will Use while setting cluster up:
  • Red Hat Enterprise Linux 7
  • Red Hat Cluster Services:
    • Cluster Manager (corosync); Manages the starting, stopping and managing of the cluster.
    • Resource Manager (pacemaker); Manages cluster resources and services. Handles service recovery during failures.
    • Clustered Logical Volume Manager (clvm); Cluster-aware (disk) volume manager (backs GFS2 filesystems and KVM virtual machines).
    • Global File System version 2 (gfs2); Cluster-aware, concurrently mountable file system.
  • Distributed Redundant Block Device (DRBD); Keeps shared data synchronized across cluster nodes.
  • KVM; Hypervisor that controls and supports virtual machines.

Upgrading iLO4 & other firmware

Insert cable to the desired NIC port of the server. After powering server on, wait until this appears:

Press F10. 
Choose "Perform Maintenance", then "Intelligent Provisioning Preferences" here you can verify an IP address assigned via DHCP (if DHCP is used) or assign an IP manually (cable connected port is shown as tick in a green circle). This IP must have privilege to access the Internet. After verifying/assigning an IP  go back and choose "Firmware update" (If you want to view verified packets and download status during firmware updates availability testing - click "More"). All available packets will be shown and then you can choose needed updates and install them.
By default only IP address is assigned to the iLO via DHCP and no DNS or Default Gateway. To fix that access "iLO Configuration" ("Intelligent Provisioning" -> "Perform Maintenance"),  and check those below:

also disable IPv6 if you don't need it:

 Accessing iLO4

Insert network cable to the servers iLO port.
On the picture above you can see IPv4 which is assigned to the iLO via DHCP server. If you have firewall - give that IP permission to access the Internet (Internet access is needed in order to register your server). Access iLO via https://iLO_IPv4. Default User-name and Password are on the bottom of the tag on the front of the server:

Verify that "Administration" -> "Access Settings" -> "IPMI/DCMI over LAN Access" is "Enabled.
I don't exactly know why we need to assign iLO4 DNS Name, but I've assigned it (iLO DNS Name can be found on the same tag).
If you done some changes in a iLO4 Web GUI - you must to "Reset" iLO. This can be done either in the tab where you done changes, or via "Information" -> "Diagnostics" -> "Reset iLO"

Host system (CentOS7) installation

After upgrading firmware and verifying access to the iLO4, go to "Configure and Install" of the "Intelligent Provisioning":
  
 
Insert CentOS7 installation DVD into server's optical drive. 
Then:
Manual is selected because CentOS7 is not distinctly RHEL and  CentOS7 installation  media is not recognized by HP Intelligent Provisioning.

After hitting "Continue" HP Drivers related Warning message is shown, ignore this message and accept. After reboot CentOS7 installation will start and you'll see all HP RAID Logical Disks.

PS
On one of my servers IP (Intelligent Provisioning) is not working and I installed OS using USB Flash:

  1. Download CentOS 7
  2. lsblk -a #find a proper USB Flash i.e. /dev/sdb
  3. fdisk /dev/sdb #create partition if no one exists
  4. lsblk -a # find created partition label i.e. /dev/sdb1
  5. mkfs.fat /dev/sdb1 or mkfs.vfat /dev/sdb1
  6. Write downloaded CentOS 7 iso to the USB Flash (use only disk label, not partition label):
    1. dd if=CentOS-7-x86_64-Minimal-1708.iso of=/dev/sdb #NOT /dev/sdb1
  7. Install
  8. Set amount of space needed for VM's on both servers (i.e. you assume to have 100GB space for VM's on one server and 150GB on the other, sum=100+150=250) as raw device/partition, this will save you much time when setting up clustered storage


Thursday, December 7, 2017

Java Bubble sort

Example:
we have array of 5 numbers: [5,3,4,1,2]
To sort this array with Bubble sort we must compare each pair of adjacent items - if the order is wrong - swap them:
At step 3.2 our array will be sorted but algorithm doesn't know that so the algorithm will:
  1.  make external loop (array.length) times, one time for each index of the array,
  2.  and internal loop pairs_in_an_array times, one time for each adjacent pair  
  3. (let's count pairs in [5,3,4,1,2] :  
  4. 1) [5,3] ; 2) [3,4] ; 3) [4,1] ; 4) [1,2] - it's equal to (array.length - 1))
  1. loop 1:
    1. [5,3,4,1,2] -> [3,5,4,1,2]
    2. [3,5,4,1,2] -> [3,4,5,1,2]
    3. [3,4,5,1,2] -> [3,4,1,5,2]
    4. [3,4,1,5,2] -> [3,4,1,2,5]
  2. loop 2: 
    1. [3,4,1,2,5] -> [3,4,1,2,5]
    2. [3,4,1,2,5] -> [3,1,4,2,5]
    3. [3,1,4,2,5] -> [3,1,2,4,5]
    4. [3,1,2,4,5] -> [3,1,2,4,5]
  3. loop 3:
    1. [3,1,2,4,5] -> [1,3,2,4,5]
    2. [1,3,2,4,5] -> [1,2,3,4,5]
    3. [1,2,3,4,5] -> [1,2,3,4,5]
    4. [1,2,3,4,5] -> [1,2,3,4,5] 
  4. loop 4:
    1. [1,2,3,4,5] -> [1,2,3,4,5]
    2. [1,2,3,4,5] -> [1,2,3,4,5]
    3. [1,2,3,4,5] -> [1,2,3,4,5]
    4. [1,2,3,4,5] -> [1,2,3,4,5]
  5. loop 5: 
    1. [1,2,3,4,5] -> [1,2,3,4,5]
    2. [1,2,3,4,5] -> [1,2,3,4,5]
    3. [1,2,3,4,5] -> [1,2,3,4,5]
    4. [1,2,3,4,5] -> [1,2,3,4,5]
The algorithm called bubble sort because each high element goes to the top of the array as bubble goes to the top of the water reservoir.
Algorithm itself is too slow and impractical to be used in production environment. 

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

    {
    }

    public static void sort(int[] array) 

    {
        // extI - external loop iterator
        // intI - internal loop iterator
        for (int extI = 0; extI < array.length; extI++)

        {
            for (int intI = 0; intI < array.length-1; intI++)

            {
                if (array[intI + 1] < array[intI])

                {
                    int temp = array[intI + 1];
                    array[intI + 1] = array[intI];
                    array[intI] = temp;
                }
            }
        }
    }
}

Wednesday, December 6, 2017

Python string slicing (substringing) in Java 

we have a string "I don't want to learn programming, I want to earn money"

Python slicing:
>>> line[0:10]
"I don't wa"
>>> line[0:-1]
"I don't want to learn programming, I want to earn mone"
>>> line[2:]
"don't want to learn programming, I want to earn money"
>>> line[:]
"I don't want to learn programming, I want to earn money"
>>> line[10:-3]
'nt to learn programming, I want to earn mo'

Python slicing Java implementation:
public class Solution 
{
    public static void main(String[] args) 

    {
        String s = "I don't want to learn programming, I want to earn money";
        slicer(s, 0, 10);
        slicer(s, 0, -1);
        slicer(s, 2);
        slicer(s);
        slicer(s, 10, -3);
    }

    // using VarArgs to allow using no index, only one ore both
    // indexes without method overloading
    public static void slicer(String str, int... index) 

    {
            int startIndex;
            int endIndex;

            if (index.length > 1)

            {
                startIndex = index[0];
                endIndex = index[1];
            } else if (index.length == 1) 

            {
                startIndex = index[0];
                endIndex = str.length();
            } else 

            {
                startIndex = 0;
                endIndex = str.length();
            }

            if (endIndex < 0) 

            {
                endIndex = str.length() + endIndex;
            }

            char[] sentence = str.toCharArray();
            for (int n = startIndex; n < endIndex; n++) 

            {
                System.out.print(sentence[n]);
            }
            System.out.print("\n");
    }

}





Wednesday, November 29, 2017

Error Description: 13801: IKE authentication credentials are unacceptable

Tried to connect Windows 7 client to the pfSense® with IKEv2 and native Windows IPSec VPN client. Everything was setup using IKEv2_with_EAP-MSCHAPv2 and every-time trying to connect I got "Error Description: 13801: IKE authentication credentials are unacceptable". After searching and troubleshooting it turned out that importing CA cert to the Windows 7 client PC must be done only via mmc console otherwise certificate is shown as installed but nothing works as expected.
PS to install CA certificates use this link: Import_Root_Cert_mmc

Friday, November 24, 2017

MySQL OUTFILE & INFILE

To write dump into file (by default this file will go to the /var/lib/mysql/DBNAME/test.sql). I use NULL for id column's values because it's AUTOINCREMENT and will be generated automatically (otherwise if I dump actual value duplicate values will be created):
SELECT
 NULL,time,callid,queuename,agent,event,data1,data2,data3,data4,data5
INTO OUTFILE 'test.sql'
FIELDS TERMINATED BY ','
OPTIONALLY
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM
queue_log;

Files content is something like:
cat test.sql
\N,"2014-10-28 17:45:19.924148","NONE","NONE","NONE","QUEUESTART","","","","",""

To merge this file into an existent table:
LOAD DATA INFILE 'test.sql'
INTO TABLE queue_log
FIELDS TERMINATED BY ','
OPTIONALLY
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

Monday, November 20, 2017

Accessing CentOS 7 via RDP 

Install needed packages:
$ yum install epel-release
$ yum install xrdp tigervnc-server tigervnc-server-module

Change SELinux context for xrdp:
$ chcon -t bin_t /usr/sbin/xrdp
$ chcon -t bin_t /usr/sbin/xrdp-sesman

Open rdp port in firewall:
$ firewall-cmd --zone=public --add-port=3389/tcp --permanent
$ firewall-cmd --zone=public --add-port=3389/udp --permanent
$ firewall-cmd --reload

Enable and start xrdp service:
$ systemctl enable xrdp
$ systemctl start xrdp

Modify GNOME Display Manager custom:
$ vi /etc/gdm/custom.conf
[security]
AllowRemoteRoot=true
DisallowTCP=false
[xdmcp]
Enable=true

Wednesday, November 8, 2017

Can't remove final physical volume  from volume group (Linux)

I have:
[root@localhost ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  VolGroup   1   0   0 wz--n- 279.36g 279.36g
  centos     1   3   0 wz--n-  <3.64t   3.04t
[root@localhost ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree 
  /dev/sda3  centos   lvm2 a--   <3.64t   3.04t
  /dev/sdb1  VolGroup lvm2 a--  279.36g 279.36g
 and want to remove VolGroup and add /dev/sdb1 into centos VG:
[root@localhost ~]# pvremove /dev/sdb1
  PV /dev/sdb1 is used by VG VolGroup so please use vgreduce first.
  (If you are certain you need pvremove, then confirm by using --force twice.)
  /dev/sdb1: physical volume label not removed.
[root@localhost ~]# vgreduce VolGroup /dev/sdb1
  Can't remove final physical volume "/dev/sdb1" from volume group "VolGroup"

To overcome that issue we'll first inactivate "VolGroup" and then remove that VG:
[root@localhost ~]# vgchange -an VolGroup
  0 logical volume(s) in volume group "VolGroup" now active
[root@localhost ~]# vgremove VolGroup
  Volume group "VolGroup" successfully removed 

Verifying and adding PV to a VG:
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   3   0 wz--n- <3.64t 3.04t
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda3  centos lvm2 a--   <3.64t   3.04t
  /dev/sdb1         lvm2 ---  279.36g 279.36g
[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize VFree
  centos   2   3   0 wz--n- 3.91t 3.31t
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda3  centos lvm2 a--   <3.64t   3.04t
  /dev/sdb1  centos lvm2 a--  279.36g 279.36g