Page 1
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page1
Experiment No:A1
Title: To Implement Packet sniffer.
Aim: Implementation of Packet sniffer. Program should identify header of each
protocol. Use multi-core programming.
Prerequisites:
Student should know Wireshark packet sniffer tool.
Student should know basic concept like Protocol, Packet header format of protocols.
Objective: Study of Packet sniffer tool and understand how to implement packet sniffer tool.
Theory:
Protocol: It is an agreement between the communicating parties show that how communication is
proceed.
Packet Sniffer:
A packet sniffer is a wire-tap devices\SW that plugs into computer networks and eavesdrops on
the network traffic. Like a telephone wiretap. Allows us to listen in on other people's conversations.
A "sniffing" program lets someone listen in on computer conversations.
A packet sniffer can be a computer program or a piece of computer hardware that can intercept
and log traffic passing over a digital network or part of a network. As data streams travel back and
forth over the network, the sniffer captures each packet and eventually decodes and analyzes its
content according with any specifications.
However, computer conversations consist of apparently random binary data. Therefore, network
wiretap programs also come with a feature known as "protocol analysis", which allow them to
"decode" the computer traffic and make sense of it.
Page 2
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page2
Why we use packet snifing?
The versatility of packet sniffers means they can be used to:
Analyze network problems.
Detect network intrusion attempts.
Gain information for effecting a network intrusion.
Gather and report network statistics
Filter suspect content from network traffic.
Debug client/server communications
Malicious use:
Spy on other network users and collect sensitive information such as
passwords (depending on any content encryption methods which may be in
use)
Reverse engineer protocols used over the network.
Example uses:
A packet sniffer for a token ring network could detect that the token has been lost or the
presence of too many tokens (verifying the protocol).
Page 3
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page3
A packet sniffer could detect that messages are being sent to a network adapter; if the
network adapter did not report receiving the messages then this would localize the failure
to the adapter.
A packet sniffer could detect excessive messages being sent by a port, detecting an error
in the implementation.
A packet sniffer could collect statistics on the amount of traffic (number of messages) from
a process detecting the need for more bandwidth or a better method.
To implement Packet sniffer tool using multicore programming we have some goals:
Goal 1:Implement a TCP Protocol Analysis Tool in C.
Tasks:
T1:Creating a Socket to capture packets.
T2:Capturing the Packets from the network.
T3:Extracting headers from the packet.
T4:Printing the extracted header in an arranged format.
Page 4
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page4
So we can successfully implement a TCP Protocol Analysis Tool in C using above tasks.
Goal 2:Implement a Protocol Analysis Tool in Python.
Tasks:
T1:Intercept the Network Interface to capture Packet.
T2:Applying filter to capture IP packets.
T3:Printing the packet.
So we can successfully implement a Protocol Analysis Tool in Python using above tasks.
Goal 3:Implement a Multithreaded Protocol Analysis Tool in Python.
Tasks:
T1:Intercept the Network Interface to capture Packet.
T2:Dividing the work on multiple cores i.emultiprocessing.
Page 5
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page5
T3:Applying filter to capture IP packets.
T4:Printing the packet.
So we can successfully implement a Multithreaded Protocol Analysis Tool in Python using above
tasks.
Conclusion: Thus we have implemented packet sniffer tool.
Questions:
1. What is packet sniffer?
2. What is protocol?
3. Draw Header format of IPv4, TCP, UDP, and ICMP.
Page 6
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page6
Assignment No:A2
Title: Create subnets. Assign subnet mask. Perform following:
a) Ping the machine of same subnet.
b) Ping the machine in subnet A from machine of subnet B.
c) Analyze the output of the above sub assignments.
Aim: Consider the network id 192.168.4.0 or such relevant IP and create four subnets
namely A, B, C, D. Assign the subnet mask. Write a Python program to Perform
the following operations (use overloading if applicable).
a) Ping the machine of same subnet.
b) Ping the machine in subnet A from machine of subnet B.
c) Analyze the output of the above sub assignments.
Prerequisites: Student should know what is LAN, what is Subnet, what is ping command.
Objective:
To study how to design subnet and assign subnet mask.
Theory:
Subnet: A subnetwork, or subnet, is a logical, visible subdivision of an IP network.
Subnetting: The practice of dividing a network into two or more networks is called subnetting.
Computers that belong to a subnet are addressed with a common, identical, most-significant bit-
group in their IP address.
Each IP class is equipped with its own default subnet mask which bounds that IP class to have
prefixed number of Networks and prefixed number of Hosts per network. Classful IP addressing
does not provide any flexibility of having less number of Hosts per Network or more Networks
per IP Class.
Class A Subnets
In Class A, only the first octet is used as Network identifier and rest of three octets are used to be
assigned to Hosts (i.e. 16777214 Hosts per Network). To make more subnet in Class A, bits from
Host part are borrowed and the subnet mask is changed accordingly.
For example, if one MSB (Most Significant Bit) is borrowed from host bits of second octet and
added to Network address, it creates two Subnets (21=2) with (223-2) 8388606 Hosts per Subnet.
Page 7
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page7
The Subnet mask is changed accordingly to reflect subnetting. Given below is a list of all possible
combination of Class A subnets:
Class B Subnets
By default, using Classful Networking, 14 bits are used as Network bits providing (214) 16384
Networks and (216-1) 65534 Hosts. Class B IP Addresses can be subnetted the same way as Class
A addresses, by borrowing bits from Host bits. Below is given all possible combination of Class
B subnetting:
Page 8
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page8
Class C Subnets
Class C IP addresses are normally assigned to a very small size network because it can only have
254 hosts in a network. Given below is a list of all possible combination of subnetted Class B IP
address:
Ping Command:
The ping command is a Command Prompt command used to test the ability of the source computer
to reach a specified destination computer. The ping command is usually used as a simple way
verify that a computer can communicate over the network with another computer or network
device.
Page 9
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page9
The ping command operates by sending Internet Control Message Protocol (ICMP) Echo Request
messages to the destination computer and waiting for a response. How many of those responses
are returned, and how long it takes for them to return, are the two major pieces of information that
the ping command provides.
Command is:
ping ip address
EX.ping 172.16.1.10
Conclusion: Thus we have Created subnet, assigned subnet mask and performed ping operation.
Questions:
1. What is subnet?
2. Give the range of class A,B & C.
3. What is the default mask for class A,B & C?
4. What is subnet mask?
Page 10
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page10
Assignment No: A3
Title: Menu Driven Image Processing Operations
Aim: Write C++ Program with GUI to capture using remotely placed camera and read
uncompressed TIFF Image to perform following functions (Menu Driven) Use of Overloading and
Morphism is expected. Image Frame1 is used for displaying Original Image and Image Frame 2 is
used for displaying the action performed.
Sharpen the Image
Blur the Image (Programmable rectangular Seed)
Programmable image Contrast and Brightness
Rotate image by programmable angle
Convolution (overloading: FFT, Other)
Histogram
Mean and Standard Deviation of image
PDF of a Signal acquired through ADC
Prerequisites: Basics of Image processing and types of digital image processing.
Objective:
Know the basic components of an image processing system.
Know the key concepts in image file formats.
Understand the model for an image analysis process.
Theory:
Blurring
In blurring, we simple blur an image. An image looks sharper or more detailed if we are able to
perceive all the objects and their shapes correctly in it. For example. An image with a face looks
clear when we are able to identify eyes, ears, nose, lips, and forehead e.t.c very clear. This shape
of an object is due to its edges. So in blurring, we simple reduce the edge content and make the
transition from one color to the other very smooth.
Page 11
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page11
ORIGINAL IMAGE BLURRED IMAGE
Sharpening
Human perception is highly sensitive to edges and fine details of an image, and since they are
composed primarily by high frequency components, the visual quality of an image can be
enormously degraded if the high frequencies are attenuated or completed removed. In contrast,
enhancing the high-frequency components of an image leads to an improvement in the visual
quality. Image sharpening refers to any enhancement technique that highlights edges and fine
details in an image. Image sharpening is widely used in printing and photographic industries for
increasing the local contrast and sharpening the images.
In principle, image sharpening consists of adding to the original image a signal that is
proportional to a high-pass filtered version of the original image. Figure No. 1 illustrates this
procedure, often referred to an unsharp masking on a one-dimensional signal. As shown in Fig
No.1, the original image is first filtered by a high-pass filter that extracts the high-frequency
components, and then a scaled version of the high-pass filter output is added to the original image,
thus producing a sharpened image of the original. Note that the homogeneous regions of the signal,
i.e., where the signal is constant, remain unchanged.
Page 12
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page12
Brightness:
Brightness is a relative term. It depends on your visual perception. Since brightness is a relative
term, so brightness can be defined as the amount of energy output by a source of light relative to
the source we are comparing it to. In some cases we can easily say that the image is bright, and
in some cases, its not easy to perceive.
For Example:-
Just have a look at both of these images, and compare which one is brighter.
Page 13
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page13
We can easily see that the image on the right side is brighter as compared to the image on the
left. But if the image on the right is made darker then the first one, then we can say that the
image on the left is brighter then the left.
Contrast:
The range of optical density and tone on a photographic image (or the extent to which adjacent
areas on a CRT differ in brightness.
Contrast stretching (often called normalization) is a simple image enhancement technique that
attempts to improve the contrast in an image by `stretching' the range of intensity values it contains
to span a desired range of values, e.g. the full range of pixel values that the image type concerned
allows. It differs from the more sophisticated histogram equalization in that it can only apply a
linear scaling function to the image pixel values. As a result the `enhancement' is less harsh. (Most
implementations accept a gray level image as input and produce another gray level image as
output.)
Page 14
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page14
Rotation of an Image:
The rotation operator performs a geometric transform which maps the position of a picture
element in an input image onto a position in an output image by rotating it through a user-
specified angle about an origin . In most implementations, output locations which are
outside the boundary of the image are ignored. Rotation is most commonly used to improve the
visual appearance of an image, although it can be useful as a preprocessor in applications where
directional operators are involved. Rotation is a special case of affine transformation.
Page 15
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page15
Convolution of an image:
Consider this example.
The same image in the frequency domain can be represented as.
Page 16
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page16
Now what’s the relationship between image or spatial domain and frequency domain. This
relationship can be explained by a theorem which is called as Convolution theorem.
Convolution Theorem
The relationship between the spatial domain and the frequency domain can be established by
convolution theorem.
The convolution theorem can be represented as.
It can be stated as the convolution in spatial domain is equal to filtering in frequency domain and
vice versa.
The filtering in frequency domain can be represented as following:
The steps in filtering are given below.
At first step we have to do some pre – processing an image in spatial domain, means
increase its contrast or brightness
Then we will take discrete Fourier transform of the image
Then we will center the discrete Fourier transform , as we will bring the discrete Fourier
transform in center from corners
Then we will apply filtering , means we will multiply the Fourier transform by a filter
function
Then we will again shift the DFT from center to the corners
Page 17
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page17
Last step would be take to inverse discrete Fourier transform , to bring the result back from
frequency domain to spatial domain
And this step of post processing is optional, just like pre processing, in which we just
increase the appearance of image.
Filters
The concept of filter in frequency domain is same as the concept of a mask in convolution.
After converting an image to frequency domain, some filters are applied in filtering process to
perform different kind of processing on an image. The processing include blurring an image ,
sharpening an image e.t.c.
The common type of filters for these purposes is:
Ideal high pass filter
Ideal low pass filter
Gaussian high pass filter
Gaussian low pass filter
Histogram:
We have already seen that contrast can be increased using histogram stretching. In this tutorial we
will see that how histogram equalization can be used to enhance contrast.
Before performing histogram equalization, you must know two important concepts used in
equalizing histograms. These two concepts are known as PMF and CDF.
They are discussed in our tutorial of PMF and CDF. Please visit them in order to successfully grasp
the concept of histogram equalization.
Histogram Equalization:
Histogram equalization is used to enhance contrast. It is not necessary that contrast will always be
increase in this. There may be some cases were histogram equalization can be worse. In those cases
the contrast is decreased.
Let’s start histogram equalization by taking this image below as a simple image.
Page 18
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page18
Histogram of this image:
The histogram of this image has been shown below.
Mean & standard Deviation
Average
The average brightness of a region is defined as the sample mean of the pixel brightnesses within
that region. The average, ma, of the brightnesses over the Λ pixels within a region (ℜ) is given by:
Page 19
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page19
The unbiased estimate of the standard deviation, sa, of the brightnesses within a region (ℜ) with
Λ pixels is called the sample standard deviation and is given by:
Conclusion: Hence we have studied Menu Driven Image Processing Operations on JPG image
and TIFF image.
FAQ:-
1) What is image enhancement in digital image processing? Explain any two gray level
transforms in used for image enhancement.
2) Explain the operation of CCD (Charge Coupled Device) used in electronic cameras.
3) Describe in brief fundamental steps in Digital image processing.
Page 20
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page20
Assignment No:A4
Title: To read the HTTP header and analyze the parameters
Aim: Write a program to read the HTTP header and analyze the parameters.
Prerequisites:
Student should know what Protocol is.
Student should know what HTTP Protocol is.
Objective: Study of HTTP header and Analyze parameter.
Theory:
Hypertext Transport Protocol
This protocol used for communication between web browsers and web servers.It is used
on World Wide Web.
TCP port 80 (443 secure).
RFC 2616 (ver 1.1)
HTTP is based on the client-server architecture model and a stateless request/response
protocol that operates by exchanging messages across a reliable TCP/IP connection.
An HTTP "client" is a program (Web browser or any other client) that establishes a
connection to a server for the purpose of sending one or more HTTP request messages.
An HTTP "server" is a program (Generally a web server like Apache Web Server or
Internet Information Services IIS, etc.) that accepts connections in order to serve HTTP
requests by sending HTTP response messages.
HTTP makes use of the Uniform Resource Identifier (URI) to identify a given resource
and to establish a connection. Once the connection is established, HTTP messages are
passed in a format similar to that used by the Internet mail [RFC5322] and the
Multipurpose Internet Mail Extensions (MIME) [RFC2045].
I. Message Format:
These messages include requests from client to server and responses from server to
client which will have the following format:
HTTP-message = <Request> | <Response> ; HTTP/1.1 messages
Page 21
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page21
HTTP requests and HTTP responses use a generic message format of RFC 822 for
transferring the required data. This generic message format consists of the following four
items:
Message Start-Line:
A start-line will have the following generic syntax:
Start-line = Request-Line | Status-Line
o Request Line: - Used in HTTP Request Message.
GET /hello.htm HTTP/1.1 (This is Request-Line sent by the client)
o Status-Line: - Used in HTTP Response Message.
HTTP/1.1 200 OK (This is Status-Line sent by the server)
Header Fields:
HTTP header fields provide required information about the request or response, or about
the object sent in the message body.
There are four types of HTTP message headers:
a. General-header: These header fields have general applicability for both request
and response messages.
b. Request-header: These header fields have applicability only for request
messages.
c. Response-header: These header fields have applicability only for response
messages.
d. Entity-header: These header fields define meta information about the entity-
body or, if no body is present, about the resource identified by the request.
Message Body:
The message body part is optional for an HTTP message but if it is available, then it is
used to carry the entity-body associated with the request or response. If entity body is
Page 22
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page22
associated, then usually Content-Type and Content-Length headers lines specify the
nature of the body associated.
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
II. URI-URN-URL
Uniform Resource Identifier: Information about a resource
Uniform Resource Name : The name of the resource with in a namespace
Uniform Resource Locator: How to find the resource, a URI that says how to find the
resource.
III. HTTP –URLs
Uniform Resource Locator:
Protocol (http, ftp, news)
Host name (name.domainname)
Port (usually 80)
Directory path to the resource
Resource name
Example:
http://xxx.myplace.com/www/index.html
http://xxx.myplace.com:80/cgi-bin/t.exe
IV. HTTP –methods:
Page 23
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page23
1. GET
Retrieve a URL from the server
Simple page request
Run a CGI program
Run a CGI with arguments attached to the URL
2. POST
Preferred method for forms processing
Run a CGI program
Parameterized data in sysin
More secure and private
3. PUT
Used to transfer a file from the client to the server
4. HEAD
Requests URLs status header only
Used for conditional URL handling for performance enhancement schemes
Retrieve URL only if not in local cache or date is more recent than cached
copy
5. DELETE
Removes all current representations of the target resource given by a URI.
6. CONNECT
Establishes a tunnel to the server identified by a given URI.
7. OPTIONS
Describes the communication options for the target resource.
8. TRACE
Performs a message loop-back test along the path to the target resource.
V. HTTP Request:
The Request-Line begins with a method token, followed by the Request-URI
and the protocol versionThe elements are separated by space SP characters.
Request-Line = Method SP Request-URI SP HTTP-Version
Request Header Fields: The request-header fields allow the client to pass
additional information about the request, and about the client itself, to the
server. Here is a list of some important Request-header fields that can be used
based on the requirement:
o Accept-Charset
o Accept-Encoding
o Accept-Language
o Authorization
o Expect
o From
Page 24
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page24
o Host
o If-Match
o If-Modified-Since
o If-None-Match
o If-Range
o If-Unmodified-Since
o Max-Forwards
o Proxy-Authorization
o Range
o Referer
o TE
o User-Agent
Examples of Request Message:
Now let's put it all together to form an HTTP request to fetch hello.htm page
from the web server .
GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
VI. HTTP Response:
Message Status-Line:
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase
HTTP Version:A server supporting HTTP version 1.1 will return the
following version information:
HTTP-Version = HTTP/1.1
Status Codes
•200 OK •201 created
•202 accepted •204 no content
Page 25
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page25
•301 moved perm. •302 moved temp
•304 not modified •400 bad request
•401 unauthorized •403 forbidden
•404 not found •500 int. server error
•501 not impl. •502 bad gateway
•503 svc not avail
Examples of Response Message:
Now let's put it all together to form an HTTP response for a request to fetch the
hello.htm page from the web server .
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Conclusion: Thus we have Studied HTTP header and its parameters.
Questions:
1. What is HTTP?
2. Draw message format of HTTP.
Page 26
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page26
Assignment No:A5
Title: Installing and configure DHCP server and install the software on remote machine.
Aim: Installing and configure DHCP server and write a program (Python) to install the
software on remote machine.
Prerequisites: Student should know what is BOOTP Protocol,commands for linux i.e command
to install packages,remove packages etc.
Objective: To study how to assign IP address automatically to DHCP clients.
To learn & understand the basic concepts DHCP and configuration of DHCP
Server.
Theory:
A] Dynamic Host Configuration Protocol(DHCP):
Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a server to
automatically assign an IP address to a computer from a defined range of numbers (i.e., a scope)
configured for a given network. It is an extension of BOOTP protocol.
DHCP message Format:
Page 27
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page27
DHCP States:
DHCP assigns an IP address when a system is started, for example:
1. A user turns on a computer with a DHCP client.
2. The client computer sends a broadcast request (called a DISCOVER or
DHCPDISCOVER), looking for a DHCP server to answer.
3. The router directs the DISCOVER packet to the correct DHCP server.
4. The server receives the DISCOVER packet. Based on availability and usage policies set
on the server, the server determines an appropriate address (if any) to give to the client.
The server then temporarily reserves that address for the client and sends back to the
client an OFFER (or DHCPOFFER) packet, with that address information. The server
also configures the client's DNS servers, WINS servers, NTP servers, and sometimes
other services as well.
5. The client sends a REQUEST (or DHCPREQUEST) packet, letting the server know that
it intends to use the address.
Page 28
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page28
6. The server sends an ACK (or DHCPACK) packet, confirming that the client has a been
given a lease on the address for a server-specified period of time.
When a computer uses a static IP address, it means that the computer is manually
configured to use a specific IP address. One problem with static assignment, which can result from
user error or inattention to detail, occurs when two computers are configured with the same IP
address. This creates a conflict that results in loss of service. Using DHCP to dynamically assign
IP addresses minimizes these conflicts.
The most common settings provided by a DHCP server to DHCP clients include:
IP address and netmask
IP address of the default-gateway to use
IP adresses of the DNS servers to use
However, a DHCP server can also supply configuration properties such as:
Host Name
Domain Name
Time Server
Print Server
The advantage of using DHCP is that changes to the network, for example a change in the
address of the DNS server, need only be changed at the DHCP server, and all network hosts will
be reconfigured the next time their DHCP clients poll the DHCP server. As an added advantage,
it is also easier to integrate new computers into the network, as there is no need to check for the
availability of an IP address. Conflicts in IP address allocation are also reduced.
A DHCP server can provide configuration settings using the following methods:
Manual allocation (MAC address)
This method entails using DHCP to identify the unique hardware address of each network
card connected to the network and then continually supplying a constant configuration
each time the DHCP client makes a request to the DHCP server using that network
device. This ensures that a particular address is assigned automatically to that network
card, based on it's MAC address.
Dynamic allocation (address pool)
In this method, the DHCP server will assign an IP address from a pool of addresses
(sometimes also called a range or scope) for a period of time or lease, that is configured
on the server or until the client informs the server that it doesn't need the address
anymore. This way, the clients will be receiving their configuration properties
Page 29
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page29
dynamically and on a "first come, first served" basis. When a DHCP client is no longer
on the network for a specified period, the configuration is expired and released back to
the address pool for use by other DHCP Clients. This way, an address can be leased or
used for a period of time. After this period, the client has to renegociate the lease with the
server to maintain use of the address.
Automatic allocation
Using this method, the DHCP automatically assigns an IP address permanently to a
device, selecting it from a pool of available addresses. Usually DHCP is used to assign a
temporary address to a client, but a DHCP server can allow an infinite lease time.
The last two methods can be considered "automatic" because in each case the DHCP server
assigns an address with no extra intervention needed. The only difference between them is in
how long the IP address is leased, in other words whether a client's address varies over time.
Ubuntu is shipped with both DHCP server and client. The server is dhcpd (dynamic host
configuration protocol daemon). The client provided with Ubuntu is dhclient and should be
installed on all computers required to be automatically configured. Both programs are easy to
install and configure and will be automatically started at system boot.
Installation of DHCP server in ubuntu
At a terminal prompt, enter the following command to install dhcpd:
sudo apt-get install isc-dhcp-server
This will complete the installation.
Configuring DHCP server
Next you need to make a backup copy of /etc/dhcp3/dhcpd.conf file
Edit /etc/dhcp/dhcpd.conf file using the following command:
sudo gedit /etc/dhcp/dhcpd.conf
You need to change the following sections in /etc/dhcp/dhcpd.conf file
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.2.255;
option routers 192.168.2.254;
option domain-name-servers 192.168.2.1, 192.168.2.2;
option domain-name "yourdomainname.com";
Page 30
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page30
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.10 192.168.2.200;
}
save and exit the file
This will result in the DHCP server giving a client an IP address from the range
192.168.2.10-192.168.2.200 . It will lease an IP address for 600 seconds if the client doesn't ask
for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The
server will also "advise" the client that it should use 255.255.255.0 as its subnet mask,
192.168.2.255 as its broadcast address, 192.168.2.254 as the router/gateway and 192.168.2.1 and
192.168.2.2 as its DNS servers.
Configure Ubuntu DHCP Client:
If you want to configure your ubuntu desktop as DHCP client following this procedure
You need to open /etc/network/interfaces file
sudo vi /etc/network/interfaces
make sure you have the following lines (eth0 is an example)
auto lo eth0
iface eth0 inet dhcp
iface lo inet loopback
Save and exit the file.
B] Remote installation of software:
There are certain tasks while installing Software on remote machine:
1. Authentication
2. Execution of commands
3. Whatever executed on remote machine that shoul be reflected on client’s machine.
For the connectivity with remote system SSH protocol is used having port no 22.It is secure
share protocol.
OpenSSH is a freely available version of the Secure Shell (SSH) protocol family of tools for
remotely controlling, or transferring files between, computers. Traditional tools used to
accomplish these functions, such as telnet or rcp, are insecure and transmit the user's password in
Page 31
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page31
cleartext when used. OpenSSH provides a server daemon and client tools to facilitate secure,
encrypted remote control and file transfer operations, effectively replacing the legacy tools.
Installation of SSH server:
sudo apt-get install openssh-server
Start SSH service using following command:
Service ssh start
Command to Copy File from one computer to remote:
scp filename usrname_of_remot_ machine@hostname_of_remote_machine:/path_where_
we_have_to_copy_file/
Command to copy file from remote to local:
scp usrname_of_remote_machine@hostname_of_remote_machine/path/filename
We will implement a python program to execute a command on remote machine.
Conclusion: Thus we have configured DHCP server and installed the software on remote machine.
Questions:
1. What is DHCP?
2. Explain lease allocation process.
3. Draw DHCP packet format.
Page 32
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page32
Assignment No:A6
Title: Design and Setup LAN with Star topology to access Storage Area Network (SAN).
The SAN must have DSP data, Text Data, Multimedia Data available for the
access.
Aim: To design and setup LAN with star topology to access Storage Area Network.
Prerequisites:
Student should know about IP addressing.
Student should know basic concept like type of network topology, storage types, device.
Student should know basic commands for Ubuntu.
Objective: Implement Storage Area Network on LAN.
Theory:
What is SAN ?
A storage area network (SAN) is a dedicated network that provides access to consolidated, block
level data storage. SANs are primarily used to enhance storage devices, such as disk arrays, tape
libraries, and optical jukeboxes, accessible to servers so that the devices appear like locally
attached devices to the operating system. A SAN typically has its own network of storage devices
that are generally not accessible through the local area network (LAN) by other devices.
Page 33
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page33
Benefits of SAN?
Sharing storage usually simplifies storage administration and adds flexibility since cables
and storage devices do not have to be physically moved to shift storage from one server to
another.
Other benefits include the ability to allow servers to boot from the SAN itself. This allows
for a quick and easy replacement of faulty servers since the SAN can be reconfigured so
that a replacement server can use the LUN of the faulty server. While this area of
technology is still new, many view it as being the future of the enterprise datacenter
SANs also tend to enable more effective disaster recovery processes. A SAN could span a
distant location containing a secondary storage array. This enables storage replication
either implemented by disk array controllers, by server software, or by specialized SAN
devices. Since IP WANs are often the least costly method of long-distance transport, the
Fibre Channel over IP (FCIP) and iSCSI protocols have been developed to allow SAN
extension over IP networks. The traditional physical SCSI layer could only support a few
meters of distance - not nearly enough to ensure business continuance in a disaster.
SAN using iSCSI:
Page 34
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page34
The Small Computer Systems Interface (SCSI) is a popular family of protocols for
communicating with I/O devices, especially storage devices.
iSCSI= Internet SCSI = SCSI over TCP/IP–send SCSI commands over an IP network
The iSCSI protocol enables universal access to storage devices and storage-area networks
(SANs) over standard Ethernet-based TCP/IP networks.
iSCSI maintains the SCSI notion of an Initiator and Target device
iSCSI removes the traditional bus structure of SCSI and maps SCSI over a network
iSCSISession Types:
iSCSI has two (2) Session types
–Discovery
–Normal
Each Session has two (2) Phases
–Login–Contains Security Negotiation and Operational Parameter Negotiation
–Full Feature Phase
Configuration of iSCSI on Ubuntu:
TARGET CONFIGURATION:
LioTarget
LIOTarget is available in Linux kernels 3.1 and higher.
Install the Liotarget packages:
# apt-get install targetcli
Liotarget is controlled using the targetcli command line utility.
Configuration Commands:
> targetcli
Page 35
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page35
>cd backstores/fileio
/backstores/fileio> help create(for help)
/backstores/fileio> create lun0 /root/iscsilun0 2g (create 2GB file backed LUN)
Now the LUN is created. Next we’ll set up the target so client systems can access the storage.
/backstores/fileio/lun0> cd /iscsi
/iscsi> create(create iqnand target port group)
/iscsi/iqn.20...a672ba1/tpgt1> set attribute authentication=0(turn off chap auth)
/iscsi/iqn.20...a672ba1/tpgt1> cd luns
/iscsi/iqn.20...a1/tpgt1/luns> create /backstores/fileio/lun0(create the target LUN)
/iscsi/iqn.20...gt1/luns/lun0> cd ../../portals
/iscsi/iqn.20...tpgt1/portals> create IP Address of machine (eg 172.16.75.209)
Register initiator —this IQN is the IQN of the initiator —do this for each initiator that will access
the target
/iscsi/iqn.20...102.164:3260> cd../../acls
/iscsi/iqn.20...a1/tpgt1/acls> create iqn.1994-05.com.redhat:f5b312caf756
/> saveconfig (SAVE the configuration!)
/> exit
INITIATOR CONFIGURATION:
iSCSI Initiator Install
To configure Ubuntu Server as an iSCSI initiator
install the open-iscsipackage.
In a terminal enter: sudo apt-get install open-iscsi
Page 36
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page36
iSCSI Initiator Configuration
Once the open-iscsipackage is installed, edit /etc/iscsi/iscsid.conf changing the following: node.startup=
automatic
You can check which targets are available by using the iscsiadmutility. Enter the following in a terminal:
sudo iscsiadm –m discovery –t st -p 172.16.75.209
-m: determines the mode that iscsiadm executes in.
-t: specifies the type of discovery.
-p: option indicates the target IP address.
If the target is available you should see output similar to the following: 172.16.75.209:3260,1 iqn.1992-
05.com.emc:sl7b92030000520000-2
–The iqn number and IP address above will vary depending on your hardware.
Login to the iSCSI node:
sudo iscsiadm –m node –login
Check to make sure that the new disk has been detected using dmesg:
dmesg| grep sd
Formatting disk:
Next, create a partition, format the file system, and mount the new iSCSI disk. In a terminal enter:
sudo fdisk /dev/sdb
n
p
Page 37
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page37
enter
w
Now format the file system and mount it to /srv as an example:
sudo mkfs.ext4 /dev/sdb1
sudo mount /dev/sdb1 /srv
Finally, add an entry to /etc/fstab to mount the iSCSI drive during boot:
/dev/sdb1 /srvext4 defaults,auto,_netdev 0 0
Reboot Target machine
Conclusion:
Thus we have implemented and configuration SAN in local Area Network using Liotarget (storage
management soft) and iSCSI Protocol.
Questions:
1) What is SAN?
2) Basic Structure of SAN.
3) Packages needed for configuration of SAN.
4) Give steps for configuration of Target/Server Machine.
5) Give steps for configuration of Client/initiator machine.
Page 38
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page38
Assignment No:B1
Title: Edge detection by Sobel operator
Aim: Write a Python program to grab the image from Camera and apply the edge detection
algorithm (overloaded with Sobel variants, Others) to find the edges use BBB / ARM Cortex
A5/A9/M4 Mobile Boards. Store the Images in SAN (for BIGDATA analytics)
Prerequisites:
Objective: To understand & implement edge detection algorithm by sobel operator on an image.
Theory: 1. Edge detection
Edge detection is a basic tool used in image processing, basically for feature detection and
extraction, which aim to identify points in a digital image where brightness of image changes
sharply and find discontinuities. The purpose of edge detection is significantly reducing the
amount of data in an image and preserves the structural properties for further image processing. In
a grey level image the edge is a local feature that, with in a neighborhood separates regions in each
of which the gray level is more or less uniform with in different values on the two sides of the
edge. For a noisy image it is difficult to detect edges as both edge and noise contains high
frequency contents which results in blurred and distorted result.
Different edge detection methodologies
Edge detection makes use of differential operators to detect changes in the gradients of the grey
levels. It is divided into two main categories:
Page 39
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page39
FIRST ORDER EDGE DETECTION OR GRADIENT BASED EDGE OPERATOR:
It is based on the use of a first order derivative, or can say gradient based. If I (i , j) be the input
image, then image gradient is given by following formula
Classical operators
Robert, Sobel , Prewitt are classified as classical operators which are easy to operate but highly
sensitive to noise.
Page 40
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page40
1. Robert operator
It is gradient based operator. It firstly computes the sum of the squares of the difference between
diagonally adjacent pixels through discrete differentiation and then calculate approximate gradient
of the image. The input image is convolved with the default kernels of operator and gradient
magnitude and directions are computed. It uses following 2 x2 two kernels:
Conclusion: Thus we have implemented packet sniffer tool.
The plus factor of this operator is its simplicity but having small kernel it is highly sensitive to
noise not and not much compatible with today’s technology.
2 .Sobel operator
Sobel operator is a discrete differentiation operator used to compute an approximation of the
gradient of image intensity function for edge detection. At each pixel of an image, sobel operator
gives either the corresponding gradient vector or normal to the vector. It convolves the input image
with kernel and computes the gradient magnitude and direction. It uses following 3x3 two kernels:
As compared to Robert operator have slow computation ability but as it has large kernel so it is
less sensitive to noise as compared to Robert operator. As having larger mask, errors due to effects
of noise are reduced by local averaging within the neighborhood of the mask.
Page 41
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page41
3 Prewitt operators
The function of Prewitt edge detector is almost same as of sobel detector but have different kernels:
Prewitt edge operator gives better performance than that of sobel operator.
ARM Cortex Description :
Conceptually the Cortex-M4 is a Cortex-M3 plus DSP Instructions, and optional floating-point
unit (FPU). If a core contains an FPU, it is known as a Cortex-M4F, otherwise it is a Cortex-M4.
Key features of the Cortex-M4 core are:
ARMv7E-M architecture
Instruction sets
o Thumb (entire)
o Thumb-2 (entire)
o 1-cycle 32-bit hardware multiply, 2-12 cycle 32-bit hardware divide, saturated math
support
o DSP extension: Single cycle 16/32-bit MAC, single cycle dual 16-bit MAC, 8/16-
bit SIMD arithmetic
3-stage pipeline with branch speculation
1 to 240 physical interrupts, plus NMI
Page 42
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page42
12 cycle interrupt latency
Integrated sleep modes
Silicon options:
Optional Floating-Point Unit (FPU): single-precision only IEEE-754 compliant. This is
called the FPv4-SP extension.
Optional Memory Protection Unit (MPU): 0 or 8 regions
Chips
The following microcontrollers are based on the Cortex-M4 core:
Atmel SAM4L, SAM4N, SAM4S
Freescale Kinetis K
The following microcontrollers are based on the Cortex-M4F (M4 + FPU) core:
Atmel SAM4C (dual core), SAM4E, SAMG
Energy Micro EFM32 Wonder
Freescale Kinetis K
Infineon XMC4000
NXP LPC4000, LPC4300(one Cortex-M4F + one Cortex-M0)
STMicroelectronics STM32 F3, F4
Texas Instruments LM4F, TM4C
Spansion FM4F
Toshiba TX04
The following chips have either a Cortex-M4 or M4F as a secondary core:
Freescale Vybrid VF6 (one Cortex-A5 + one Cortex-M4F)
Texas Instruments OMAP 5 (one dual-core Cortex-A15 + two Cortex-M4)
Page 43
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page43
Conclusion:
Page 44
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page44
Hence we have studied edge detection algorithm by Sobel operator on image.
FAQ:-
1) What is edge detection technique? Explain in brief different edge detection techniques.
2) Explain the following terms associated with audio processing.
i) Timbre ii) Loudness iii) Pitch
3) What do you mean by Speech Synthesis and Recognition? Draw and explain Human
Speech Model in brief.
Page 45
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page45
Assignment No:B4
Title: Study and perform Linux networking commands emulation using Python or C++.
Aim: Study and perform Linux networking commands emulation using Python or C++.
Prerequisites: Student should know basic Linux commands.
Objective:
Students should be able to perform Linux networking commands emulation using Python or C++.
Theory:
Linux networking commands emulation:
An emulation is a system that behaves exactly like something else, and abides by all of
the rules of the system being emulated. It is effectively a complete replication of another system,
right down to being binary compatible with the emulated system's inputs and outputs, but
operating in a different environment to the environment of the original emulated system. The
rules are fixed, and cannot be changed or the system fails.
Example of Networking commands in Unix
let's see some example of various networking command in Unix and Linux. Some of them are
quite basic e.g. ping and telnet and some are more powerful e.g. nslookup and netstat. When you
used these commands in combination of find and grep you can get anything you are looking for
e.g. hostname, connection end points, connection status etc.
hostname with no options displays the machines host name
hostname –d displays the domain name the machine belongs to
hostname –f displays the fully qualified host and domain name
hostname –i displays the IP address for the current machine
ping
It sends packets of information to the user-defined source. If the packets are received, the
destination device sends packets back. Ping can be used for two purposes
1. To ensure that a network connection can be established.
2. Timing information as to the speed of the connection.
Page 46
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page46
If you do ping www.yahoo.com it will display its IP address. Use ctrl+C to stop the test.
ifconfig
View network configuration, it displays the current network adapter configuration. It is handy to
determine if you are getting transmit (TX) or receive (RX) errors.
netstat
Most useful and very versatile for finding connection to and from the host. You can find out all
the multicast groups (network) subscribed by this host by issuing "netstat -g"
netstat -nap | grep port will display process id of application which is using that port
netstat -a or netstat –all will display all connections including TCP and UDP
netstat --tcp or netstat –t will display only TCP connection
netstat --udp or netstat –u will display only UDP connection
netstat -g will display all multicast network subscribed by this host.
nslookup
If you know the IP address it will display hostname. To find all the IP addresses for a given
domain name, the command nslookup is used. You must have a connection to the internet for this
utility to be useful.
E.g. nslookup blogger.com
You can also use nslookup to convert hostname to IP Address and from IP Address from
hostname.
traceroute
A handy utility to view the number of hops and response time to get to a remote system or web
site is traceroute. Again you need an internet connection to make use of this tool.
Ex. traceroute 172.16.75.222
port = 33434
max_hops = 30
Page 47
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page47
finger
View user information, displays a user’s login name, real name, terminal name and write status.
this is pretty old unix command and rarely used now days.
Conclusion: Thus we have studied how to perform Linux networking commands emulation.
Questions:
1. What are different Linux networking commands?
2. What is Emulation?
3. finding host/domain name and IP address – hostname
4. test network connection – ping
5. getting network configuration – ifconfig
6. Network connections, routing tables, interface statistics – netstat
7. query DNS lookup name – nslookup
8. checking status of destination host - telnet
Page 48
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page48
Assignment No:B9
Title: Implementation of Concurrent Text Conferencing application using Python or
Java.
Aim: Implementation of Concurrent Text Conferencing application using Python or
Java.
Prerequisites: Student should know what Text conferencing is.
Objective: To study implementation of chat application.
Theory:
Concurrent Text Conferencing:
The Concurrent text conferencing include the LAN Chat Server is a program that functions as
the server side of the chat software for the local area network.
The server side of the program allows all the clients of the software to connect with one to each
other. In order to operate this program correctly, you will need the client side of this program
(different distribution).
Text Messaging
It combines everything necessary for text chat between users: chatting in channels, message exchange,
animated emoticons, and a bulletin board. All text information is transferred in Unicode encoding.
Image Exchange
It allows image exchange that is quick, comfortable and effective. Images inserted into public channels,
private channels or messages are automatically compressed to ensure maximum comfort and minimum
network load.
File Transfer
It enables users to exchange files in the fastest and most comfortable way. Just drag and drop the
necessary files or folders onto the recipient’s image in the list and the program will begin the file transfer.
Advanced buffering mechanisms make the most effective possible use of networks with a bandwidth from
32 Kbit/s to 1 000 Mbit/s. Resumed downloads allow users to finish a file transfer even in cases where the
connection is broken for up to 5 minutes.
Page 49
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page49
What is the difference between the terms concurrent and parallel execution?
What is Thread in java?
1. All Java programs have at least one thread, known as the main thread, which is created by
the JVM at the program’s start, when the main() method is invoked with the main thread.
2. Every Java thread is created and controlled by the java.lang.Thread class.
3. A Java program can have many threads, and these threads can run concurrently, either
asynchronously or synchronously.
Multitasking:
1. multitasking is a method by which multiple tasks, also known as processes, share common
processing resources such as a CPU
2. Multitasking refers to the ability of the OS to quickly switch between each computing task
to give the impression the different applications are executing multiple actions
simultaneously.
3. As CPU clock speeds have increased steadily over time, not only do applications run faster,
but OSs can switch between applications more quickly. This provides better overall
performance
Page 50
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page50
Multicore:
When running on a multicore system, multitasking OSs can truly execute multiple tasks
concurrently.
the multiple computing engines work independently on different tasks.
For example, on a dual-core system, four applications - such as word processing, e-mail,
Web browsing, and antivirus software - can each access a separate processor core at the
same time. You can multitask by checking e-mail and typing a letter simultaneously, thus
improving overall performance for applications.
Page 51
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page51
Multithreading:
Multithreading is the ability of a program or an operating system to serve more than one
user at a time and to manage multiple simultaneous requests without the need to have
multiple copies of the programs running within the computer.
The main purpose of multithreading is to provide simultaneous execution of two or more
parts of a program to maximum utilize the CPU time. A multithreaded program contains
two or more parts that can run concurrently. Each part of such a program called a thread.
Each thread has a separate path of its execution. So this way a single program can perform
two or more tasks simultaneously.
Threads are lightweight processes; they share the same address space. In Multithreaded
environment, programs make maximum use of CPU so that the idle time can be kept to
minimum.
Difference between Process and Thread?
Process:
1. Program in Execution
2. Heavy Weight
3. Required Separate address space
4. inter process communication is expensive
Thread:
1. separate path of execution,one or more thread is called process
2. light weight
3. share same address space
4. Inter thread communication is less expensive
Conclusion: Thus we have studied Implementation of Concurrent Text Conferencing application.
Questions:
1. What is Text conferencing in LAN?
2. Explain the concept of concurrent Text Conferencing?
3. What are different steps for performing Concurrent text conferencing?
Page 52
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page52
Assignment No: B12
Title: Implement a program for remote print manager to print documents on remote
printer. (IP based printer) using Python
Aim: To implement python program to print document on remote printer.
Prerequisites:
Student should know about printer management in LAN.
Student should know basics of subprocess like os, popen and print command.
Objective: Implement program for print a document on remote printer.
Theory:
Remote Printing:
Remote printing is a function in which a computer is used with a distant printer. Remote printing
programs are available for most computers. It is often possible, however, to set up the feature in
the operating system without the need for a specialized application program.
We are using the following subprocess
subprocess.Popen()
The underlying process creation and management in this module is handled by the Popen class. It
offers a lot of flexibility so that developers are able to handle the less common cases not covered
by the convenience functions. subprocess.Popen() executes a child program in a new process.
subprocess.Popen() – stdin
Writing to a process can be done in a very similar way. If we want to send data to the process's stdin, we
need to create the Popen object with stdin=subprocess.PIPE
subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
Page 53
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page53
subprocess.PIPE
Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that a pipe
to the standard stream should be opened.
subprocess.STDOUT
Special value that can be used as the stderr argument to Popen and indicates that standard error should go
into the same handle as standard output.
To support a wide variety of use cases, the Popen constructor accept a large number of optional arguments.
The arguments that are most commonly needed are:
args is required for all calls and should be a string, or a sequence of program arguments. Providing a
sequence of arguments is generally preferred, as it allows the module to take care of any required escaping
and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must
be True (see below) or else the string must simply name the program to be executed without specifying any
arguments.
stdin, stdout and stderr specify the executed program’s standard input, standard output and standard
error file handles, respectively. Valid values are PIPE, an existing file descriptor (a positive integer), an
existing file object, and None. PIPE indicates that a new pipe to the child should be created. With the
default settings of None, no redirection will occur; the child’s file handles will be inherited from the parent.
Additionally, stderr can be STDOUT, which indicates that the stderr data from the child process should be
captured into the same file handle as for stdout.
Conclusion: Thus we have implement a program for printing a document on remote printer.
Questions:
1) What is meaning of remote printer?
2) What is subprocess?
3) Explain Subprocess.Popen().
Page 54
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page54
ASSIGNMENT No.B 17
TITLE: Generate sine wave of programmable frequency
PROBLEM STATEMENT:
Write a C++/ Python program to generate a Sine wave of Programmable frequency and capture samples at programmable frequency (Max up as per Nyquist Sampling Theorem) and reconstruct the Sign wave using collected Samples using ARM Cortex A5/A9. Use oscilloscope to calculate signal frequency. Write your observations. Store a Data file in SAN (BIGDATA)
OBJECTIVE:
1. To learn the basic concept of sampling.
2. To learn the nyquist sampling criteria.
3. To generate sine wave and observe its sampling frequency and then reconstruct sine wave
using collected samples.
PART-1 Write a C++/ Python program to generate a Sign wave of Programmable frequency and capture samples at programmable frequency. PART-2 Reconstruct the Sign wave using collected Samples using ARM Cortex A5/A9. Use oscilloscope to calculate signal frequency. Write your observations.
Prerequisite:
Software: turbo c/c++, mini com.
Hardware: ARM cortex A5/A9, oscilloscope
THEORY: The simplest method to generate Sine wave is to use Trigonometric Sin function. The Sin function will generate the samples from our specific parameter like sampling frequency, number of samples, input frequency. In this project, generating the correct sample is important. The library function "sin ()" does all of the work. It’s most basic form as a function of time (t) is:
Page 55
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page55
y (t)=A.sinωt
Where:
A, the amplitude ω, the angular frequency, specifies how many oscillations occur in a unit time interval, in radians per second. φ, the phase, specifies where in its cycle the oscillation begins at t = 0.
The definition of proper sampling is quite simple. Suppose you sample a continuous signal in some manner. If you can exactly reconstruct the analog signal from the samples, you must have done the sampling properly. Even if the sampled data appears confusing or incomplete, the key information has been captured if you can reverse the process.
Figure shows several sinusoids before and after digitization. The continuous line represents the analog signal entering the ADC, while the square markers are the digital signal leaving the ADC. In (a), the analog signal is a constant DC value, a cosine wave of zero frequency. Since the analog signal is a series of straight lines between each of the samples, all of the information needed to reconstruct the analog signal is contained in the digital data. According to our definition, this is proper sampling.
The sine wave shown in (b) has a frequency of 0.09 of the sampling rate. This might represent, for example, a 90 cycle/second sine wave being sampled at 1000 samples/second. Expressed in another way, there are 11.1 samples taken over each complete cycle of the sinusoid. This situation is more complicated than the previous case, because the analog signal cannot be reconstructed by simply drawing straight lines between the data points. Do these samples properly represent the analog signal? The answer is yes, because no other sinusoid, or combination of sinusoids, will produce this pattern of samples (within the reasonable constraints listed below). These samples correspond to only one analog signal, and therefore the analog signal can be exactly reconstructed. Again, an instance of proper sampling.
In (c), the situation is made more difficult by increasing the sine wave's frequency to 0.31 of the sampling rate. This results in only 3.2 samples per sine wave cycle. Here the samples are so sparse that they don't even appear to follow the general trend of the analog signal. Do these samples properly represent the analog waveform? Again, the answer is yes, and for exactly the same reason. The samples are a unique representation of the analog signal. All of the information needed to reconstruct the continuous waveform is contained in the digital data. How you go about doing this will be discussed later in this chapter. Obviously, it must be more sophisticated than just drawing straight lines between the data points. As strange as it seems, this is proper sampling according to our definition.
In (d), the analog frequency is pushed even higher to 0.95 of the sampling rate, with a mere 1.05 samples per sine wave cycle. Do these samples properly represent the data? No, they don't! The samples represent a different sine wave from the one contained in the analog signal. In particular, the original sine wave of 0.95 frequencies misrepresents itself as a sine wave of 0.05 frequency in the digital signal. This phenomenon of sinusoids changing frequency during sampling is called
Page 56
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page56
aliasing. Just as a criminal might take on an assumed name or identity (an alias), the sinusoid assumes another frequency that is not its own. Since the digital data is no longer uniquely related to a particular analog signal, an unambiguous reconstruction is impossible. There is nothing in the sampled data to suggest that the original analog signal had a frequency of 0.95 rather than 0.05. The sine wave has hidden its true identity completely; the perfect crime has been committed! According to our definition, this is an example of improper sampling.
a) The analog signal is a constant DC value b) frequency of 0.09 of the sampling rate
c) The sine wave's frequency to 0.31 of the sampling rate d) The sine wave's frequency to 0.91 of the sampling rate
Nyquist criteria is the minimum sampling rate required to avoid aliasing, where aliasing is the distortion that results in the signal when reconstructed from samples is different from the original continuous time signal. Given by fs >= 2*f
Page 57
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page57
Part-I
Program to generate a Sign wave of Programmable frequency and capture samples at programmable frequency
Input:-
1. Amplitude(a)
2. Frequency (f) 3. Sampling frequency (fs)
Observation:-
Sr. Amplitude(a) Signal Frequency(f) Sample Frequency(fs) Samples(n)
No.
1 5V 100Hz 200Hz ?
2
3
3
4
5
Output: - Sine wave with its samples (n).
Page 58
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page58
Part-II
Reconstruct the Sign wave using collected Samples using ARM Cortex A5/A9. Use oscilloscope to calculate signal frequency. Write your observations.
Fig.2 Block diagram user interface, ARM Cortex A5/A9 & oscilloscope for to
reconstruct sine wave. Conclusion: Hence we have studied generation of Sine Wave and Cosine Wave
FAQ:-
3) Explain aliasing effect and Sampling theorem in detail.
4) State classification of signals.
5) Explain A/D and D/A converter with block diagram and State advantages of Digital
Signal processing.
Page 59
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page59
ASSIGNMENT No.B 18
TITLE: Generate SQUARE wave of programmable frequency PROBLEM STATEMENT:
Write a C++/ Python program to generate a Square wave of programmable frequency. Write a
function to generate Pole-Zero Diagram using multicore programming.
OBJECTIVE:
1. To learn the basic concept to generate a Square wave.
2. To learn the concept of Pole zero Diagram.
3. To generate sine wave and observe its sampling frequency and then Draw pole zero plot.
Prerequisite:
Software: turbo c/c++
THEORY:
PART-1
Square Wave Generation
A square wave is a non-sinusoidal periodic waveform (which can be represented as an
infinite summation of sinusoidal waves), in which the amplitude alternates at a steady frequency
between fixed minimum and maximum values, with the same duration at minimum and maximum.
Square waves are often encountered in electronics and signal processing. Square waves are
universally encountered in digital switching circuits and are naturally generated by binary (two-
level) logic devices. They are used as timing references or "clock signals", because their fast
transitions are suitable for triggering synchronous logic circuits at precisely determined intervals.
A square wave having amplitude 'a' is represented as follows:
Page 60
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page60
If the sampling frequency is '𝑓𝑠 ', then for a wave of amplitude 'a' the number of samples is given
by 2a/𝑓𝑠.
Algorithm:
Step 1: Enter frequency F and Sampling Frequency Fs.
Step 2:
k=0;
do
{
for(n=(k*Fs)/(2*F);n<((k+1)*Fs)/(2*F);n++)
{ // positive half cycle of square wave
x[n]=A;
Page 61
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page61
if(n>MAX)break;
}
for(n=((k+1)*Fs)/(2*F);n<((k+2)*Fs)/(2*F);n++)
{ // negative half cycle of square wave
x[n] = -A;
if(n>MAX) break;
}
k = k+2; // this count is modified for next cycle
} while(n<MAX);
break;
Step 3: Plotting this wave by using Graphics function.
PART-2
Generation of Pole-Zero Diagram
THEORY:
Consider a LTI system with input X(n) and output Y(n).
In terms of z-Transform we can define system transfer function H(z) as the ratio of o/p & i/p
H(Z) = Y(Z)/X(Z)
We can express z-Transform as the ratio of 2 polynomials called as rational z-transform.
X(Z ) = N(Z)/D(Z)
= b0 + b1Z -1 + b2Z -2 + -------- + bnZ-n
a0 + a1Z-1 + a2
-2 + -------- + anZ-n
Poles are the values of Z for which X(Z) is infinity.
Zeros are the values of Z for which X(Z) is 0.
Page 62
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page62
The equation can be written as,
m
X(Z)= ∑ bkZ-k
K=0
n
∑ akZ-k
K=0
Rearranging the equation,
X(Z) = Z-mb0 [Zm + b1/b0 (Z
m-1) + ……………… +bm/b0]
Z-nb0 [Zn + b1/b0 (Z
n-1) + ……………… +bn/b0]
Where Z1, Z2 ………………. Zm are zeros.
&b1, b2 …………….... bn are poles.
EXAMPLE:
Determine pole-zero plot for the system.
X(Z) = 1 + 3Z-1
1 + 3Z-1 + 2Z-2
Multiply ÷ by Z^2.
Therefore,
X(Z) = Z2 + 3Z
Z2 + 3Z + 2
= Z(Z + 3)
(Z + 1)(Z + 2)
Here, X(Z) is 0 for Z=0 & Z=-3.
X(Z) is ∞ for Z=-1,-2.
Therefore,
Poles = -1,-2.
Zeros = 0,-3.
Page 63
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page63
Conclusion: Hence pole zero plot and square wave generated . FAQ:-
6) Define system function H (z).Obtain it from Nth order difference equation and express it
for all pole and all zero system.
7) How the system function H(z) describes the properties of DT system? What is pole zero
plot.
8) Draw the pole zero plot for a system described as:
y(n)=x(n)-x(n-1)+3y(n-1)-2y(n-2)
Page 64
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page64
Assignment No: 19B
Title: To capture a signal and perform various operations for analyzing it.
Aim: Write a C++/ Python program to capture signal using ARM Cortex A5/A9/M4
ADC and signal generator, generate/construct a Square/Sine wave of programmable frequency and
voltage Draw Voltage (y-axis) and Time (x-axis) graph. Write a function to emulate simple RC
filter with R being Trim-pot(GUI meter) of 10K and C = 0.1 microFarad. Write a program to
generate a Voltage-Time response curve with reference to change in R. Draw the resultant outcome
graph. Store the data in SAN (BIGDATA)
Objective: To generate a square/sine wave of programmable frequency and emulate a RC filter
and understanding the response curves.
Theory:
ARM
Conceptually the Cortex-M4 is a Cortex-M3 plus DSP Instructions, and optional floating-point
unit (FPU). If a core contains an FPU, it is known as a Cortex-M4F, otherwise it is a Cortex-M4.
Key features of the Cortex-M4 core are:
ARMv7E-M architecture
Instruction sets
o Thumb (entire)
o Thumb-2 (entire)
o 1-cycle 32-bit hardware multiply, 2-12 cycle 32-bit hardware divide, saturated math
support
o DSP extension: Single cycle 16/32-bit MAC, single cycle dual 16-bit MAC, 8/16-
bit SIMD arithmetic
3-stage pipeline with branch speculation
1 to 240 physical interrupts, plus NMI
12 cycle interrupt latency
Integrated sleep modes
Silicon options:
Page 65
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page65
Optional Floating-Point Unit (FPU): single-precision only IEEE-754 compliant. This is
called the FPv4-SP extension.
Optional Memory Protection Unit (MPU): 0 or 8 regions
Chips
The following microcontrollers are based on the Cortex-M4 core:
Atmel SAM4L, SAM4N, SAM4S
Freescale Kinetis K
The following microcontrollers are based on the Cortex-M4F (M4 + FPU) core:
Atmel SAM4C (dual core), SAM4E, SAMG
Energy Micro EFM32 Wonder
Freescale Kinetis K
Infineon XMC4000
NXP LPC4000, LPC4300(one Cortex-M4F + one Cortex-M0)
STMicroelectronics STM32 F3, F4
Texas Instruments LM4F, TM4C
Spansion FM4F
Toshiba TX04
The following chips have either a Cortex-M4 or M4F as a secondary core:
Freescale Vybrid VF6 (one Cortex-A5 + one Cortex-M4F)
Texas Instruments OMAP 5 (one dual-core Cortex-A15 + two Cortex-M4)
Square waveA square wave is a non-sinusoidal periodic waveform (which can be represented as
an infinite summation of sinusoidal waves), in which the amplitude alternates at a steady frequency
between fixed minimum and maximum values, with the same duration at minimum and maximum.
The transition between minimum to maximum is instantaneous for an ideal square wave; this is
Page 66
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page66
not realizable in physical systems. Square waves are often encountered in electronics and signal
processing. Its stochastic counterpart is a two-state trajectory. A similar but not necessarily
symmetrical wave, with arbitrary durations at minimum and maximum, is called a rectangular
wave (of which the square wave is a special case).
Square waves are universally encountered in digital switching circuits and are naturally generated
by binary (two-level) logic devices. They are used as timing references or "clock signals", because
their fast transitions are suitable for triggering synchronous logic circuits at precisely determined
intervals. However, as the frequency-domain graph shows, square waves contain a wide range of
harmonics; these can generate electromagnetic radiation or pulses of current that interfere with
other nearby circuits, causing noise or errors. To avoid this problem in very sensitive circuits such
as precision analog-to-digital converters, sine waves are used instead of square waves as timing
references.
In musical terms, they are often described as sounding hollow, and are therefore used as the basis
for wind instrument sounds created using subtractive synthesis. Additionally, the distortion effect
used on electric guitars clips the outermost regions of the waveform, causing it to increasingly
resemble a square wave as more distortion is applied.
The sine wave or sinusoid is a mathematical curve that describes a smooth repetitive oscillation.
It is named after the function sine, of which it is the graph. It occurs often in pure and applied
mathematics, as well as physics, engineering, signal processing and many other fields. Its most
basic form as a function of time (t) is:
The sine wave is important in physics because it retains its wave shape when added to another sine
wave of the same frequency and arbitrary phase and magnitude. It is the only periodic waveform
that has this property. This property leads to its importance in Fourier analysis and makes it
acoustically unique.
Page 67
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page67
A storage area network (SAN) is a dedicated network that provides access to consolidated, block
level data storage. SANs are primarily used to enhance storage devices, such as disk arrays, tape
libraries, and optical jukeboxes, accessible to servers so that the devices appear like locally
attached devices to the operating system. A SAN typically has its own network of storage devices
that are generally not accessible through the local area network (LAN) by other devices. The cost
and complexity of SANs dropped in the early 2000s to levels allowing wider adoption across both
enterprise and small to medium sized business environments.
A SAN does not provide file abstraction, only block-level operations. However, file systems built
on top of SANs do provide file-level access, and are known as SAN filesystems or shared disk file
systems.
Sharing storage usually simplifies storage administration and adds flexibility since cables and
storage devices do not have to be physically moved to shift storage from one server to another.
Other benefits include the ability to allow servers to boot from the SAN itself. This allows for a
quick and easy replacement of faulty servers since the SAN can be reconfigured so that a
replacement server can use the LUN of the faulty server. While this area of technology is still new,
many view it as being the future of the enterprise datacenter.
SANs also tend to enable more effective disaster recovery processes. A SAN could span a distant
location containing a secondary storage array. This enables storage replication either implemented
by disk array controllers, by server software, or by specialized SAN devices. Since IP WANs are
often the least costly method of long-distance transport, the Fibre Channel over IP (FCIP) and
iSCSI protocols have been developed to allow SAN extension over IP networks. The traditional
physical SCSI layer could only support a few meters of distance - not nearly enough to ensure
business continuance in a disaster.
The economic consolidation of disk arrays has accelerated the advancement of several features
including I/O caching, snap shotting, and volume cloning (Business Continuance Volumes or
BCVs).
Page 68
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page68
Fig: VT curve before RC filter Fig: VT curve after RC filte
Page 69
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page69
Conclusion:
Hence we have observed voltage to time response curve with respect to resistor.
FAQ:-
9) Discuss the form of an Nth order difference equation used to describe a DT system. How
can it be expressed as an FIR and IIR system?
10) What are filter structures? Explain how the Direct and cascade form of FIR filters are
obtained and realized from the system function H(z).
11) Derive the Direct form II IIR filter structure from system function H(z) and represent it
using multipliers, adders and delay elements.
Page 70
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page70
Assignment No: C5
Title: Installation and setup to control the remote machine.
Aim: Install setup and access remote machine.
Prerequisites:
Student should know about remote machine
Objective: To install, setup and access remote machine by using Remote Desktop Connection
windows XP.
Theory:
Connect to another computer using Remote Desktop Connection Windows XP:
With Remote Desktop Connection, you can connect to a computer running Windows from another
computer running Windows that's connected to the same network or to the Internet. For example,
you can use all of your work computer's programs, files, and network resources from your home
computer, and it's just like you're sitting in front of your computer at work.
To connect to a remote computer, that computer must be turned on, it must have a network
connection, Remote Desktop must be enabled, you must have network access to the remote
computer (this could be through the Internet), and you must have permission to connect. For
permission to connect, you must be on the list of users. Before you start a connection, it's a good
idea to look up the name of the computer you're connecting to and to make sure Remote Desktop
connections are allowed through its firewall.
If you're user account doesn't require a password to sign in, you'll need to add a password before
you're allowed to start a connection with a remote computer.
Step 1:
Page 71
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page71
Secondly, you need to make sure that you are logged in as a computer administrator on the machine
in order to set it up for remote access. If you brought a computer from a store or got it straight
from the manufacturer, the first user name you create is always an Administrator account.
An easy way to check whether or not you are an Administrator is to go to Start, Control Panel and
then click on User Accounts. You’ll see your user name and it should have “Administrators” or
“Computer Administrator” written next to it.
Step:2
Thirdly, the administrator account on your machine must have a password. If you do not have to
type in a password in order to access Windows when you start up your computer, then you do not
have a password set up and Remote Desktop will not work. Remote desktop does not allow you to
connect to a computer with a user account that does not have a password.
When you go to User Accounts and click on the Administrator account, you will see an option to
create a password for the account. Go ahead and do that before moving on.
Page 72
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page72
Step:3
Next, if the computer you are connecting to is running Windows XP SP3, then you need to open the
firewall to allow remote desktop connections. To do this, go to Start, Control Panel, Windows
Firewall and click on the Exceptions tab.
Step:4
Make sure that the Remote Desktop check box is checked. The last thing that needs to be done in
order for Remote Desktop to work correctly is to tell Windows that we want to allow users to connect
remotely. So far we’ve just fulfilled the requirements, but now we have to actually allow remote
desktop connections to this computer.
Page 73
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page73
Go to Start, Control Panel, and click on System. Click on the Remote tab and make sure that the
“Allows users to connect remotely to this computer” box is checked. Don’t worry about clicking the
Select Remote Users button because Administrators have access by default. If you want to give an
non-administrator account remote desktop access, then click that button and add the user.
Step:5
And that’s it! Your computer is now setup for remote desktop! First try connecting to the XP machine
from another computer on your home network. In order to connect, go to the other computer and
click on Start, All programs, Accessories, Communications, and Remote Desktop Connection. If you
want to connect to the XP machine from Windows Vista, Windows 7 or Windows 8, just click on
Start and perform a search for remote desktop connection.
Page 74
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page74
Step:6
In the dialog box, you can type in the IP address or the name of the computer. The best way to connect
is to type in the IP address of the computer. In order to get the IP address of the computer you want
to connect to, go to the computer and click on Start, Run and type in CMD.
Page 75
Programming Lab IV Class/Branch:TE(comp)
Department of Computer Engineering ZES’s ZCOER, Pune-411041 Page75
Step:7
Using “ipconfig” command in cmd you can find IP ADDRESS of your machine.
Step:8
Click Connect and you should get a login screen pop up, which means you have successfully connected
to the other computer. You can now enter the Computer Administrator user name and password.
If you get an error saying that computer cannot accept new connections, etc. that means something
was not configured correctly. Remember you need to give the administrator account a password,
open the port in the firewall, and check the allow remote connections check box in the System
properties. All three items need to be performed on computer you want to connect TO.
Once you are able to connect from within the same network, now you can try to connect from outside.
So if you want to connect to your home computer from the office, you can do that, but you’ll have to
do a few extra things.
Conclusion: Thus we have install, configure and connect to a machine by remotely.
Questions:
4) What is mean by remote access machine?
5) What are steps used to connect remotely?
6) List of the software/tools which are used for remote connection?