Wednesday, 8 November 2017

Network Introduction

What is a Network?

A network is simply defined as something that connects things together for a specific purpose. The term network is used in a variety of contexts, Including telephone, television, computer, or even people networks.

A computer network connects two or more devices/computers together to share a nearly limitless range of information and services, including:

• Documents
• Email and messaging
• Websites
• Databases
• Music

In below diagram Ok and An connected through a network



Now come to the Point Protocol:--

Protocols are rules that govern how devices communicate and share information across a network.
Examples of protocols include:

1. IP – Internet Protocol
2. HTTP - Hyper Text Transfer Protocol

Multiple protocols often work together to facilitate end-to-end network Communication. Protocols are covered in great detail later .

Basic Types of Network:--

Network types are often defined by function or size or no of connected workstations. The two most common categories of networks are:

• LANs (Local Area Networks)
• WANs (Wide Area Networks)

A LAN is generally a high-speed network that covers a small geographic area, usually contained within a single building or campus. A LAN is usually under the administrative control of a single organization. Ethernet is the most common LAN technology.

A WAN can be defined one of two ways. The book definition of a WAN is a network that spans large geographical locations, usually to connect multiple LANs.

A MAN (Metropolitan Area Network) is another category of network, though the term is not prevalently used. A MAN is defined as a network that connects LAN’s across a city-wide geographic area.

An internetwork is a general term describing multiple networks connected together. The Internet is the largest and most well-known internetwork.

Network Architectures

A host refers to any workstation that is connected to a network. A host can also  defined as any device assigned an IP address.

A host can use following functions:

• A host which request data, called as a client.
• A which provide data, called as a server.
• A host can both request and provide data, called as a peer.

Because of these functions, multiple network architectures have been developed, including:

1. Peer-to-Peer
2. Client/Server
3. Mainframe/Terminal

In a basic peer-to-peer architecture, all hosts on the network can both request and provide data and services. For example, two Windows 10 workstations configured to share files would be considered a peer-to-peer network.

Peer-to-peer networks are very simple to configure like static routes, yet this architecture presents several challenges. Data is difficult to manage and back-up, as it is spread across multiple orkstation. Security is equally problematic, as user accounts and permissions much be configured individually on each host.

Explanations No 1:--

In a client/server architecture, systems are assigned specific roles. Clients request data and services stored on servers. An example of a client/server network would be Windows 10 workstations accessing files off of a Windows 2007 server.

Advantage of the client/server:--

There are several advantages to the client/server architecture. Data and services are now centrally located on one or more servers, consolidating the security and management of that data. As a result, client/server networks can scale far larger than peer-to-peer networks.

Disadvantage of the client/server:--

One key disadvantage of the client/server architecture is that  server can present a single point of failure. This can be mitigated by adding redundancy at the server layer.

Monday, 6 November 2017

Hardware Addressing


Hardware Addressing



A hardware address is used to uniquely identify a host within a local network. Hardware addressing is a function of the Data-Link layer of the OSI model (Layer-2).

Ethernet utilizes the 48-bit MAC address as its hardware address. The MAC address is often hardcoded on physical network interfaces, though some interfaces support changing the MAC address using special utilities. In virtualization environments, dynamically assigning MAC addresses is very common.

A MAC address is most often represented in hexadecimal, using one of two accepted formats:

06:23:AD:F2:32:17

0643.ADF2.3217

The first six hexadecimal digits of a MAC address identify the manufacturer of the physical network interface. This is referred to as the OUI (Organizational Unique Identifier). The last six digits uniquely identify the host itself, and are referred to as the host ID.


The MAC address has one shortcoming – it contains no hierarchy. MAC addresses provide no mechanism to create boundaries between networks.
There is no method to distinguish one network from another.
This lack of hierarchy poses significant difficulties to network scalability. If only Layer-2 hardware addressing existed, all hosts would technically exist on the same network. Internetworks like the Internet could not exist, as it would be impossible to separate my network from your network.

Imagine if the entire Internet existed purely as a single Layer-2 switched network. Switches, as a rule, will forward a broadcast out every port. With billions of hosts on the Internet, the resulting broadcast storms would be devastating. The Internet would simply collapse.

The scalability limitations of Layer-2 hardware addresses are mitigated
using logical addresses, covered in great detail in this guide.


Logical Addressing

Logical addressing is a function of the Network layer of the OSI Model (Layer-3), and provides a hierarchical structure to separate networks. Logical addresses are never hardcoded on physical network interfaces, and can be dynamically assigned and changed freely. A logical address contains two components:
Network ID – identifies which network a host belongs to.
Host ID – uniquely identifies the host on that network.
Examples of logical addressing protocols include Internetwork Packet Exchange (IPX) and Internet Protocol (IP). IPX was predominantly used on Novell networks, but is now almost entirely deprecated. IP is the most widely-used logical address, and is the backbone protocol of the Internet.

Internet Protocol (IP)

In the 1970’s, the Department of Defense developed the Transmission Control Protocol (TCP), to provide both Network and Transport layer functions. When this proved to be an inflexible solution, those functions were separated - with the Internet Protocol (IP) providing Network layer services, and TCP providing Transport layer services. Together, TCP and IP provide the core functionality for the TCP/IP or Internet protocol suite.
IP provides two fundamental Network layer services:
Logical addressing – provides a unique address that identifies both the host, and the network that host exists on.
Routing – determines the best path to a particular destination network, and then routes data accordingly. IP was originally defined in RFC 760, and has been revised several times. IP Version 4 (IPv4) was the first version to experience widespread deployment, and is defined in RFC 791. IPv4 will be the focus of this guide. IPv4 employs a 32-bit address, which limits the number of possible addresses to 4,294,967,296. IPv4 will eventually be replaced by IP Version 6(IPv6), due to a shortage of available IPv4 addresses

IPv4 Addressing:--

A core function of IP is to provide logical addressing for hosts. An IP address provides a hierarchical structure to both uniquely identify a host, and what network that host exists on. An IP address is most often represented in decimal, in the following format:
158.80.164.3 An IP address is comprised of four octets, separated by periods: 

Each octet is an 8-bit number, resulting in a 32-bit IP address. The smallest possible value of an octet is 0, or 00000000 in binary. The largest possible value of an octet is 255, or 11111111 in binary.
The above IP address represented in binary would look as follows:

Decimal to Binary Conversion

The simplest method of converting between decimal and binary is to remember the following table:
128 64 32 16 8 4 2 1
To convert  decimal number of 172 to binary, start with the leftmost column. Since 172 is greater than 128, that binary bit will be set to 1. Next, add the value of the next column (128 + 64 = 192). Since 172 is less than 192, that binary bit will be set to 0.  Again, add the value of the next column (128 + 32 = 160). Since 172 is greater than 160, that binary bit will be set to 1. Continue this process until the columns with binary bits set to 1 add up to 192:--


Now what is  Subnet Mask:--

Part of an IP address identifies the network. The other part of the address identifies the host. A subnet mask is required to provide this distinction:
158.80.164.3 255.255.0.0
The above IP address has a subnet mask of 255.255.0.0. The subnet mask follows two rules:
If a binary bit is set to a 1 (or on) in a subnet mask, the corresponding bit in the address identifies the network.
If a binary bit is set to a 0 (or off) in a subnet mask, the corresponding bit in the address identifies the host.
Looking at the above address and subnet mask in binary:

The first 16 bits of the subnet mask are set to 1. Thus, the first 16 bits of the address (158.80) identify the network. The last 16 bits of the subnet mask are set to 0. Thus, the last 16 bits of the address (164.3) identify the unique host on that network.
The network portion of the subnet mask must be contiguous. For example, a subnet mask of 255.0.0.255 is not valid. Hosts on the same logical network will have identical network addresses, and can communicate freely. For example, the following two hosts are on the same network:
Host A: 158.80.164.100 255.255.0.0
Host B: 158.80.164.101 255.255.0.0
Both share the same network address (158.80), which is determined by the 255.255.0.0 subnet mask. Hosts that are on different networks cannot communicate without an intermediating device. For example:
Host A: 158.80.164.100 255.255.0.0
Host B: 158.85.164.101 255.255.0.0
The subnet mask has remained the same, but the network addresses are now different (158.80 and 158.85 respectively). Thus, the two hosts are not on the same network, and cannot communicate without a router between them.
Routing is the process of forwarding packets from one network to another. Consider the following, trickier example: 
Host A: 158.80.1.1 255.248.0.0
Host B: 158.79.1.1 255.248.0.0
The specified subnet mask is now 255.248.0.0, which doesn’t fall cleanly on an octet boundary. To determine if these hosts are on separate networks, first convert everything to binary: 
Host A Address:  10011110.01010000.00000001.00000001
Host B Address:  10011110.01001111.00000001.00000001
Subnet Mask:       11111111.11111000.00000000.00000000
Remember, the 1 (or on) bits in the subnet mask identify the network portion of the address. In this example, the first 13 bits (the 8 bits of the first octet, and the first 5 bits of the second octet) identify the network. Looking at only the first 13 bits of each address:
Host A Address: 10011110.01010
Host B Address: 10011110.01001
Clearly, the network addresses are not identical. Thus, these two hosts are on separate networks, and require a router to communicate.

Spanning Tree Protocol

Switching Loops


By default, a switch will forward a broadcast or multicast out all ports, excluding the port the broadcast/multicast was sent from.
When a loop is introduced into the network, a highly destructive broadcast storm can develop within seconds. Broadcast storms occur when road casts are endlessly switched through the loop, choking off all other traffic.

Consider the following looped environment:




In the above structure If the computer connected to Switch 4 sends out a broadcast, the switch will forward the broadcast out all ports, including the ports connecting to Switch 2 and Switch 5. Those switches, likewise, will forward that broadcast out all ports, including to their neighboring switches.

The broadcast will loop around the switches infinitely. In fact, there will be two separate broadcast storms cycling in opposite directions through the switching loop. Only powering off the switch or physically removing the loop will stop the storm.

So in this situation we will use Spanning Tree Protocol (STP)


Switches (and bridges) needed a mechanism to prevent loops from forming,and thus Spanning Tree Protocol (STP, or IEEE 802.1D) was developed. 
STP is enabled by default on all VLANs on Catalyst switches.
STP-enabled switches communicate to form a topology of the entire switching network, and then shutting down (or blocking) a port if a loop exists. The blocked port can be reactivated if another link on the switching network goes down, thus preserving fault-tolerance. Once all switches agree on the topology database, the switches are considered converged.
STP switches send Bridge Protocol Data Units  to each other to form their topology databases. BPDU’s are sent out all ports every two  seconds, are forwarded to a specific MAC multicast address: 0180.c202.0100

 STP Types

Various flavors of 802.1D STP exist, including:
Common Spanning Tree (CST) –A single STP process is used for all VLANs.
Per-VLAN Spanning Tree (PVST) – Cisco proprietary version of STP, which employs a separate STP process for each VLAN.
Per-VLAN Spanning Tree Plus (PVST+) – Enhanced version of PVST that allows CST-enabled switches and PVST-enabled switches to interoperate. This is default on newer Catalyst switches.

The STP Process

To maintain a loop-free environment, STP performs the following functions:
Ø  A Root Bridge is elected
Ø  Root Ports are identified
Ø  Designated Ports are identified
Ø  If a loop exists, a port is placed in Blocking state. If the loop is removed the blocked port is activated again.
If multiple loops exist in the switching environment, multiple ports will be placed in a blocking state.

Electing an STP Root Bridge

The first step in the STP process is electing a Root Bridge, which serves as the centralized point of the STP topology. Good design practice dictates that the Root Bridge be placed closest to the center of the STP topology.
The Root Bridge is determined by a switch’s priority. The default priority is 32,768, and the lowest priority wins. In case of a tie in priority, the switch with the lowest MAC address will be elected root bridge. The combination of a switch’s priority and MAC address make up that switch’s Bridge ID.
Consider the following example:


Remember that the lowest priority determines the Root Bridge. Switches 2,3, and 5 have the default priority set. Switches 1 and 4 each have a priority of 100 configured. However, Switch 1 will become the root bridge, as it has the lowest MAC address.

Switches exchange BPDU’s to perform the election process. By default, all switches “believe” they are the Root Bridge, until a switch with a lower Bridge ID is discovered.

Root Bridge elections are a continuous process. If a new switch with a lower Bridge ID is added to the topology, it will be elected as the new Root Bridge.


Switch# show spanning-tree interface Ge0/10

Interface Fa0/10 in Spanning tree 5 is Forwarding

Port path cost 150, Port priority 140

<snip>

Some useful and imp Basic STP Configuration

 

To disable STP for a specific VLAN:

Switch(config)# no spanning-tree vlan 10

To adjust the Bridge Priority of a switch from its default of 32,768, to

increase its chances of being elected Root Bridge of a VLAN:

Switch(config)# spanning-tree vlan 10 priority 150

To change an interface’s Path Cost from its defaults:

Switch(config)# int fa0/24

Switch(config-if)# spanning-tree cost 42

To force a switch to become the Root Bridge:

Switch(config)# spanning-tree vlan 10 root primary

The root primary parameter in the above command automatically lowers the

switch’s priority to 24,576. If another switch on the network has a lower

priority than 24,576, the above command will lower the priority by 4096 less

than the priority of the other switch.

It is possible to assign a Secondary Root Bridge for redundancy. To force a

switch to become a Secondary Root Bridge:



Switch(config)# spanning-tree vlan 10 root secondary

The root secondary parameter in the above command automatically lowers

the switch’s priority to 28,672.



To specify the diameter of the switching topology:

Switch(config)# spanning-tree vlan 10 root primary diameter 7

The diameter parameter in the preceding command indicates the length of

the STP topology (number of switches). The maximum (and default) value

for the diameter is 7. Note that the switching topology can contain more than

seven switches; however, each branch of the switching tree can only extend

seven switches deep, from the Root Bridge.

The diameter command will also adjust the Hello, Forward Delay, and Max

Age timers. This is the recommended way to adjust timers, as the hello

timers are tuned specifically to the diameter of the switching network.



Friday, 3 November 2017

method overloading in java example


Method Overloading in Java


If a class has multiple methods having same name but different in parameters, this is known as method overloading.

Method overloading increase the readability of the program. We can achieve method overloading either by changing the number of arguments or by changing the data type.

We will explain the method overloading by an example. This example achieve method overloading by changing the data type of argument.

Example 1:

package keywords;



public class Overloading {

       public int sum(int a, int b){

              return a+b;

       }

       public double sum(double a, double b){

              return a+b;

       }

       public static void main(String []p){

              Overloading obj=new Overloading();

              int c=obj.sum(10, 15);

              double k=obj.sum(15.5, 12.7);

              System.out.println("Sum of two integers is "+c);

              System.out.println("Sum of two double number is "+k);

             

       }



}



Output:

Sum of two integers is 25

Sum of two double number is 28.2



Code Explanation:


In this example we have two method in a class complete with same name but these two methods have different type of parameters. When we call the sum method compiler identify the method by the type of parameters passed during the calling of method. When we call sum method with integers parameters then sum method with integer parameter is called, When we call with double parameter then it call method with double parameter. This thing we can observe in the output clearly