Wednesday, April 10, 2013

IPsec interview questions

  • IPsec

Internet Protocol Security (IPsec) is a protocol suite for securing Internet Protocol (IP) communications by authenticating and encrypting each IP packet of a communication session
Some other Internet security systems in widespread use, such as Secure Sockets Layer (SSL), Transport Layer Security (TLS) and Secure Shell (SSH), operate in the upper layers of the TCP/IP model. In the past, the use of TLS/SSL had to be designed into an application to protect the application protocols. In contrast, since day one, applications did not need to be specifically designed to use IPsec. Hence, IPsec protects any application traffic across an IP network.
http://en.wikipedia.org/wiki/IPsec


  • 85) What do mean by tunnel mode?

This is a mode of data exchange wherein two communicating computers do not use IPSec themselves. Instead, the gateway that is connecting their LANs to the transit network creates a virtual tunnel that uses the IPSec protocol to secure all communication that passes through it.

IPsec consist of several protocols
ISAKMP
IKE
ESP - protocol 50
AH - protocol 51

IPsec Modes
Transport Mode
Tunnel Mode

Encryption Algols
DES
3DES
AES
RSA

Hashing Algols
MD5
SHA-1

IKE Phases

Data integrity - HMAC
Data Confidentiality - Encryption
Data Origin Authentication - SA peer
anti-replay - sequence numbers
HMAC
Diffie-Hellman
http://networkqna.com/ipsec/


  • Q1 – In which IPSEC Phase is the keys used for data encryption derived.

Q2 – In IPSEC, If ESP provides both encryption and authentication, why is AH required.
Q3 – Explain two methods by which two IPSEC routers can authenticate with each other.
Q4 – Which UDP ports should be open on a firewall to allow traffic from a L2TP/IPSEC based VPN clients to a PPTP VPN server on the inside
Q5 -Which IP protocol does AH and ESP headers use in IPSEC
Q6 – Which type of VPN would you use if data has to be encrypted at the network layer
Q7 – What is the use of configuring ACL in IPSEC configuration on a Cisco router
Q8 – If a packet sniffer is used on the VPN tunnel can the inner IP header be viewed
Q9 – Are the pre-shared keys used between the routers used for data encryption between systems at the different sites.
Q10 – How does the IPSEC protocols, ESP and AH provide replay protection
http://tcpipguru.com/ipsec-interview-questions/

  • IPSEC - The Internet Protocol Security is a set of protocols that provides security features to IP; like authentication, encryption and confidentiality.
L2TP -Layer Two Tunneling Protocol is a tunneling protocol (VPN) used to transport in L2 traffic over an IP Network ( Internet)
L2TP as follows from the name, is a layer 2 tunneling protocol. So, it can tunnel Layer 2 frames over IPSEC. 
https://learningnetwork.cisco.com/s/question/0D53i00000Kt2n1/ipsec-vs-l2tp-over-ipsec

PPTP or Point-to-Point Tunneling Protocol is an outdated method for implementing VPNs. It is developed by Microsoft and the easiest protocol to configure. PPTP VPN has low overhead and that makes it faster than other VPN protocols.

L2TP or Layer 2 Tunneling Protocol (L2TP) is the result of a partnership between Cisco and Microsoft.
It was created to provide a more secure VPN protocol than PPTP. L2TP is a tunneling protocol like PPTP that allows users to access the common network remotely.
https://www.purevpn.com/blog/difference-between-pptp-and-l2tp-protocols/

IEEE 802.1X is an IEEE Standard for port-based Network Access Control (PNAC). It is part of the IEEE 802.1 group of networking protocols. It provides an authentication mechanism to devices wishing to attach to a LAN or WLAN.
https://en.wikipedia.org/wiki/IEEE_802.1X


What is the difference between a PAL and a PLA?


PLA is programmable logic array while PAL is Programmable Array Logic.

PLA is a kind of programmable logic device used to implement combinational logic circuit.
It has Programmable AND Gate linked with Programmable OR Gate.

PAL is an combinational PLD that was developed to overcome certain disadvantage of PLA.
PLA shows longer delay due to additional fusible links which results from using two programmable array and increase circuit complexity.
Thus, PAL is used which is less complex and fast to implement. PAL consists of programmable AND linked with fixed OR.
http://wiki.answers.com/Q/What_is_the_difference_between_a_PAL_and_a_PLA

CMOS vs TTL


  • What are the Basic Differences Between CMOS and TTL Signals?



CMOS compared to TTL:

CMOS components are typically more expensive that TTL equivalents.
However, CMOS technology is usually less expensive on a system level due to CMOS chips being smaller and requiring less regulation.

CMOS circuits do not draw as much power as TTL circuits while at rest.
However, CMOS power consumption increases faster with higher clock speeds than TTL does.  Lower current draw requires less power supply distribution, therefore causing a simpler and cheaper design.

Due to longer rise and fall times, the transmission of digital signals become simpler and less expensive with CMOS chips.

CMOS components are more susceptible to damage from electrostatic discharge than TTL compenents.

http://digital.ni.com/public.nsf/allkb/2D038D3AE1C35011862565A8005C5C63

microprocessors




  • DRAM

Dynamic random-access memory (DRAM) is a type of random-access memory that stores each bit of data in a separate capacitor within an integrated circuit.
http://en.wikipedia.org/wiki/DRAM



  • SDRAM

Synchronous dynamic random access memory (SDRAM) is dynamic random access memory (DRAM) that is synchronized with the system bus. Classic DRAM has an asynchronous interface, which means that it responds as quickly as possible to changes in control inputs.
SDRAM has a synchronous interface, meaning that it waits for a clock signal before responding to control inputs and is therefore synchronized with the computer's system bus
http://en.wikipedia.org/wiki/SDRAM



  • SRAM

Static random-access memory (SRAM) is a type of semiconductor memory that uses bistable latching circuitry to store each bit.
The term static differentiates it from dynamic RAM (DRAM) which must be periodically refreshed.
SRAM exhibits data remanence, but it is still volatile in the conventional sense that data is eventually lost when the memory is not powered.



  • Data remanence
Data remanence is the residual representation of data that remains even after attempts have been made to remove or erase the data. This residue may result from data being left intact by a nominal file deletion operation, by reformatting of storage media that does not remove data previously written to the media, or through physical properties of the storage medium that allow previously written data to be recovered
http://en.wikipedia.org/wiki/Data_remanence



  • Transistor–transistor logic

Transistor–transistor logic (TTL) is a class of digital circuits built from bipolar junction transistors (BJT) and resistors. It is called transistor–transistor logic because both the logic gating function (e.g., AND) and the amplifying function are performed by transistors
http://en.wikipedia.org/wiki/Transistor-transistor_logic

IP address classes

  • An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication.[1][2] An IP address serves two principal functions: host or network interface identification and location addressing.

    IP networks may be divided into subnetworks in both IPv4 and IPv6. For this purpose, an IP address is recognized as consisting of two parts: the network prefix in the high-order bits and the remaining bits called the rest field, host identifier, or interface identifier (IPv6), used for host numbering within a network.The subnet mask or CIDR notation determines how the IP address is divided into network and host parts.
      The term subnet mask is only used within IPv4. Both IP versions however use the CIDR concept and notation. In this, the IP address is followed by a slash and the number (in decimal) of bits used for the network part, also called the routing prefix. For example, an IPv4 address and its subnet mask may be 192.0.2.1 and 255.255.255.0, respectively. The CIDR notation for the same IP address and subnet is 192.0.2.1/24, because the first 24 bits of the IP address indicate the network and subnet.

          Private addresses
            Early network design, when global end-to-end connectivity was envisioned for communications with all Internet hosts, intended that IP addresses be globally unique. However, it was found that this was not always necessary as private networks developed and public address space needed to be conserved.
              Computers not connected to the Internet, such as factory machines that communicate only with each other via TCP/IP, need not have globally unique IP addresses. Today, such private networks are widely used and typically connect to the Internet with network address translation (NAT), when needed.
                Three non-overlapping ranges of IPv4 addresses for private networks are reserved.These addresses are not routed on the Internet and thus their use need not be coordinated with an IP address registry. Any user may use any of the reserved blocks. Typically, a network administrator will divide a block into subnets; for example, many home routers automatically use a default address range of 192.168.0.0 through 192.168.0.255 (192.168.0.0/24).

                    IPv6 addresses
                      In IPv6, the address size was increased from 32 bits in IPv4 to 128 bits, thus providing up to 2128 (approximately 3.403×1038) addresses
                        Private addresses
                          Just as IPv4 reserves addresses for private networks, blocks of addresses are set aside in IPv6. In IPv6, these are referred to as unique local addresses (ULAs).


                                IP address assignment
                                  Dynamic IP addresses are assigned using methods such as Zeroconf for self-configuration, or by the Dynamic Host Configuration Protocol (DHCP) from a network server. The address assigned with DHCP usually has an expiration period, after which the address may be assigned to another device, or to the originally associated host if it is still powered up. A network administrator may implement a DHCP method so that the same host always receives a specific address.

                                      Sticky dynamic IP address
                                        A sticky dynamic IP address is an informal term used by cable and DSL Internet access subscribers to describe a dynamically assigned IP address which seldom changes.
                                          The addresses are usually assigned with DHCP. If a modem is turned off and powered up again before the next expiration of the address lease, it often receives the same IP address.

                                              Routing
                                                Unicast addressing
                                                  The most common concept of an IP address is in unicast addressing, available in both IPv4 and IPv6. It normally refers to a single sender or a single receiver, and can be used for both sending and receiving.
                                                    Broadcast addressing
                                                      Broadcasting is an addressing technique available in IPv4 to send data to all possible destinations on a network in one transmission operation, while all receivers capture the network packet (all-hosts broadcast). The address 255.255.255.255 is used for network broadcast.IPv6 does not implement broadcast addressing, and replaces it with multicast to the specially-defined all-nodes multicast address
                                                        Multicast addressing
                                                          A multicast address is associated with a group of interested receivers. In IPv4, addresses 224.0.0.0 through 239.255.255.255 (the former Class D addresses) are designated as multicast addresses
                                                            IPv6 uses the address block with the prefix ff00::/8 for multicast applications. In either case, the sender sends a single datagram from its unicast address to the multicast group address and the intermediary routers take care of making copies and sending them to all receivers that have joined the corresponding multicast group.

                                                                Anycast addressing
                                                                  Like broadcast and multicast, anycast is a one-to-many routing topology.
                                                                    Anycast address is an inherent feature of only IPv6. In IPv4, anycast addressing implementations typically operate using the shortest-path metric of BGP routing and do not take into account congestion or other attributes of the path

                                                                        Public address
                                                                          A public IP address is a globally routable unicast IP address,
                                                                            Public IP addresses may be used for communication between hosts on the global Internet.

                                                                                Firewalling
                                                                                  For security and privacy considerations, network administrators often desire to restrict public Internet traffic within their private networks. The source and destination IP addresses contained in the headers of each IP packet are a convenient means to discriminate traffic by IP address blocking or by selectively tailoring responses to external requests to internal servers. This is achieved with firewall software running on the networks gateway router. A database of IP addresses of permissible traffic may be maintained in blacklists or whitelists.

                                                                                      Address translation
                                                                                        Multiple client devices can appear to share an IP address, either because they are part of a shared hosting web server environment or because an IPv4 network address translator (NAT) or proxy server acts as an intermediary agent on behalf of the client, in which case the real originating IP address might be masked from the server receiving a request.
                                                                                          A common practice is to have a NAT mask a large number of devices in a private network. Only the "outside" interface(s) of the NAT needs to have an Internet-routable address.
                                                                                            Commonly, the NAT device maps TCP or UDP port numbers on the side of the larger, public network to individual private addresses on the masqueraded network.
                                                                                              In residential networks, NAT functions are usually implemented in a residential gateway. In this scenario, the computers connected to the router have private IP addresses and the router has a public address on its external interface to communicate on the Internet. The internal computers appear to share one public IP address.
                                                                                                http://en.wikipedia.org/wiki/IP_address
                                                                                                IP address classes


                                                                                                Note: Class A addresses 127.0.0.0 to 127.255.255.255 cannot be used and is reserved for loopback and diagnostic functions.

                                                                                                A 1 – 126*
                                                                                                B 128 – 191
                                                                                                C 192 – 223
                                                                                                D 224 – 239
                                                                                                E 240 – 254

                                                                                                http://www.vlsm-calc.net/ipclasses.php


                                                                                                • A private IP address is an IP address that's reserved for internal use behind a router or other Network Address Translation (NAT) device, apart from the public.


                                                                                                Private IP addresses are in contrast to public IP addresses, which are public and can not be used within a home or business network

                                                                                                Sometimes a private IP address is also referred to as a local IP address.

                                                                                                Which IP Addresses Are Private?
                                                                                                The Internet Assigned Numbers Authority (IANA) reserves the following IP address blocks for use as private IP addresses:

                                                                                                10.0.0.0 to 10.255.255.255 The first set of IP addresses from above allow for over 16 million addresses
                                                                                                172.16.0.0 to 172.31.255.255 The second for over 1 million
                                                                                                192.168.0.0 to 192.168.255.255 over 65,000 for the last range.



                                                                                                Why Private IP Addresses Are Used
                                                                                                Instead of having devices inside a home or business network each use a public IP address, of which there's a limited supply, private IP addresses provide an entirely separate set of addresses that still allow access on a network but without taking up a public IP address space.

                                                                                                For example, let's consider a standard router on a home network. Most routers in homes and businesses across the globe, probably yours and your next door neighbor's, all have the IP address of 192.168.1.1, and assign 192.168.1.2, 192.168.1.3, ... to the various devices that connect to it (via something called DHCP).

                                                                                                It doesn't matter how many routers use the 192.168.1.1 address, or how many dozens or hundreds of devices inside that network share IP addresses with users of other networks because they aren't communicating with each other directly.

                                                                                                Instead, the devices in a network use the router to translate their requests through the public IP address, which can communicate with other public IP addresses and eventually to other local networks.

                                                                                                For example, before landing on this page, your device (be it a computer, phone, or whatever), which uses a private IP address, requested this page through a router, which has a public IP address. Once the request was made and Livewire responded to deliver the page, it was downloaded to your device through a public IP address before reaching your router, after which it got handed off to your private/local address to reach your device

                                                                                                Reserved IP Addresses
                                                                                                Another set of IP addresses that are restricted even further are called reserved IP addresses. These are similar to private IP addresses in the sense that they can't be used for communicating on the greater internet, but they're even more restrictive than that.
                                                                                                The most famous reserved IP is 127.0.0.1. This address is called the loopback address and is used to test the network adapter or integrated chip.
                                                                                                No traffic addressed to 127.0.0.1 is sent over the local network or public internet.

                                                                                                Technically, the entire range from 127.0.0.0 to 127.255.255.255 is reserved for loopback purposes but you'll almost never see anything but 127.0.0.1 used in the real world.
                                                                                                Addresses in the range from 0.0.0.0 to 0.255.255.255 are also reserved but don't do anything at all. If you're even able to assign a device an IP address in this range, it will not function properly no matter where on the network it's installed


                                                                                                https://www.lifewire.com/what-is-a-private-ip-address-2625970

                                                                                                • Note: Class A addresses 127.0.0.0 to 127.255.255.255 cannot be used and is reserved for loopback and diagnostic functions.

                                                                                                Private IP Addresses
                                                                                                http://www.vlsm-calc.net/ipclasses.php



                                                                                                • Private IP Addresses

                                                                                                Most organizations have far more computers than available IP addresses. Using private IP addresses helps to tackle this issue by allowing companies to have a single Internet gateway with a public IP address. All of the other nodes have private IP addresses. The gateway uses a Network Address Translation (NAT) server to translate the private IP addresses to an address that can be routed across the Internet.
                                                                                                https://www.sqa.org.uk/e-learning/WebTech01CD/page_12.htm



                                                                                                • The most common use of private addresses is in residential IPv4 networks since most Internet service providers (ISPs) allocate only a single publicly routable IPv4 address to each residential customer, but many homes have more than one computer or another Internet-connected device, such as smartphones. In this situation, a network address translator (NAT/PAT) gateway is usually used to provide Internet connectivity to multiple hosts.


                                                                                                Private addresses are also commonly used in corporate networks, which for security reasons, are not connected directly to the Internet. Often a proxy, SOCKS gateway, or similar devices are used to provide restricted Internet access to network-internal users.

                                                                                                In both cases, private addresses are often seen as enhancing network security for the internal network, since it is difficult for the Internet (external) host to connect directly to an internal system.
                                                                                                https://en.wikipedia.org/wiki/Private_network



                                                                                                • Automatic Private IP Addressing (APIPA) is a DHCP fail-safe that protects a computer system from failure by invoking a standby mechanism for local Internet Protocol version 4 (IPv4) networks supported by Microsoft Windows. With APIPA, DHCP clients can obtain IP addresses even when DHCP servers are not functional. APIPA exists in all modern versions of Windows, including Windows 10.

                                                                                                How APIPA Works
                                                                                                Networks that are set up for dynamic addressing rely on a DHCP server to manage the pool of available local IP addresses. When a Windows client device attempts to join the local network, it contacts the DHCP server to request its IP address. If the DHCP server stops functioning, a network glitch interferes with the request, or some issue occurs on the Windows device, this process can fail.
                                                                                                When the DHCP process fails, Windows automatically assigns an IP address from the private range, which is 169.254.0.1 to 169.254.255.254. Using Address Resolution Protocol (ARP), clients verify that the chosen APIPA address is unique on the network before they use it. Clients then check back with the DHCP server at periodic intervals—usually every five minutes—and update their addresses automatically when the DHCP server is able to service requests.
                                                                                                All APIPA devices use the default network mask 255.255.0.0, and all reside on the same subnet.
                                                                                                Limitations of APIPA
                                                                                                APIPA addresses do not fall into any of the private IP address ranges defined by the Internet Protocol standard and are restricted for use on local networks only. Like private IP addresses, ping tests or any other connection requests from the internet and other outside networks cannot be made to APIPA devices directly.
                                                                                                APIPA-configured devices can communicate with peer devices on their local network but cannot communicate outside of it. While APIPA provides Windows clients a usable IP address, it does not provide the client with nameserver (DNS or WINS) and network gateway addresses as DHCP does.
                                                                                                Local networks should not attempt to manually assign addresses in the APIPA range because IP address conflicts will result. To maintain the benefit APIPA has of indicating DHCP failures, administrators should avoid using those addresses for any other purpose and instead limit their networks to use the standard IP address ranges.
                                                                                                https://www.lifewire.com/automatic-private-internet-protocol-addressing-816437


                                                                                                • If no DHCP server is currently available (either because the server is temporarily down or because none exists on the network), the computer selects an IP address from a range of addresses (from 169.254.0.0 - 169.254.255.255) reserved by the Internet Assigned Numbers Authority (IANA) for that purpose. The client uses the Address Resolution Protocol (ARP) to ensure that the chosen address is not already being used by another network computer. Once the computer has assigned itself an IP address, it can communicate over TCP/IP with other computers on the LAN that are either configured for APIPA or are manually set to the correct address range and a subnet mask value of 255.255.0.0. APIPA is enabled by default but can be disabled in some cases. DHCP messages notify the user when they are switched between DHCP addressing and APIPA.

                                                                                                https://whatis.techtarget.com/definition/Automatic-Private-IP-Addressing-APIPA
                                                                                                • IP Loopback Address

                                                                                                127.0.0.1 is the loopback address in IP. Loopback is a test mechanism of network adapters. Messages sent to 127.0.0.1 do not get delivered to the network. Instead, the adapter intercepts all loopback messages and returns them to the sending application. IP applications often use this feature to test the behavior of their network interface.

                                                                                                IPv6 uses 0:0:0:0:0:0:0:1 as its loopback address, equivalent to 127.0.0.1 in IPv4
                                                                                                http://compnetworking.about.com/od/workingwithipaddresses/l/aa042400c.htm


                                                                                                • Identifying the Problem Source

                                                                                                A logical approach is helpful when troubleshooting any problem. Some common questions to ask during troubleshooting include the following:

                                                                                                What works?

                                                                                                What does not work?

                                                                                                How are the things that do and do not work related?

                                                                                                Have the things that do not work ever worked?

                                                                                                If so, what has changed since it last worked?

                                                                                                Table 16-1 Tools and Services for Troubleshooting TCP/IP
                                                                                                Arp
                                                                                                Allows viewing and editing of the Address Resolution Protocol (ARP) cache.
                                                                                                Hostname

                                                                                                Displays the host name of the computer.

                                                                                                Ipconfig

                                                                                                Displays the current TCP/IP configuration for both IPv4 and IPv6. Also used to manage Dynamic Host Configuration Protocol (DHCP)-allocated IPv4 address configurations, display or flush the DNS client resolver cache, and register DNS names.

                                                                                                Nbtstat

                                                                                                Displays NetBIOS over TCP/IP (NetBT) configuration and allows management of the NetBIOS name cache.

                                                                                                Netsh

                                                                                                Configuration tool for many network services. For each network service, there is a context containing commands specific for that service. For the netsh interface ip and netsh interface ipv6 contexts, displays and administers TCP/IP protocol settings on either the local computer or a remote computer.

                                                                                                Netstat

                                                                                                Displays protocol statistics and information on current TCP connections.

                                                                                                Nslookup

                                                                                                Performs DNS queries and displays the results.

                                                                                                Ping

                                                                                                Sends Internet Control Message Protocol (ICMP) Echo or Internet Control Message Protocol for IPv6 (ICMPv6) Echo Request messages to test reachability.

                                                                                                Route

                                                                                                Allows viewing of the IPv4 and IPv6 routing tables and editing of the IPv4 routing table.

                                                                                                Tracert

                                                                                                Sends ICMP Echo or ICMPv6 Echo Request messages to trace the network route taken by IPv4 or IPv6 packets to a specific destination.

                                                                                                Pathping

                                                                                                Sends ICMP Echo or ICMPv6 Echo Request messages to trace the route an IPv4 or IPv6 packet takes to a destination and displays information on packet losses for each router and link in the path.

                                                                                                SNMP service

                                                                                                Provides status and statistical information to Simple Network Management System (SNMP) management systems.

                                                                                                Event Viewer

                                                                                                Records errors and events.

                                                                                                Performance Logs and Alerts

                                                                                                Logs TCP/IP core protocol performance and sends alerts (the SNMP service must be installed).

                                                                                                Network Monitor

                                                                                                Captures and displays the contents of TCP/IP packets sent to and from computers running Windows Server 2003.

                                                                                                Netdiag

                                                                                                Runs a series of diagnostics test on networking components. Netdiag is installed as part of the Windows XP and Windows Server 2003 Support Tools in the Support\Tools folder of the Windows XP or Windows Server 2003 product CD-ROM.

                                                                                                Telnet

                                                                                                Tests TCP connection establishment between two nodes.

                                                                                                Ttcp

                                                                                                Listens for and sends TCP segment data or UDP messages between two nodes.Ttcp.exe is provided with Windows XP Service Pack 2 in the Valueadd\Msft\Net\Tools folder of the Windows XP Service Pack 2 CD-ROM.



                                                                                                Troubleshooting IPv4
                                                                                                The following sections describe the tools and techniques used to identify a problem at successive layers of the TCP/IP protocol stack that is using an IPv4 Internet layer. Depending on the type of problem, you might do one of the following:

                                                                                                Start at the bottom of the stack and move up.

                                                                                                Start at the top of the stack and move down.

                                                                                                The following sections are organized from the top of the stack and describe how to:

                                                                                                Verify IPv4 connectivity.

                                                                                                Verify DNS name resolution for IPv4 addresses.

                                                                                                Verify NetBIOS name resolution.

                                                                                                Verify IPv4-based TCP sessions.


                                                                                                Repair the Connection
                                                                                                The tasks that are performed by Network Connection Repair are the following:
                                                                                                Checks whether DHCP is enabled and, if enabled, sends a broadcast DHCPRequest message to refresh the IPv4 address configuration.
                                                                                                Flushes the ARP cache. This is equivalent to the arp -d * command.
                                                                                                Flushes and reloads the DNS client resolver cache with entries from the Hosts file. This is equivalent to the ipconfig /flushdns command.
                                                                                                Re-registers DNS names using DNS dynamic update. This is equivalent to the ipconfig /registerdns command.
                                                                                                Flushes and reloads the NetBIOS name cache with #PRE entries in the Lmhosts file. This is equivalent to the nbtstat -R command.
                                                                                                Releases and then re-registers NetBIOS names with the Windows Internet Name Service (WINS). This is equivalent to the nbtstat -RR command.

                                                                                                Chapter Summary
                                                                                                The chapter includes the following pieces of key information:

                                                                                                To try and isolate the components that might be at fault when approaching a troubleshooting issue, you should determine what works, what does not work, whether it has ever worked, and what has changed since it last worked.

                                                                                                Windows provides the following tools for troubleshooting TCP/IP problems: Arp, Hostname, Ipconfig, Nbtstat, Netsh, Netstat, Nslookup, Ping, Route, Tracert, Pathping, SNMP service, Event Viewer, Performance Logs and Alerts, Network Monitor, and Netdiag.

                                                                                                Troubleshoot IPv4 communications by verifying IPv4 connectivity, verifying DNS name resolution for IPv4 addresses, verifying NetBIOS name resolution, and verifying IPv4-based TCP sessions.

                                                                                                Troubleshoot IPv6 communications by verifying IPv6 connectivity, verifying DNS name resolution for IPv6 addresses, and verifying IPv6-based TCP sessions.


                                                                                                https://docs.microsoft.com/en-us/previous-versions/tn-archive/bb727023(v=technet.10)


                                                                                                • What Is Straight Through Cable?

                                                                                                A straight through cable is a type of twisted pair cable that is used in local area networks to connect a computer to a network hub such as a router. This type of cable is also sometimes called a patch cable and is an alternative to wireless connections where one or more computers access a router through a wireless signal. On a straight through cable, the wired pins match. Straight through cable use one wiring standard: both ends use T568A wiring standard or both ends use T568B wiring standard.

                                                                                                What Is Crossover Cable?
                                                                                                An Ethernet crossover cable is a type of Ethernet cable used to connect computing devices together directly. Unlike straight through cable, crossover cables use two different wiring standards: one end uses the T568A wiring standard, and the other end uses the T568B wiring standard. The internal wiring of Ethernet crossover cables reverses the transmit and receive signals.

                                                                                                It is most often used to connect two devices of the same type: e.g. two computers (via network interface controller) or two switches to each other.
                                                                                                http://www.cables-solutions.com/difference-between-straight-through-and-crossover-cable.html



                                                                                                • Netstat: network analysis and troubleshooting, explained

                                                                                                    In lines saying 'ESTABLISHED', you need the remote port to identify what has connected to the remote site.
                                                                                                    In lines saying 'LISTENING', you need the local port to identify what is listening there.
                                                                                                    Each outbound TCP connection also causes a LISTENING entry on the same port.
                                                                                                    Most UDP listening ports are duplicates from a listening TCP port. Ignore them unless they don't have a TCP twin.
                                                                                                    TIME_WAIT entries are not important.
                                                                                                    If it says 0.0.0.0 on the Local Address column, it means that port is listening on all 'network interfaces' (i.e. your computer, your modem(s) and your network card(s)).
                                                                                                    If it says 127.0.0.1 on the Local Address column, it means that port is ONLY listening for connections from your PC itself, not from the Internet or network. No danger there.
                                                                                                    If it displays your online IP on the Local Address column, it means that port is ONLY listening for connections from the Internet.
                                                                                                    If it displays your local network IP on the Local Address column, it means that port is ONLY listening for connections from the local network.
                                                                                                https://sites.google.com/site/xiangyangsite/home/technical-tips/linux-unix/networks-related-commands-on-linux/how-to-read-netstat--an-results


                                                                                                • A bundle of network tools

                                                                                                The netstat command doesn’t really do unique things. It can print network statistics, but ifconfig can do so, too. It can print routing tables, but route can do that, too. It can print open connections, but lsof does that, and more. So why use netstat at all? There are two main reasons:

                                                                                                    netstat bundles a few often-used network analysis actions in a single command and
                                                                                                    netstat is multi-platform
                                                                                                https://linuxacademy.com/blog/linux/netstat-network-analysis-and-troubleshooting-explained/   

                                                                                                the following IPv4 address ranges are reserved by the IANA for private internets, and are not publicly routable on the global internet:


                                                                                                    10.0.0.0/8 IP addresses: 10.0.0.0 – 10.255.255.255
                                                                                                    172.16.0.0/12 IP addresses: 172.16.0.0 – 172.31.255.255
                                                                                                    192.168.0.0/16 IP addresses: 192.168.0.0 – 192.168.255.255


                                                                                                Note that only a portion of the “172” and the “192” address ranges are designated for private use. The remaining addresses are considered “public,” and thus are routable on the global Internet.

                                                                                                https://www.arin.net/reference/research/statistics/address_filters/ 

                                                                                                • Private network

                                                                                                In IP networking, a private network is a computer network that uses private IP address space. Both the IPv4 and the IPv6 specifications define private IP address ranges.[1][2] These addresses are commonly used for local area networks (LANs) in residential, office, and enterprise environments. 

                                                                                                Private network addresses are not allocated to any specific organization. Anyone may use these addresses without approval from regional or local Internet registries. Private IP address spaces were originally defined to assist in delaying IPv4 address exhaustion. IP packets originating from or addressed to a private IP address cannot be routed through the public Internet. 

                                                                                                24-bit block 10.0.0.0 – 10.255.255.255 16777216 10.0.0.0/8 (255.0.0.0) 24 bits 8 bits single class A network
                                                                                                20-bit block 172.16.0.0 – 172.31.255.255 1048576 172.16.0.0/12 (255.240.0.0) 20 bits 12 bits 16 contiguous class B networks
                                                                                                16-bit block 192.168.0.0 – 192.168.255.255 65536 192.168.0.0/16 (255.255.0.0) 16 bits 16 bits 256 contiguous class C networks 

                                                                                                Private IPv6 addresses
                                                                                                The concept of private networks has been extended in the next generation of the Internet Protocol, IPv6, and special address blocks are reserved. 
                                                                                                The address block fc00::/7 is reserved by IANA for Unique Local Addresses (ULA)

                                                                                                https://en.wikipedia.org/wiki/Private_network

                                                                                                • 0.0.0.0
                                                                                                In the Internet Protocol Version 4, the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non-applicable target.

                                                                                                As a host address

                                                                                                A way to specify "any IPv4 address at all". It is used in this way when configuring servers (i.e. when binding listening sockets). This is known to TCP programmers as INADDR_ANY.
                                                                                                The address a host claims as its own when it has not yet been assigned an address. Such as when sending the initial DHCPDISCOVER packet when using DHCP.
                                                                                                The address a host assigns to itself when address request via DHCP has failed, provided the host's IP stack supports this. This usage has been replaced with the APIPA mechanism in modern operating systems.
                                                                                                A way to explicitly specify that the target is unavailable
                                                                                                A way to route request to a nonexistent target instead of the original target. Often used for adblocking purposes.

                                                                                                In the context of servers, 0.0.0.0 can mean "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses. 

                                                                                                Routing

                                                                                                In the context of routing tables, a network destination of 0.0.0.0 is used with a network mask of 0 to depict the default route as a destination subnet. This destination is expressed as "0.0.0.0/0" in CIDR notation. It matches all addresses in the IPv4 address space and is present on most hosts, directed towards a local router.

                                                                                                In routing tables, 0.0.0.0 can also appear in the gateway column. This indicates that the gateway to reach the corresponding destination subnet is unspecified. This generally means that no intermediate routing hops are necessary because the system is directly connected to the destination

                                                                                                In IPv6
                                                                                                In IPv6, the all-zeros address is typically represented by ::, which is the short notation of 0000:0000:0000:0000:0000:0000:0000:0000
                                                                                                The IPv6 variant serves the same purpose as its IPv4 counterpart. 

                                                                                                https://en.wikipedia.org/wiki/0.0.0.0

                                                                                                • IANA IPv4 Special-Purpose Address Registry

                                                                                                • Private-Use
                                                                                                Documentation (TEST-NET-1)
                                                                                                Documentation (TEST-NET-2)
                                                                                                Documentation (TEST-NET-3)
                                                                                                http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml

                                                                                                • Reserved IP addresses
                                                                                                Assigned as TEST-NET-1, documentation and examples.
                                                                                                Assigned as TEST-NET-2, documentation and examples
                                                                                                Assigned as TEST-NET-3, documentation and examples
                                                                                                https://en.wikipedia.org/wiki/Reserved_IP_addresses














                                                                                                • a link-local address is a network address that is valid only for communications within the network segment or the broadcast domain that the host is connected to.
                                                                                                Link-local addresses are most often assigned automatically with a process known as stateless address autoconfiguration or link-local address autoconfiguration
                                                                                                also known as automatic private IP addressing (APIPA) or auto-IP. 
                                                                                                Link-local addresses are not guaranteed to be unique beyond their network segment. Therefore, routers do not forward packets with link-local source or destination addresses. 
                                                                                                IPv4 link-local addresses are assigned from address block 169.254.0.0/16 (169.254.0.0 through 169.254.255.255). IPv6, they are assigned from the block fe80::/10
                                                                                                https://en.wikipedia.org/wiki/Link-local_address

                                                                                                Network 169.254.0.0/16 is a "reserved network" named IPv4 Link-Local Addresses
                                                                                                IPv4 Link-Local addresses are not suitable for communication with
                                                                                                devices not directly connected to the same physical (or logical)
                                                                                                link, and are only used where stable, routable addresses are not
                                                                                                available (such as on ad hoc or isolated networks)
                                                                                                https://access.redhat.com/solutions/4403501

                                                                                                Link local addresses allow machines to automatically have an IP address on a network if they haven't been manually configured or automatically configured by a special server on the network (DHCP).
                                                                                                 Before an address is chosen from that range, the machine sends out a special message (using ARP which stands for address resolution protocol) to the machines on the network around it (assuming that they also haven't been assigned an address manually or automatically) to find out if 169.254.1.1 is free. If it is, then the machine assigns that address to its network card. If that address is already in use by another machine on the same network, then it tries the next IP 169.254.1.2 and so on, until it finds a free address

                                                                                                IP addresses, either IPv4 or IPv6. It is valid in some circumstances to refer to a MAC address as a link-local address but it is a less common use of the term. 

                                                                                                the range for IPv4 is 169.254.0.0/16 (169.254.0.1 to 169.254.255.254), with 169.254.0.0 and 169.254.255.255 reserved as network/broadcast addresses

                                                                                                IPv6 has fe80::/10 reserved for Link-Local addresses with most automatically assigned ones being in the fe80::/64 range. 
                                                                                                The link-local IP address must be unique within its network segment

                                                                                                The process a device assigning an address to itself is a common use for Link-local IP addresses but it is not the only way they are used. In stateless address autoconfiguration the device should check that an address it wants to try and use is available and then use it. There is nothing to stop you manually assigning the same link-local IP address to two devices you administe

                                                                                                https://serverfault.com/questions/118324/what-is-a-link-local-address



                                                                                                Monday, April 8, 2013

                                                                                                java network

                                                                                                • jNetPcap is an open-source java library. It contains
                                                                                                    A Java wrapper for nearly all libpcap library native calls
                                                                                                    Decodes captured packets in real-time
                                                                                                    Provides a large library of network protocols (core protocols)
                                                                                                    Users can easily add their own protocol definitions using java SDK
                                                                                                    jNetPcap uses a mixture of native and java implementation for optimum packet decoding performance
                                                                                                http://jnetpcap.com/



                                                                                                • jpcap 

                                                                                                The jpcap network capture tool performs real-time decomposition and visualization of network traffic.
                                                                                                Screenshots of the capture console and visualization component in action
                                                                                                http://jpcap.sourceforge.net/

                                                                                                Friday, March 29, 2013

                                                                                                How to Convert from Decimal to Binary



                                                                                                • How to Convert from Decimal to Binary


                                                                                                The decimal (base ten) numeral system has ten possible values (0,1,2,3,4,5,6,7,8, or 9) for each place-value. In contrast, the binary (base two) numeral system has two possible values, often represented as 0 or 1, for each place-value.

                                                                                                http://www.wikihow.com/Convert-from-Decimal-to-Binary



                                                                                                • Converting Decimal Fractions to Binary


                                                                                                In fact, there is a simple, step-by-step method for computing the binary expansion on the right-hand side of the point. We will illustrate the method by converting the decimal value .625 to a binary representation..

                                                                                                Step 1: Begin with the decimal fraction and multiply by 2. The whole number part of the result is the first binary digit to the right of the point.

                                                                                                Because .625 x 2 = 1.25, the first binary digit to the right of the point is a 1.
                                                                                                So far, we have .625 = .1??? . . . (base 2) .

                                                                                                Step 2: Next we disregard the whole number part of the previous result (the 1 in this case) and multiply by 2 once again. The whole number part of this new result is the second binary digit to the right of the point. We will continue this process until we get a zero as our decimal part or until we recognize an infinite repeating pattern.

                                                                                                Because .25 x 2 = 0.50, the second binary digit to the right of the point is a 0.
                                                                                                So far, we have .625 = .10?? . . . (base 2) .

                                                                                                Step 3: Disregarding the whole number part of the previous result (this result was .50 so there actually is no whole number part to disregard in this case), we multiply by 2 once again. The whole number part of the result is now the next binary digit to the right of the point.

                                                                                                Because .50 x 2 = 1.00, the third binary digit to the right of the point is a 1.
                                                                                                So now we have .625 = .101?? . . . (base 2) .

                                                                                                Step 4: In fact, we do not need a Step 4. We are finished in Step 3, because we had 0 as the fractional part of our result there.

                                                                                                Hence the representation of .625 = .101 (base 2) .

                                                                                                You should double-check our result by expanding the binary representation.






                                                                                                • Infinite Binary Fractions


                                                                                                the binary representation of the decimal fraction 1/10 is, in fact, infinite.Step 1: Begin with the decimal fraction and multiply by 2. The whole number part of the result is the first binary digit to the right of the point.

                                                                                                Because .1 x 2 = 0.2, the first binary digit to the right of the point is a 0.
                                                                                                So far, we have .1 (decimal) = .0??? . . . (base 2) .

                                                                                                Step 2: Next we disregard the whole number part of the previous result (0 in this case) and multiply by 2 once again. The whole number part of this new result is the second binary digit to the right of the point. We will continue this process until we get a zero as our decimal part or until we recognize an infinite repeating pattern.

                                                                                                Because .2 x 2 = 0.4, the second binary digit to the right of the point is also a 0.
                                                                                                So far, we have .1 (decimal) = .00?? . . . (base 2) .

                                                                                                Step 3: Disregarding the whole number part of the previous result (again a 0), we multiply by 2 once again. The whole number part of the result is now the next binary digit to the right of the point.

                                                                                                Because .4 x 2 = 0.8, the third binary digit to the right of the point is also a 0.
                                                                                                So now we have .1 (decimal) = .000?? . . . (base 2) .

                                                                                                Step 4: We multiply by 2 once again, disregarding the whole number part of the previous result (again a 0 in this case).

                                                                                                Because .8 x 2 = 1.6, the fourth binary digit to the right of the point is a 1.
                                                                                                So now we have .1 (decimal) = .0001?? . . . (base 2) .

                                                                                                Step 5: We multiply by 2 once again, disregarding the whole number part of the previous result (a 1 in this case).

                                                                                                Because .6 x 2 = 1.2, the fifth binary digit to the right of the point is a 1.
                                                                                                So now we have .1 (decimal) = .00011?? . . . (base 2) .

                                                                                                Step 6: We multiply by 2 once again, disregarding the whole number part of the previous result. Let's make an important observation here. Notice that this next step to be performed (multiply 2. x 2) is exactly the same action we had in step 2. We are then bound to repeat steps 2-5, then return to Step 2 again indefinitely. In other words, we will never get a 0 as the decimal fraction part of our result. Instead we will just cycle through steps 2-5 forever. This means we will obtain the sequence of digits generated in steps 2-5, namely 0011, over and over. Hence, the final binary representation will be.

                                                                                                .1 (decimal) = .00011001100110011 . . . (base 2) .
                                                                                                The repeating pattern is more obvious if we highlight it in color as below:

                                                                                                .1 (decimal) = .00011001100110011 . . . (base 2) .

                                                                                                http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm





                                                                                                • We can construct binary fractions using a binary "point", in the same was as we do with decimal:


                                                                                                101.101
                                                                                                ||| |||
                                                                                                ||| ||2-3 (1/8)
                                                                                                ||| |2-2  (1/4)
                                                                                                ||| 2-1   (1/2)
                                                                                                ||20     (1)
                                                                                                |21       (2)
                                                                                                        22        (4)
                                                                                                And so the above number represents 4 + 1 + 1/2 + 1/8 = 5 5/8 (5.625)

                                                                                                http://turing.cs.camosun.bc.ca/COMP166/resources/floatingpoint.html




                                                                                                • Binary Numbering


                                                                                                0.101

                                                                                                = 0 X 20 + 1 X 2-1 + 0 X 2-2 + 1 X 2-3

                                                                                                = 0 + 1/2 + 0 + 1/8

                                                                                                = 4/8 + 1/8

                                                                                                = 5/8


                                                                                                http://cs.furman.edu/digitaldomain/more/binary/bin1.html




                                                                                                • 1. Which of the following is the binary representation of 4 5/8?


                                                                                                A. 100.11

                                                                                                ANSWER: D


                                                                                                https://docs.google.com/viewer?a=v&q=cache:00oarkgsJgkJ:site.iugaza.edu.ps/lalsaedi/files/2010/02/Chapter_One.doc+&hl=tr&pid=bl&srcid=ADGEESjzXurOtyhphMb3gIqn3eIZoYb-rzzeM8VZfuwgjEkeUT3qz6Owdai6A5spFoV9glErHyRAj6EarlH-34TTNh2pLRWHfuR1FFwSmZMgIaTCnS1Frc-dZb873BWlEwdPq7zcNzVB&sig=AHIEtbRxYL1hEMxqJSLu9JaEE3mZTjp23w




                                                                                                • Example: Convert decimal 44 to binary.


                                                                                                DIVIDE
                                                                                                44 / 2 = 22 remainder = 0
                                                                                                22 / 2 = 11 remainder = 0
                                                                                                11 / 2 =  5 remainder = 1
                                                                                                 5 / 2 =  2 remainder = 1
                                                                                                 2 / 2 =  1 remainder = 0
                                                                                                 1 / 2 =  0 remainder = 1


                                                                                                REVERSE THE ORDER OF REMAINDERS
                                                                                                The bits, in the order they were generated is 001101 Reversing the order of bits we get 101100. Properly padded with leading zeroes to fill out one byte, we get 01011000

                                                                                                http://www.inetdaemon.com/tutorials/basic_concepts/number_systems/binary/conversion.shtml




                                                                                                • Example.  Convert the decimal number 29410 into its binary number equivalent.


                                                                                                Number 294 Dividing each number by "2" gives a result plus a remainder. The binary result is obtained by placing the remainders in order with the least significant bit (LSB) being at the top and the most significant bit (MSB) being at the bottom.
                                                                                                divide by 2
                                                                                                result 147 remainder 0  (LSB)
                                                                                                divide by 2
                                                                                                result 73 remainder 1
                                                                                                divide by 2
                                                                                                result 36 remainder 1
                                                                                                divide by 2
                                                                                                result 18 remainder 0
                                                                                                divide by 2
                                                                                                result 9 remainder 0
                                                                                                divide by 2
                                                                                                result 4 remainder 1
                                                                                                divide by 2
                                                                                                result 2 remainder 0
                                                                                                divide by 2
                                                                                                result 1 remainder 0
                                                                                                divide by 2
                                                                                                result 0 remainder 1  (MSB)

                                                                                                Then, the decimal to binary conversion gives the decimal number 29410 equivalent of 1001001102 in binary, reading from right to left.

                                                                                                http://www.electronics-tutorials.ws/binary/bin_2.html

                                                                                                The shift operators


                                                                                                The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right.

                                                                                                The following diagram shows the affect of shifting a value to the left by one digit
                                                                                                  00001111  =  15
                                                                                                SHIFT LEFT
                                                                                                  00011110  =  30


                                                                                                Compound Assignment Operators
                                                                                                The shift operators have equivalents for compound assignment
                                                                                                These are used by adding an equals sign to the operator and using the number of bits to shift by as the operand.


                                                                                                int value = 240;             // 11110000

                                                                                                value >>= 2;      // Result = 60
                                                                                                value <<= 1;      // Result = 120


                                                                                                http://www.blackwasp.co.uk/CSharpShiftOperators.aspx

                                                                                                Wednesday, March 27, 2013

                                                                                                Data vs. Information



                                                                                                • Data vs. Information


                                                                                                Data:
                                                                                                raw facts
                                                                                                no context
                                                                                                just numbers and text

                                                                                                Information:
                                                                                                data with context
                                                                                                processed data
                                                                                                value-added to data
                                                                                                summarized
                                                                                                organized
                                                                                                analyzed
                                                                                                http://www.google.com.tr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CDgQFjAB&url=http%3A%2F%2Fwww.cs.siena.edu%2F~ebreimer%2Fcourses%2Fcsis-114-s08%2Flectures%2FData%2520vs.%2520Information%2520(4).ppt&ei=qGZTUYbxCYjIswaYv4GgBg&usg=AFQjCNG67c6gZwgrpj3FEVUYSbNru5jdKQ&bvm=bv.44342787,d.Yms




                                                                                                • Data:


                                                                                                Meaning
                                                                                                Data is raw, unorganized facts that need to be processed. Data can be something simple and seemingly random and useless until it is organized.
                                                                                                Example
                                                                                                Each student's test score is one piece of data

                                                                                                Information:

                                                                                                Meaning
                                                                                                When data is processed, organized, structured or presented in a given context so as to make it useful, it is called Information.
                                                                                                Example
                                                                                                The class' average score or the school's average score is the information that can be concluded from the given data

                                                                                                http://www.diffen.com/difference/Data_vs_Information

                                                                                                Binary-coded decimal(BCD)

                                                                                                • Binary-coded decimal

                                                                                                In computing and electronic systems, binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight, although other sizes (such as six bits) have been used historically

                                                                                                As an example, encoding the decimal number 91 using uncompressed BCD results in the following binary pattern of two bytes:
                                                                                                Decimal:          9          1
                                                                                                Binary :  0000 1001  0000 0001

                                                                                                In packed BCD, the same number would fit into a single byte:
                                                                                                Decimal:     9    1
                                                                                                Binary :  1001 0001
                                                                                                https://en.wikipedia.org/wiki/Binary-coded_decimal




                                                                                                • BCD to deciman conversion


                                                                                                Short for Binary Coded Decimal, BCD is also known as packet decimal and is numbers 0 through 9 converted to four-digit binary. Below is a list of the decimal numbers 0 through 9 and the binary conversion.

                                                                                                Using this conversion, the number 25, for example, would have a BCD number of 0010 0101 or 00100101. However, in binary, 25 is represented as 11001.

                                                                                                http://www.computerhope.com/jargon/b/bcd.htm

                                                                                                graph vs tree



                                                                                                • Introduction

                                                                                                Realize that all trees are graphs. A tree is a special case of a graph, one whose nodes are all reachable from some starting node and one that has no cycles.
                                                                                                Graph (c) does not have any cycles, as one less edge than it does number of nodes, and all nodes are reachable. Therefore, it is a tree.
                                                                                                http://msdn.microsoft.com/en-us/library/ms379574(v=vs.80).aspx



                                                                                                • A tree is a connected graph with no cycles

                                                                                                https://docs.google.com/viewer?a=v&q=cache:2B00UUiFWB0J:www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15251-f09/Site/Materials/Lectures/Lecture18/lecture18.pdf+&hl=en&pid=bl&srcid=ADGEESh21IGgvVbbit2jwxSTnGhgmrTQ7ygsouGco178oA5Zj-HGbftJXWYOo6zmIzJVrz1KflxLwogoo8SkPw6iQOVKvx0fJ6-yOdeZwucLjGfNtXr2MLtxnOwRQKyxN0QFE-R3pEMo&sig=AHIEtbTjJflUVZU-sehW22YfIRzxWuFFUg

                                                                                                A Tree is just a restricted form of a Graph.
                                                                                                Trees have direction (parent / child relationships) and don't contain cycles.
                                                                                                They fit with in the category of Directed Acyclic Graphs (or a DAG)
                                                                                                http://stackoverflow.com/questions/7423401/whats-the-difference-between-the-data-structure-tree-and-graph

                                                                                                Tree is a hierarchical model.
                                                                                                Graph is a network model.
                                                                                                http://freefeast.info/difference-between/difference-between-trees-and-graphs-trees-vs-graphs/

                                                                                                Infix to Postfix Conversion

                                                                                                • Infix to Postfix Conversion : 


                                                                                                Infix String : a+b*c-d
                                                                                                Postfix String : abc*+d-
                                                                                                http://scriptasylum.com/tutorials/infix_postfix/algorithms/infix-postfix/index.htm



                                                                                                • Infix to Postfix Notation

                                                                                                http://www.youtube.com/watch?v=rA0x7b4YiMI


                                                                                                • Infix to Postfix Notation

                                                                                                http://www.youtube.com/watch?v=1X_li3efgDI&feature=related



                                                                                                • Insert-sort with Romanian folk dance

                                                                                                https://www.youtube.com/watch?v=ROalU379l3U


                                                                                                • Algorithms #2 - Insertion Sort

                                                                                                https://www.youtube.com/watch?v=Fr0SmtN0IJM

                                                                                                Tuesday, March 26, 2013

                                                                                                Binary search algorithm

                                                                                                • Binary search algorithm

                                                                                                In computer science, a binary search or half-interval search algorithm finds the position of a specified value (the input "key") within a sorted array.
                                                                                                In each step, the algorithm compares the input key value with the key value of the middle element of the array

                                                                                                If the keys match, then a matching element has been found so its index, or position, is returned. Otherwise, if the sought key is less than the middle element's key, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the input key is greater, on the sub-array to the right

                                                                                                http://en.wikipedia.org/wiki/Binary_search_algorithm


                                                                                                • Binary search algorithm


                                                                                                It means, that in worst case, algorithm makes 20 steps to find a value in sorted array of a million elements or to say, that it doesn't present it the array.


                                                                                                Algorithm

                                                                                                Algorithm is quite simple. It can be done either recursively or iteratively:

                                                                                                get the middle element;
                                                                                                if the middle element equals to the searched value, the algorithm stops;
                                                                                                otherwise, two cases are possible:
                                                                                                searched value is less, than the middle element. In this case, go to the step 1 for the part of the array, before middle element.
                                                                                                searched value is greater, than the middle element. In this case, go to the step 1 for the part of the array, after middle element.
                                                                                                   
                                                                                                   
                                                                                                Java

                                                                                                /**
                                                                                                 * searches for a value in sorted array
                                                                                                 *
                                                                                                 * @param array
                                                                                                 *            array to search in
                                                                                                 * @param value
                                                                                                 *            searched value
                                                                                                 * @param left
                                                                                                 *            index of left boundary
                                                                                                 * @param right
                                                                                                 *            index of right boundary
                                                                                                 * @return position of searched value, if it presents in the array or -1, if
                                                                                                 *         it is absent
                                                                                                 */
                                                                                                int binarySearch(int[] array, int value, int left, int right) {
                                                                                                      if (left > right)
                                                                                                            return -1;
                                                                                                      int middle = (left + right) / 2;
                                                                                                      if (array[middle] == value)
                                                                                                            return middle;
                                                                                                      else if (array[middle] > value)
                                                                                                            return binarySearch(array, value, left, middle - 1);
                                                                                                      else
                                                                                                            return binarySearch(array, value, middle + 1, right);        
                                                                                                }


                                                                                                http://www.algolist.net/Algorithms/Binary_search




                                                                                                • İkili Arama Algoritması (Binary Search Algorithm)

                                                                                                http://www.bilgisayarkavramlari.com/2009/12/21/ikili-arama-algoritmasi-binary-search-algorithm/



                                                                                                • İkili arama algoritması

                                                                                                http://tr.wikipedia.org/wiki/%C4%B0kili_arama_algoritmas%C4%B1



                                                                                                • Binary Search - Example, Explanations, Algorithm & Code Part 2/2

                                                                                                http://www.youtube.com/watch?v=ZvJA-bdIvN8


                                                                                                Sunday, March 24, 2013

                                                                                                Reflection

                                                                                                • Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine.

                                                                                                http://docs.oracle.com/javase/tutorial/reflect/index.html




                                                                                                • Reflection allows the examination/modification of classes/objects at runtime. Personally I have only used it to implement a factory pattern. This is where there are a number of classes/subclasses that could be used to create objects at runtime. Based on some variable I can create the correct object by loading the class I want.


                                                                                                Class<?> c = Class.forName(someclass);
                                                                                                superTypeOfClass = c.newInstance();

                                                                                                I believe the instanceOf (isInstance() maybe) is also part of the Reflection API allowing you to discover the run time type of an object. Hope this helps.


                                                                                                Another example is Spring core framework's depedency injection. It is done through Reflection API.


                                                                                                Reflection API helps to manipulate classes and its properties at run time. You can create instance for class and can execute all methods (including private).
                                                                                                For example, To test private methods in JUnit.
                                                                                                http://www.linkedin.com/groups/What-is-Reflection-API-Can-70526.S.225700742?view=&srchtype=discussedNews&gid=70526&item=225700742&type=member&trk=eml-anet_dig-b_pd-ttl-cn&ut=0j-X2_38EiZRE1

                                                                                                Cocoa Touch



                                                                                                • Cocoa Touch

                                                                                                Cocoa Touch is a UI framework for building software programs to run on the iPhone, iPod Touch, and iPad from Apple Inc.
                                                                                                https://en.wikipedia.org/wiki/Cocoa_Touch

                                                                                                Saturday, March 23, 2013

                                                                                                Java ORMs for MongoDB



                                                                                                • MJORM (mongo-java-orm) - A MongoDB Java ORM

                                                                                                This project aims to provide a robust query api and ORM for MongoDB and the Java programming language
                                                                                                https://code.google.com/p/mongo-java-orm/


                                                                                                • Spring Data - MongoDB

                                                                                                Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for for new datastores while retaining store-specific features and capabilities
                                                                                                http://www.springsource.org/spring-data/mongodb


                                                                                                • Morphia

                                                                                                Morphia is a lightweight type-safe library for mapping Java objects to/from MongoDB:
                                                                                                https://code.google.com/p/morphia/


                                                                                                • jongo

                                                                                                http://jongo.org/


                                                                                                • Hibernate OGM

                                                                                                Hibernate OGM is an attempt to store data in a NoSQL data grid using the Hibernate ORM engine rather than rewriting a JPA engine from scratch.
                                                                                                https://github.com/hibernate/hibernate-ogm

                                                                                                dependency injection

                                                                                                • Google Guice
                                                                                                Google Guice is an open source software framework for the Java platform released by Google under the Apache License. It provides support for dependency injection using annotations to configure Java objects
                                                                                                Dependency injection is a design pattern whose core principle is to separate behavior from dependency resolution.
                                                                                                http://en.wikipedia.org/wiki/Google_Guice



                                                                                                Put simply, Guice alleviates the need for factories and the use of new in your Java code
                                                                                                Think of Guice's @Inject as the new new
                                                                                                https://code.google.com/p/google-guice/


                                                                                                • Dependency Injection in Spring
                                                                                                Dependency injection (DI) is a design pattern in object-oriented computer programming whose purpose is to reduce the coupling between software components.
                                                                                                http://www.mkyong.com/spring/spring-dependency-injection-di/
                                                                                                http://en.wikipedia.org/wiki/Dependency_injection
                                                                                                http://www.youtube.com/watch?v=PGfs2CxDGM4



                                                                                                • You can mix both, Constructor-based and Setter-based DI but it is a good rule of thumb to use constructor arguments for mandatory dependencies and setters for optional dependencies.

                                                                                                ode is cleaner with the DI principle and decoupling is more effective when objects are provided with their dependencies. The object does not look up its dependencies, and does not know the location or class of the dependencies rather everything is taken care by the Spring Framework.

                                                                                                http://www.tutorialspoint.com/spring/spring_dependency_injection.html



                                                                                                • Dependency Injection Types

                                                                                                Constructor Injection
                                                                                                The constructor arguments are injected during instance instantiation.
                                                                                                Setter Injection
                                                                                                This is the most favored method of dependency injection in Spring. Dependencies are “set” in the objects through setter methods defined in a Spring configuration file
                                                                                                Interface Injection
                                                                                                This is not implemented in Spring currently, but by Avalon. It’s a different type of DI that involves mapping items to inject to specific interfaces.
                                                                                                Spring uses the concept of a BeanFactory as its assembler, and it is the BeanFactory that manages the JavaBeans you have configured to run within it.
                                                                                                In Spring, the initialization of a bean by the framework is exactly equivalent to using the new keyword to instantiate an object in Java code
                                                                                                Once the framework has instantiated the object, it manages the scope of the bean, based on its configuration.

                                                                                                Because the IoC container is managing the beans, JNDI lookups that are typical in Java EE containers are no longer required, leaving your code container-agnostic and easier to unit test both inside and outside of the framework. And while you are coding to interfaces as part of good OO practice, Spring allows you to manage what implementations are used by leveraging dependency injection, resulting in cleaner, decoupled components.

                                                                                                All we need to do is inform Spring through an XML configuration file that the recorder bean is implemented by the LocalVoteRecorder class.
                                                                                                <bean id="recorder"      class="com.springindepth.LocalVoteRecorder" />

                                                                                                Then we simply map the recorder bean to the VotingBooth bean by setter injection in that beans definition.
                                                                                                <bean id="votingBooth"
                                                                                                      class="com.springindepth.VotingBooth">
                                                                                                    <property name="voteRecorder" ref="recorder"/>
                                                                                                </bean>

                                                                                                The IoC container manages java objects – from instantiation to destruction – through its BeanFactory.

                                                                                                http://www.springbyexample.org/examples/core-concepts-bean-management-through-ioc.html



                                                                                                • Basic Bean Creation

                                                                                                A Spring bean in the IoC container can typically be any POJO (plain old java object).
                                                                                                Creating a Spring bean is as simple as coding your POJO and adding a bean configuration element to the Spring XML configuration file or annotating the POJO

                                                                                                             
                                                                                                public class DefaultMessage {

                                                                                                    private String message = "Spring is fun.";

                                                                                                    /**
                                                                                                    * Gets message.
                                                                                                    */
                                                                                                    public String getMessage() {
                                                                                                        return message;
                                                                                                    }

                                                                                                    /**
                                                                                                    * Sets message.
                                                                                                    */
                                                                                                    public void setMessage(String message) {
                                                                                                        this.message = message;
                                                                                                    }

                                                                                                }


                                                                                                  The bean element below indicates a bean of type Message – defined by the class attribute – with an id of 'message'.
                                                                                                  The instance of this bean will be registered in the container with this id.
                                                                                                  <bean id="message"    class="org.springbyexample.di.xml.DefaultMessage" />

                                                                                                  When the container instantiates the message bean, it is equivalent to initializing an object in your code with 'new DefaultMessage()'.


                                                                                                http://www.springbyexample.org/examples/intro-to-ioc.html



                                                                                                • Basic Constructor Injection

                                                                                                we have our POJO and a basic configuration for the message bean, we can introduce our first dependency injection examples
                                                                                                Through the Spring beans XML file you can configure your bean to initialize with an argument for the constructor, and then assign the arguments.
                                                                                                Spring essentially “injects” the argument into your beans
                                                                                                This is referred to as constructor injection.

                                                                                                The following example passes in the String message using a constructor. The class is the same as the one in Basic Bean Creation except the default message on the message variable has been cleared and is now set to null. A single parameter constructor has been added to set a message.

                                                                                                public class ConstructorMessage {

                                                                                                    private String message = null;

                                                                                                    /**
                                                                                                    * Constructor
                                                                                                    */
                                                                                                    public ConstructorMessage(String message) {
                                                                                                        this.message = message;
                                                                                                    }

                                                                                                    /**
                                                                                                    * Gets message.
                                                                                                    */
                                                                                                    public String getMessage() {
                                                                                                        return message;
                                                                                                    }

                                                                                                    /**
                                                                                                    * Sets message.
                                                                                                    */
                                                                                                    public void setMessage(String message) {
                                                                                                        this.message = message;
                                                                                                    }

                                                                                                }


                                                                                                The configuration for this bean is exactly the same as in the previous example, but now we have a new element, the constructor-arg. The constructor-arg element injects a message into the bean using the constructor-arg element's value attribute.

                                                                                                <bean id="message"  class="org.springbyexample.di.xml.ConstructorMessage">
                                                                                                        <constructor-arg value="Spring is fun." />
                                                                                                    </bean>



                                                                                                http://www.springbyexample.org/examples/intro-to-ioc-basic-constructor-injection.html


                                                                                                • Basic Setter Injection

                                                                                                The Spring IoC container also supports setter injection, which is the preferred method of dependency injection in Spring.

                                                                                                In most cases Spring will lowercase the first letter after “set” in the method name and use the rest of the method name as-is for deducing the property name. So for example if there is a setMessage() method in your class, the property name you would use when setting that property on a bean in the XML config is 'message'. If there is a setFirstName() method in your class, the property name you would use when setting the value is 'firstName'. 
                                                                                                In cases where the letters after “set” are all uppercase, Spring will leave the property name as uppercase. So if you have setXML() on a class, the property name would be 'XML'

                                                                                                public class SetterMessage {

                                                                                                    private String message = null;

                                                                                                    /**
                                                                                                    * Gets message.
                                                                                                    */
                                                                                                    public String getMessage() {
                                                                                                        return message;
                                                                                                    }

                                                                                                    /**
                                                                                                    * Sets message.
                                                                                                    */
                                                                                                    public void setMessage(String message) {
                                                                                                        this.message = message;
                                                                                                    }

                                                                                                }
                                                                                                  
                                                                                                  
                                                                                                  The property element is used to define the setter injection: 
                                                                                                  
                                                                                                  <bean id="message" class="org.springbyexample.di.xml.SetterMessage">
                                                                                                        <property name="message" value="Spring is fun." />
                                                                                                    </bean>

                                                                                                http://www.springbyexample.org/examples/intro-to-ioc-basic-setter-injection.html


                                                                                                • Reference Injection
                                                                                                Values can also be injected by reference 
                                                                                                one bean definition can be injected into another.
                                                                                                To do this, you use the constructor-arg or property's ref attribute instead of the value attribute

                                                                                                  the first bean definition is a java.lang.String with the id springMessage
                                                                                                  
                                                                                                  <bean id="springMessage" class="java.lang.String">
                                                                                                        <constructor-arg value="Spring is fun." />
                                                                                                  </bean>
                                                                                                  
                                                                                                  
                                                                                                  It is injected into the second bean definition by reference using the property element's ref attribute.
                                                                                                  
                                                                                                  <bean id="message"  class="org.springbyexample.di.xml.SetterMessage">
                                                                                                        <property name="message" ref="springMessage" />
                                                                                                  </bean>
                                                                                                  
                                                                                                  http://www.springbyexample.org/examples/intro-to-ioc-reference-injection.html


                                                                                                •   Spring Constructor-based Dependency Injection
                                                                                                  
                                                                                                  Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class.
                                                                                                  
                                                                                                  
                                                                                                package com.tutorialspoint;

                                                                                                public class SpellChecker {
                                                                                                  public SpellChecker(){
                                                                                                      System.out.println("Inside SpellChecker constructor." );
                                                                                                  }

                                                                                                  public void checkSpelling() {
                                                                                                      System.out.println("Inside checkSpelling." );
                                                                                                  }
                                                                                                  
                                                                                                }

                                                                                                <!-- Definition for spellChecker bean -->
                                                                                                <bean id="spellChecker" class="com.tutorialspoint.SpellChecker"></bean>



                                                                                                package com.tutorialspoint;

                                                                                                public class TextEditor {
                                                                                                  private SpellChecker spellChecker;

                                                                                                  public TextEditor(SpellChecker spellChecker) {
                                                                                                      System.out.println("Inside TextEditor constructor." );
                                                                                                      this.spellChecker = spellChecker;
                                                                                                  }
                                                                                                  public void spellCheck() {
                                                                                                      spellChecker.checkSpelling();
                                                                                                  }
                                                                                                }


                                                                                                <!-- Definition for textEditor bean -->
                                                                                                  <bean id="textEditor" class="com.tutorialspoint.TextEditor">
                                                                                                      <constructor-arg ref="spellChecker"/>
                                                                                                  </bean>
                                                                                                  
                                                                                                  
                                                                                                  To resolve this ambiguity, the order in which the constructor arguments are defined in a bean definition is the order in which those arguments are supplied to the appropriate constructor_based_dependency_injection
                                                                                                  
                                                                                                package x.y;

                                                                                                public class Foo {
                                                                                                  public Foo(int year, String name) {
                                                                                                      // ...
                                                                                                  }
                                                                                                }
                                                                                                  

                                                                                                  <beans>
                                                                                                  <bean id="foo" class="x.y.Foo">
                                                                                                      <constructor-arg ref="bar"/>
                                                                                                      <constructor-arg ref="baz"/>
                                                                                                  </bean>

                                                                                                  <bean id="bar" class="x.y.Bar"/>
                                                                                                  <bean id="baz" class="x.y.Baz"/>
                                                                                                </beans> 
                                                                                                  
                                                                                                  
                                                                                                  one more case where we pass different types to the constructor_based_dependency_injection
                                                                                                  
                                                                                                  package x.y;

                                                                                                    public class Foo {
                                                                                                      public Foo(int year, String name) {
                                                                                                      // ...
                                                                                                      }
                                                                                                    }

                                                                                                    
                                                                                                    <bean id="exampleBean" class="examples.ExampleBean">
                                                                                                      <constructor-arg type="int" value="2001"/>
                                                                                                      <constructor-arg type="java.lang.String" value="Zara"/>
                                                                                                  </bean>
                                                                                                  
                                                                                                  
                                                                                                  the best way to pass constructor arguments, use the index attribute to specify explicitly the index of constructor arguments
                                                                                                  
                                                                                                  <bean id="exampleBean" class="examples.ExampleBean">
                                                                                                      <constructor-arg index="0" value="2001"/>
                                                                                                      <constructor-arg index="1" value="Zara"/>
                                                                                                  </bean>
                                                                                                  
                                                                                                  in case you are passing a reference to an object, you need to use ref attribute of <constructor-arg> tag and if you are passing a value directly then you should use value attribute
                                                                                                  
                                                                                                  
                                                                                                http://www.tutorialspoint.com/spring/constructor_based_dependency_injection.htm

                                                                                                Spring can instance objects in two ways: 

                                                                                                    Singleton: Instantiate only one object
                                                                                                    Prototype: Instantiate a new object everytime

                                                                                                        <bean id="ticketVendingMachine"
                                                                                                        class="com.studytrails.tutorials.springsingletonandprototype.TicketVendingMachine"
                                                                                                        scope="singleton" />

                                                                                                    <bean id="ticket"
                                                                                                        class="com.studytrails.tutorials.springsingletonandprototype.Ticket"
                                                                                                        scope="prototype" />
                                                                                                        
                                                                                                        
                                                                                                    http://www.studytrails.com/frameworks/spring/spring-singleton-and-prototype.jsp


                                                                                                •     Spring Dependency Injection: Setter Injection
                                                                                                    
                                                                                                    
                                                                                                    the ATM class and Printer class can collaborate with each other to print the balance information for a bank account
                                                                                                    
                                                                                                    dependency where the reference of one class is held by another class
                                                                                                    
                                                                                                    The ATM class holds a reference to Printer class below. 
                                                                                                    
                                                                                                    private Printer printer;
                                                                                                    
                                                                                                    ATM class depends on Printer class
                                                                                                    
                                                                                                    public class ATM { 
                                                                                                    private Printer printer;
                                                                                                    
                                                                                                    
                                                                                                    The dependencies need to be 'resolved' before the desired functionality can be achieved
                                                                                                    By 'resolved' we mean that an instance of Printer class needs to be created and associated with the 'printer' member in ATM class
                                                                                                    When dependency resolution is not performed by the class itself but is left to be done by an external agent (e.g. Spring Framework) it is called dependency injection
                                                                                                    Spring will create an instance of the Printer class and associate the instance with the 'printer' member in ATM class
                                                                                                    as the 'printer' member in ATM class is private, the ATM class needs to expose its dependency to Spring for it to inject the Printer instance into the ATM class.
                                                                                                    
                                                                                                    If the ATM class exposes its dependency on Printer class as a setter method so that Spring can inject the Printer object then this is called as Setter injection
                                                                                                    
                                                                                                    public void setPrinter(Printer printer)
                                                                                                    
                                                                                                    ATM class takes in Printer class as a setter methods
                                                                                                    
                                                                                                    public class ATM {

                                                                                                    private Printer printer;

                                                                                                    public Printer getPrinter() {
                                                                                                        return printer;
                                                                                                    }
                                                                                                    public void setPrinter(Printer printer) {
                                                                                                        this.printer = printer;
                                                                                                    }
                                                                                                    
                                                                                                    
                                                                                                       
                                                                                                    
                                                                                                    http://www.studytrails.com/frameworks/spring/spring-setter-injection.jsp


                                                                                                •  Spring Dependency Injection: Constructor Injection
                                                                                                    
                                                                                                    Spring will create an instance of the Printer class and associate the instance with the 'printer' member in ATM class. 
                                                                                                    as the 'printer' member in ATM class is private, the ATM class needs to expose its dependency to Spring for it to inject the Printer instance into the ATM class
                                                                                                    
                                                                                                    If the ATM class exposes its dependency on Printer class as a constructor so that Spring can inject it then this is called as Constructor injection
                                                                                                    
                                                                                                    public ATM(Printer printer) 
                                                                                                    
                                                                                                    ATM class takes in Printer class as a constructor argument 
                                                                                                    
                                                                                                    public class ATM {

                                                                                                    private Printer printer;
                                                                                                    
                                                                                                    public ATM(Printer printer) {
                                                                                                        this.printer = printer;
                                                                                                    }
                                                                                                    ...
                                                                                                    
                                                                                                    
                                                                                                    <bean id="printer" class="com.studytrails.tutorials.springcontructorinjection.Printer">
                                                                                                    </bean>
                                                                                                    
                                                                                                    <bean id="atm" class="com.studytrails.tutorials.springcontructorinjection.ATM">
                                                                                                            <constructor-arg ref="printer"/>
                                                                                                    </bean>    
                                                                                                        
                                                                                                    
                                                                                                    
                                                                                                    http://www.studytrails.com/frameworks/spring/spring-constructor-injection.jsp


                                                                                                • IOC can be achieved by either of the following:
                                                                                                1. DI (Dependency Injection)
                                                                                                2. Service Locator


                                                                                                3 types of DI
                                                                                                1.1 Constructor Injection
                                                                                                1.2 Setter Injection
                                                                                                1.3 Interface Injection

                                                                                                http://programmers.stackexchange.com/questions/131451/difference-between-dependency-injection-di-inversion-of-control-ioc


                                                                                                • Inversion of Control vs Dependency Injection [closed]
                                                                                                inversion of control is the principle where the control flow of a program is inverted: instead the programmer controls the flow of a program, the external sources (framework, services, other components) take control of it. It likes we plug something into something else

                                                                                                IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.
                                                                                                DI is a form of IoC, where implementations are passed into an object through constructors/setters/service look-ups, which the object will 'depend' on in order to behave correctly.

                                                                                                IoC without using DI, for example would be the Template pattern because the implementation can only be changed through sub-classing.

                                                                                                DI Frameworks are designed to make use of DI and can define interfaces (or Annotations in Java) to make it easy to pass in implementations.

                                                                                                IoC Containers are DI frameworks that can work outside of the programming language. In some you can configure which implementations to use in metadata files (e.g. XML) which are less invasive. With some you can do IoC that would normally be impossible like inject implementation at pointcuts.

                                                                                                Inversion of Control (IoC) means that objects do not create other objects on which they rely to do their work. Instead, they get the objects that they need from an outside source (for example, an xml configuration file).

                                                                                                Dependency Injection (DI) means that this is done without the object intervention, usually by a framework component that passes constructor parameters and set properties.


                                                                                                http://stackoverflow.com/questions/6550700/inversion-of-control-vs-dependency-injection