How to Assigning Subnets and Hosts

Subnet is a group of computers that share the same subnet number.
Subnet number is the part of an IP address that identifies the subnet that the IP belongs to.
Host number is the part of an IP address that identifies the host on the subnet.

The non-highlighted part above determines the subnet. It is called the subnet mask.
In this example, we have subnet mask /20: 11001000 00010111 00010110 10100001

For every host, its IP address will be in the form:
network_id host_id
Which is then broken down into:
network_id subnet_number host_number

IP address in dot notation has structure: xxx.xxx.xxx.xxx
Each xxx can be 0 - 255 in decimal. Each xxx is called an octet, because it has 8 bits.
Examples of IP of addresses:
231.33.44.1
127.0.0.0 is the local host IP address
0.0.0.0 is the local host IP address in routing tables
255.255.255.255 is the IP address used for broadcast on LANs
There are no 0.0.0.0 and 255.255.255.255 addresses assigned to any device on the Internet because all 0s is the local host and all 1s is the broadcast.

Subnet mask has the structured xxx.xxx.xxx.xxx . However, the mask has to have all consecutive 1's on the far left. The first octet has to be 255.
Subnet mask also can be written as: xxx.xxx.xxx.xxx /y, where y is the number of leading 1s.
Example of subnet mask: 255.255.255.0 /24 in decimal or 11111111.11111111.11111111.00000000 in binary

Within the octets of the subnet address, we have the subnet number.
Examples of subnet address:192.33.44.0 /24
This subnet can host IP addresses 192.33.44.1 - 192.33.44.254

Class Structure of IP address Default subnet mask IP addresses
Class C net.net.net.host
at most 8 bits for host number and subnet number
255.255.255.0 192.0.0.0 - 223.255.255.255
Class B net.net.host.host
at most 16 bits for host number and subnet number
255.255.0.0 128.x.x.x - 191.x.x.x
Class A net.host.host.host
at most 24 bits for host number and subnet number
255.0.0.0 0.x.x.x - 127.x.x.x ideally
actually 1.x.x.x - 126.x.x.x
Because subnets with all 0s and all 1s will not work.
All 0s means no subnetting, and all 1s will be the same as subnet mask.

Subnet mask in decimal octets notation Subnet mask in / notation Subnet mask in binary octets notation Type of Address # of IP addresses
255.255.255.255 /32 11111111.11111111.11111111.11111111 Class C (broadcast) 20
255.255.255.254 /31 11111111.11111111.11111111.11111110 Class C 21
255.255.255.252 /30 11111111.11111111.11111111.11111100 22
255.255.255.248 /29 11111111.11111111.11111111.11111000 23
255.255.255.240 /28 11111111.11111111.11111111.11110000 24
255.255.255.224 /27 11111111.11111111.11111111.11100000 25
255.255.255.192 /26 11111111.11111111.11111111.11000000 26
255.255.255.128 /25 27
255.255.255.0 /24 11111111.11111111.11111111.00000000 Class C default 28
255.255.254.0 /23 11111111.11111111.11111110.00000000 Class B 216
255.255.252.0 /22 11111111.11111111.11111100.00000000 210
255.255.248.0 /21 11111111.11111111.11111000.00000000 211
255.255.240.0 /20 11111111.11111111.11110000.00000000 212
255.255.224.0 /19 11111111.11111111.11100000.00000000 213
255.255.192.0 /18 11111111.11111111.11000000.00000000 214
255.255.128.0 /17 11111111.11111111.10000000.00000000 215
255.255.0.0 /16 11111111.11111111.00000000.00000000 Class B default 216
255.254.0.0 /15 11111111.11111110.00000000.00000000 Class A 217
255.252.0.0 /14 11111111.11111100.00000000.00000000 218
255.248.0.0 /13 11111111.11111000.00000000.00000000 219
255.240.0.0 /12 11111111.11110000.00000000.00000000 220
255.224.0.0 /11 11111111.11100000.00000000.00000000 221
255.192.0.0 /10 11111111.11000000.00000000.00000000 222
255.128.0.0 /9 11111111.10000000.00000000.00000000 223
255.0.0.0 /8 11111111.00000000.00000000.00000000 Class A default 224

Example: /28 mask for class C address
Starting from network 123.33.44.0
Subnet 123.33.44.0 with subnet mask /28 means the first 28 bits are used for network portion of the IP address, and the last 4 bits are used for host names.
We can have 24 - 2 hosts per subnets = 14 subnets (we cannot have hosts 0 and 255), each supporting 14 hosts.
Valid subnets: 256 - 240 = 16. So: 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224.

Subnet 16 32 48 ... 224
First host 17 33 49 225
Last host 30 46 238
Broadcast 31 47 239

Subnet Hosts
123.33.44.16 123.33.44.17
123.33.44.18
...
123.33.44.30
123.33.44.32 123.33.44.33
123.33.44.34
...
123.33.44.46
123.33.44.48 ...
...
123.33.44.224

Check:
123.33.44.17 && 00010001
255.255.255.240 = 11110000
123.33.44.16 00010000

&& is bitwise AND which means that you go through each bit, and AND the bits individually. It uses the same truth table as regular AND, except that we perform AND on every pair of bits.
For example, 1101 bitwise AND 0111 = 0101

Convert 16 in decimal to binary.
16/2 = 8 remainder 0
8/2 = 4 remainder 0
4/2 = 2 remainder 0
2/2 = 1 remainder 0
1/2 = 0 remainder 1
So binary is 00010000

https://www.easycalculation.com/decimal-converter.php

Convert 00010000 in binary to decimal.
0x27 + 0x26 + 0x25 + 1x24 + 0x23 + 0x22 + 0x21 + 0x20
= 0 + 0 + 0 + 16 + 0 + 0 + 0 + 0
So decimal is 16

https://www.easycalculation.com/binary-converter.php

Proxy Server

Proxy server is a network entity that satisfies HTTP requests on the behalf of an origin Web server. It can substantially reduce the response time for a client request and traffic on an institution‘s access link to the Internet.

Proxy Server
Schematic representation of a proxy server, where the computer in the middle acts as the proxy server between the other two.

This is a very simple proxy server which only understands simple GET-requests. This server will accept GET message from a browser, forward GET message to the destination Web server, receive the HTTP response message from the destination server, and forward the HTTP response message to the browser.

Code

There are three classes ProxyCache, HttpRequest, and HttpResponse which are able to receive requests, forward them, read replies, and return those to the clients.
1. ProxyCache holds the start-up code for the proxy and code for handling the requests.
2. HttpRequest contains the routines for parsing and processing the incoming requests from clients.
3. HttpResponse takes care of reading the replies from servers and processing them.

Running the Proxy

This proxy uses DataInputStreams for processing the replies from servers. This is because the replies are mixture of textual and binary data and the only input streams in Java which allow treating both at the same time are DataInputStreams. To get the code to compile, we must use the –deprecation argument for the compiler.
1. At the MSDOS prompt navigate to the directory of java classes
2. Type javac –deprecation proxycache.java
3. Type java ProxyCache 4533. This will start the proxy and listen in to port 4533.

Configuring the firefox browser

1. Go to the Advanced section
2. Click on the Network tab
3. Click Settings in the Connection section
4. Enter 127.0.0.1 in the HTTP Proxy field
5. Type in 4533 in Port field
6. Click OK
7. Clear web browser cache
8. Navigate to a simple page (For example: https://campus.hpu.edu/cp/home/displaylogin)

UML Class Diagram

Proxy Server UML

UML class diagram allows us to visualize relationships among classes and objects. The arrows connecting the ProxyCache, HttpRequest, and HttpResponse classes indicate that a relationship exists between classes. This diagram describes the classes in the system, the attributes and operations associated with a class. An attribute is any class-level data including variables and constants. An operation is essentially equivalent to a method.

Proxy Functionality

The proxy works as follows.
1. The proxy listens for requests from clients to a specified port at command prompt
2. When there is a request, the proxy spawns a new thread for handling the request and creates an HttpRequest-object which contains the request.
3. The new thread sends the request to the server.
4. The thread reads the server‘s reply into an HttpResponse-object and sends the response back to the requesting client.

A cache can be both a server and client at the same time. When it receives requests from and sends responses to a browser, it is a server. When it sends requests to and receives responses from an origin server, it is a client.

Microsoft Windows XP [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Francis Nguyen>cd\csci3401\java\jdk1.6.0_16\bin
C:\csci3401\java\jdk1.6.0_16\bin>javac -deprecation proxycache.java
C:\csci3401\java\jdk1.6.0_16\bin>java ProxyCache 4533
1
Setting up socket
Ready and listening at port: 4533

2
Create HttpRequest by reading it from the client socket:
Method is: GET
URI is: http://campus.hpu.edu/cp/home/cps/images/redezyn/crv_bg.gif
Version is: HTTP/1.1
Host to contact is: campus.hpu.edu at port 80

3
Send request to server:
Socket[addr=campus.hpu.edu/198.199.136.32,port=80,localport=52053]
Already sent request to server.

4
Read response and forward it to the client:

Write headers to client:
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://campus.hpu.edu/jsp/misc/noauth.jsp
Content-Length: 0
Date: Mon, 05 Apr 2010 22:49:21 GMT
Connection: close

Write body to client:
[B@1de3f2d
Finished sending response to client

2
Create HttpRequest by reading it from the client socket:
Method is: GET
URI is: http://campus.hpu.edu/jsp/misc/noauth.jsp
Version is: HTTP/1.1
Host to contact is: campus.hpu.edu at port 80

3
Send request to server:
Socket[addr=campus.hpu.edu/198.199.136.32,port=80,localport=52055]
Already sent request to server.

4
Read response and forward it to the client:

Write headers to client:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=4C037945BBDD3A0E1BAE0B04DB5CC2AD; Path=/
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Content-Length: 3988
Date: Mon, 05 Apr 2010 22:49:21 GMT
Connection: close

Write body to client:
[B@ab95e6

Finished sending response to client