Search This Blog

Thursday, August 17, 2023

DBMS Lab Cycle

Experiment -1
  1. Create an Employee table for the following fields

(Empno, Empname, Empaddress, salary, dept)

  1. Calculate the total of the salary field

  2. List the count of employees who have salary less than 50000

  3. Find the details of employee having maximum salary

  4. Add a new field title to the emplyee table with a default value as junior software engineer

  5. Update the title of employee whose employee number 2004 to "Senor software engineer"

  6. Delete the employee record of employee whose emplyee number is 2005


TEST CASE


mysql> select * from employee;

+-------+---------+------------+--------+--------------+

| empNo | empName | empAddress | salary | dept         |

+-------+---------+------------+--------+--------------+

|  2001 | Hari    | Palakkad   |  30000 | Reasearch    |

|  2002 | Devi    | Kasaragod  |  40000 | Network      |

|  2003 | Gupta   | Kannur     |  50000 | System Admin |

|  2004 | Ravi    | Calicut    |  60000 | HR           |

|  2005 | Rani    | Calicut    |  70000 | HR           |

+-------+---------+------------+--------+--------------+

5 rows in set (0.00 sec)


Experiment -2

  1. Create Student table for the following fields:

(studentNo, studentName, maths, physics, chemistry, cProgramming, department, address)


  1. List the studentno and studentname who is having marks less than 50 in C-programming in ascending order of their marks.
  2. List the studentno, studentname and department, in descending order of their department and ascending order of their name.
  3. List the name of students whose name starts with ‘S’.

  4. Find the name of student who obtained second largest mark in in C-programming.

  5. List the number of students in each department along with their average mark in maths.

  6. List the number of students who have secured marks between 70 and 80 in physics.





mysql> select * from student;

+-----------+-------------+-------+---------+-----------+--------------+------------+-----------+

| studentNo | studentName | maths | physics | chemistry | cProgramming | department |     

address   |

+-----------+-------------+-------+---------+-----------+--------------+------------+-----------+

|       100 | Hari        |    50 |      60 |        45 |           75 | CSE        | Kasaragod |

|       101 | Devi        |    60 |      55 |        78 |           40 | CSE        | Kasaragod |

|       102 | Sam         |    45 |      77 |        88 |           45 | IT         | Kannur    |

|       103 | SreeHari    |    90 |      75 |        77 |           60 | IT         | Calicut   |

|       104 | Rani        |    91 |      98 |        89 |           52 | ECE        | Kannur    |

|       105 | Raj         |    88 |      77 |        67 |           48 | CSE        | Palakkad  |

+-----------+-------------+-------+---------+-----------+--------------+------------+-----------+

6 rows in set (0.00 sec)


 

 
 
Create a table file_server(user_id,file_name,create_date). First two attributes are part of the primary key.
  1. List all unique extensions of the files in the file server.
  2. Write the SQL Query to display the user ids, file extensions and count of files in each extensions.
  3. Identify all files created after seven days or before seven days from 15-Aug-2024;

mysql> select * from file_server;
+---------+--------------+-------------+
| user_id | file_name    | create_date |
+---------+--------------+-------------+
|       1 | debug.txt    | 2024-06-01  |
|       1 | exp.txt        | 2024-07-01  |
|       1 | string.java  | 2024-07-10  |
|       2 | add.c          | 2024-08-01  |
|       2 | sub.asm      | 2024-08-09  |
|       2 | sub2.Asm    | 2024-08-14  |
|       3 | even.c       | 2024-08-18  |
|       3 | fibonacci.c  | 2024-08-12  |
|       3 | Hello.txt    | 2024-08-27  |
|       3 | traffic.java | 2024-08-09  |
|       4 | EMP.TXT      | 2024-08-21  |
|       4 | employee.txt | 2024-08-19  |
+---------+--------------+-------------+

Experiment-7

Question Link:


Experiment-8

Question Link: 

 

Experiment-9

Thursday, January 5, 2023

Network Lab Pgms


Pgm -1

TCP - Server Pgm

TCP - Client Pgm

TCP - Algorithm


Pgm -2

UDP - Server Pgm

UDP - Client Pgm


Pgm -3

Implement Link State Routing algorithm.

Sample-Output


Pgm - 4

Implement leaky bucket algorithm for congestion control.

Sample-Output 


Pgm - 5 (FTP)

Develop a file server which will provide the file requested by a client if it

exists. If not, the server sends appropriate message to the client. Server should also

send its process ID (PID) to clients for display along with the file or the message.

Sample-Output


Pgm - 6 

Implement Selective Repeat ARQ flow control protocol using UDP.

Sample-Output

 

Pgm - 7

Implement a Concurrent Server application to perform sorting using TCP to execute the program at a remote server. Client sends an array and its size to the server (using a structure variable), server sort the array and send back the result to the client. Client displays the result.

TCP - Server - Fork

TCP - Client

 

Pgm - 8

Sample Concurrent Server application using UDP.

UDP - Server - Fork

UDP - Client

 

 


 

Friday, December 9, 2022

Install MySQL on Ubuntu (22.04)

 

Follow the below commands to install MySQL on ubuntu 22.04 

For more details refer: https://linuxhint.com/install-mysql-on-ubuntu-22-04/

sudo apt update
sudo apt install mysql-server
systemctl is-active mysql
sudo pkill -f mysql_secure_installation
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Root@123';

exit
sudo mysql_secure_installation
 mysql -u root -p

Wednesday, November 30, 2022

DBMS Lab Cycle 8

 

 8. Implement a banking environment with following tables, procedures and function.

bank_customer(cust_id,cust_name,email)

cust_id is the primary key and it must be auto generated by the databse system.

account(acc_no,acc_type,cust_id,balance)

acc_no is the primary key and cust_id is foreign key.

The account_type field will accept ONLY two values saving and current. 


if the account type is saving then the minimum balance should be RS.1000 however there is no minimum balance condition for the current account.

 

1. Import DATA of account table from a csv file. [Download CSV]


mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | OFF   |
+---------------+-------+
1 row in set (0.90 sec)

mysql> SET GLOBAL local_infile=1;
Query OK, 0 rows affected (0.05 sec)

mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | ON    |
+---------------+-------+
1 row in set (0.01 sec)

mysql> quit

mysql> mysql --local-infile=1 -u root -p

mysql> use DBNAME;

mysql> LOAD DATA LOCAL INFILE '/file_name.csv' INTO TABLE table_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;


2. create a function getBalance(acc_no) to get the balance details of a bank account.

 

3. create two procedures

    credit(acc_no,amount)

    debit(acc_no,amount)

Display appropriate messages of every operations and errors.

 

4. Use curosr and create a procedure to list all email ids of customer separated by semicolon;

(Refer: https://www.mysqltutorial.org/mysql-cursor/)

account

acc_no acc_type     cust_id balance

1001 saving 1 10000

1002 saving 2 20000

1003 saving 3 30000

2001 current 4 10000

2002 current 5 20000



bank_customer

cust_id cust_name email

1 hari hari@gmail.com

2 sam sam@gmail.com

3 sree sree@lbscek.ac.in

4 ali ali@lbscek.ac.in

5 john john@yahoo.co.in

select * from account;

select getBalance(1001) as currentBalance;

call credit(1001,2000); 12000

call credit(1004,1000); ERROR

call debit(1001,1000); 11000

call debit(1004,1000); ERROR

call debit(1001,10500); ERROR

call debit(1001,10000); 1000

call debit(2001,10000); 0

select getBalance(2001) as currentBalance;

select * from account;


Function and Procedures

 


===============================================

DELIMITER //

CREATE PROCEDURE GetNameByID(IN employeeId int(4))

BEGIN

SELECT * FROM employee WHERE empNo = employeeId;

END //

DELIMITER ;

call GetNameByID(2001);

===============================================

DELIMITER //

CREATE PROCEDURE CountByDept(IN deptName VARCHAR(25), OUT total INT)

BEGIN

SELECT count(empNo) INTO total FROM employee WHERE dept = deptName;

END //

DELIMITER ;

call CountByDept('HR',@total);

select @total;

===============================================

DELIMITER //

CREATE PROCEDURE set_counter(INOUT count INT(4),IN inc INT(4))

BEGIN

SET count = count + inc;

END //

DELIMITER ;

SET @counter = 1;

CALL set_counter(@counter,1); -- 2

CALL set_counter(@counter,1); -- 3

CALL set_counter(@counter,5); -- 8

SELECT @counter; -- 8

===============================================

DROP FUNCTION IF EXISTS countByDeptFn;

DELIMITER //

CREATE FUNCTION countByDeptFn(deptName VARCHAR(25)) RETURNS int DETERMINISTIC

BEGIN

DECLARE total INT;

SELECT count(empNo) into total FROM employee WHERE dept = deptName;

RETURN total;

END //

DELIMITER ;

select countByDeptFn('HR') as EmpCount;

Friday, November 18, 2022

DBMS Lab Cycle 7

 

  7. Create tables based on the following schema

Item(item_id,item_desc,qty_on_hand,unit_price,category);

Sales(sale_id,item_id,qty_sold, unit_price, total_price, tax_amount,grand_total);


item_id is primary key in Item table and item_id is foreign key in Sales table.

sale_id is primary key in Sales table.

    i. Create trigger for calculating total_price, tax_amount and grand_total in sales table while inserting values.

The tax rate of vaious category as shown below.

book (10%)

stationery (20%)

chocolate (30%)

other (5%)

    ii. Create a trigger to calculate the stock of an Item after sales of an Item.



select * from Item;

+---------+-----------+-------------+------------+------------+

| item_id | item_desc | qty_on_hand | unit_price | category   |

+---------+-----------+-------------+------------+------------+

|     100 | TextBook  |          20 |         20 | book       |

|     101 | milkybar  |          30 |          5 | chocolate  |

|     102 | apple     |          50 |         10 | fruit      |

|     103 | pen       |         100 |          8 | stationery |

+---------+-----------+-------------+------------+------------+

4 rows in set (0.00 sec)


insert into Sales(sale_id,item_id,qty_sold) values(200,100,10);

insert into Sales(sale_id,item_id,qty_sold) values(201,101,25);

insert into Sales(sale_id,item_id,qty_sold) values(202,102,10);

insert into Sales(sale_id,item_id,qty_sold) values(203,103,20);


 select * from Sales;

+---------+---------+----------+------------+-------------+------------+-------------+

| sale_id | item_id | qty_sold | unit_price | total_price | tax_amount | grand_total |

+---------+---------+----------+------------+-------------+------------+-------------+

|     200 |     100 |       10 |         20 |         200 |         20 |         220 |

|     201 |     101 |       25 |          5 |         125 |         38 |         163 |

|     202 |     102 |       10 |         10 |         100 |          5 |         105 |

|     203 |     103 |       20 |          8 |         160 |         32 |         192 |

+---------+---------+----------+------------+-------------+------------+-------------+

4 rows in set (0.00 sec)


select * from Item;

+---------+-----------+-------------+------------+------------+

| item_id | item_desc | qty_on_hand | unit_price | category   |

+---------+-----------+-------------+------------+------------+

|     100 | TextBook  |          10 |         20 | book       |

|     101 | milkybar  |           5 |          5 | chocolate  |

|     102 | apple     |          40 |         10 | fruit      |

|     103 | pen       |          80 |          8 | stationery |

+---------+-----------+-------------+------------+------------+

4 rows in set (0.00 sec)

Trigger

Trigger

========================Insert =========================

mysql> create table table1(

-> var1 int(3) NOT NULL,

-> var2 int(3) NOT NULL,

-> sum int(3) NULL

-> );

Query OK, 0 rows affected (0.52 sec)

mysql>

mysql> Create trigger updateSumTable1

-> Before insert

-> On table1

-> For each row

-> Set new.sum=new.var1+new.var2;

Query OK, 0 rows affected (0.08 sec)

mysql>

mysql> insert into table1 values(3,6,null);

Query OK, 1 row affected (0.08 sec)

mysql> select * from table1;

+------+------+------+

| var1 | var2 | sum |

+------+------+------+

| 3 | 6 | 9 |

+------+------+------+

1 row in set (0.10 sec)


========================Delete=========================


mysql> create table table2(

-> var1 int(3) NOT NULL,

-> var2 int(3) NOT NULL,

-> sum int(3) NULL

-> );

Query OK, 0 rows affected (0.52 sec)


mysql> Create trigger updateTable2

-> After delete-> On table1

-> For each row

-> insert into table2 values(old.var1,old.var2,old.sum);

Query OK, 0 rows affected (0.09 sec)

mysql>


mysql> select * from table2;

Empty set (0.00 sec)

mysql>

mysql> delete from table1 where var1=3;

Query OK, 1 row affected (0.11 sec)

mysql> select * from table1;

Empty set (0.00 sec)

mysql> select * from table2;

+------+------+------+

| var1 | var2 | sum |

+------+------+------+

| 3 | 6 | 9 |

+------+------+------+

1 row in set (0.00 sec)

========================UPDATE=========================

mysql> create table table3(

-> var int NOT NULL,

-> sum int NULL

-> );

Query OK, 0 rows affected (0.44 sec)

mysql> DELIMITER //

mysql> Create trigger updateSumTable3

-> Before update

-> On table3

-> For each row

-> begin

-> if(new.var>old.var) then

-> Set new.sum=old.sum+new.var;

-> end if;

-> END //

Query OK, 0 rows affected (0.13 sec)

mysql> DELIMITER ;

mysql> insert into table3 values(3,3);Query OK, 1 row affected (0.12 sec)

mysql> select * from table3;

+-----+------+

| var | sum |

+-----+------+

| 3 | 3 |

+-----+------+

1 row in set (0.00 sec)

mysql> update table3 set var=5 where var=3;

Query OK, 1 row affected (0.18 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from table3;

+-----+------+

| var | sum |

+-----+------+

| 5 | 8 |

+-----+------+

1 row in set (0.00 sec)

mysql> update table3 set var=2 where var=5;

Query OK, 1 row affected (0.36 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from table3;

+-----+------+

| var | sum |

+-----+------+

| 2 | 8 |

+-----+------+

1 row in set (0.00 sec)

');




Monday, November 7, 2022

DBMS Lab Cycle 5

   5. The schema of book store database is as follows

customer (cust_id, cust_name, cust_phone)

book (book_id, title, auth_name, unit_price, pub_name, pub_year)

sale (sale_id, cust_id, book_id, order_date, quantity)

author(auth_name, country)

publisher(pub_name, pub_addr)


first attribute in each table is the primary key, foreign keys have same name as primary key.

i. Calculate the sales for a financial year 2021-22? 

ii. Display publisher wise total price of books published, except for a particular publisher PHI

iii. Write the SQL Query to Find the publisher wise total price of books published

iv. Write the SQL Query to display the name of the customer and title of the books purchased by them.

v.Find the title of books with author name and country published in year 2021;

vi. Get the titles and author name of all books written by authors not living in india.

vii.Write the SQL Query to display the cusomer ids and the total quantity of books purchased by them in the decreasing order of total quantity purcased.


TEST CASES

mysql> select * from customer;

+---------+-----------+------------+

| cust_id | cust_name | cust_phone |

+---------+-----------+------------+

|     100 | hari      |      12345 |

|     101 | john      |      23456 |

|     102 | ali       |      34567 |

+---------+-----------+------------+


mysql> select * from author;

+-----------+---------+

| auth_name | country |

+-----------+---------+

| Brown     | US      |

| Forouzan  | US      |

| Navathe   | India   |

| Samantha  | India   |

| Tanenbaum | US      |

| V Prasad  | India   |

+-----------+---------+


mysql> select * from publisher;

+----------+----------+

| pub_name | pub_addr |

+----------+----------+

| Pearson  | London   |

| PHI      | Delhi    |

| TMH      | UP       |

+----------+----------+

mysql> select * from book;

+---------+--------+-----------+------------+----------+----------+

| book_id | title  | auth_name | unit_price | pub_name | pub_year |

+---------+--------+-----------+------------+----------+----------+

|    2001 | DS     | Samantha  |        500 | PHI      |     2020 |

|    2002 | CP     | V Prasad  |        300 | TMH      |     2019 |

|    2003 | DBMS   | Navathe   |        900 | Pearson  |     2018 |

|    2004 | DC     | Forouzan  |        700 | TMH      |     2021 |

|    2005 | CN     | Tanenbaum |        800 | Pearson  |     2018 |

|    2006 | Python | Brown     |        800 | TMH      |     2021 |

+---------+--------+-----------+------------+----------+----------+


mysql> select * from sale;

+---------+---------+---------+------------+----------+

| sale_id | cust_id | book_id | order_date | quantity |

+---------+---------+---------+------------+----------+

|     301 |     100 |    2001 | 2021-01-02 |        3 |

|     302 |     100 |    2002 | 2019-04-02 |        4 |

|     303 |     100 |    2003 | 2019-04-02 |        2 |

|     304 |     101 |    2002 | 2021-05-02 |        2 |

|     305 |     101 |    2005 | 2021-05-02 |        1 |

|     306 |     102 |    2006 | 2022-01-02 |        2 |

+---------+---------+---------+------------+----------+

Wednesday, November 2, 2022

DBMS Lab Cycle 4

 Create view for following. 

i.            View (student_info) for student table(exp no:2) containing studentNo, studentName, department, address

ii.            View (student_mark) for student table(exp no:2) containing studentNo, studentName, maths, physics, chemistry, cProgramming.

iii.            Display the studentNo, studentName, totalMarks, address from student_info view and student_mark view without referring student table.  

iv.            Create a view (emp_dept) for exp no:3 containing employee name and department name. (NULL values are expected in the department name field for the employees having invalid department numbers).

  v.            Find the name of employees having invalid department numbers by referring the emp_dept view.

Friday, October 14, 2022

DBMS Lab Cycle 3

 3. Consider the following tables namely “Department” and “Employees”

Their schemas ar e as follows

dept (deptNO, deptName, deptLocation)

emp (empId, empName , deptNo, salary)

Where deptNo is the primary key in dept table and empId is primary key in emp table

Where deptNo in Employees is NOT a foreign key.

i. Display the employee name along with their department name (no need to display the

employees with invalid department details)

ii. There are some invalid department numbers (present in employee table but are not

existing in department table), display all employees (along employee name employee id

and their department number) who are part of such invalid department numbers .

iii. Display all the department numbers available with the department and employee tables

avoiding duplicates

iv. Display department numbers and name of all the departments where no employee exists.

v. Display department number, employee id and employee name of employees working at

location Cochin

vi. Display the details of those who draw the salary greater than the average salary of

employee’s from sales department

vii. The names of employees whose salary is greater than the salary of all the employees in

department 1003

viii. Give all employees in the 'Sales' department a 20% raise i n salary.

ix. Retrieve the ids of employees getting salary greater than the average
salary of their department.

x. For each department that has more than 1 employee, retrieve the
department-No and the number of employees getting salary more
than Rs. 40000.

 

TEST CASES

mysql> select * from emp;

+-------+---------+--------+--------+

| empId | empName | deptNo | salary |

+-------+---------+--------+--------+

|  2001 | Hari    |   1006 |  30000 |

|  2002 | Devi    |   1002 |  40000 |

|  2003 | Gupta  |   1003 |  50000 |

|  2004 | Ravi    |   1004 |  60000 |

|  2005 | Rani    |   1007 |  70000 |

|  2006 | John    |   1003 |  40000 |

+-------+---------+--------+--------+

6 rows in set (0.39 sec)

mysql> select * from dept;

+--------+-------------+--------------+

| deptNo | deptName    | deptLocation |

+--------+-------------+--------------+

|   1001 | HR                   | Calicut      |

|   1002 | Marketing        | Cochin       |

|   1003 | Sales                | Trivandrum   |

|   1004 | Testing             | Bangalore    |

|   1005 | Development   | Bangalore    |

+--------+-------------+--------------+

5 rows in set (0.01 sec)

Thursday, July 21, 2022

NS2 - Program 4

 #  TCP Variant Tahoe

# ========================

#

#     (0)tcp0,ftp0     (5)tcpSink0

# \   /

#   \2Mb /2Mb

# 2Mb    \   3Mbps /   2Mb

# (1)---------(3)---------------(4)------------(6)tcpSink1

#   tcp1,ftp1  / \

#   /2Mb \2Mb

# /   \

#    (2)tcp2,ftp2     (7)tcpSink2

#   

#

# [.001s]

#  tcp0 [1000b]----------> tcpsink0

# [.001s]

#  tcp1 [1000b]----------> tcpsink1

# [.001s]

#  tcp2 [1000b]----------> tcpsink2

#

#  All 10ms DropTail


set ns [new Simulator]

set f0 [open tahoe0.tr w]

set f1 [open tahoe1.tr w]

set f2 [open tahoe2.tr w]

set nr [open taho.tr w]

$ns trace-all $nr


set nf [open taho.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

global ns nr nf f0 f1 f2

$ns flush-trace

   #Close the NAM trace file

   close $nf

close $nr

close $f0

close $f1

close $f2

exec nam taho.nam &

exec xgraph tahoe0.tr tahoe1.tr tahoe2.tr -bg white -t ConjestionWindowAnalysis_Tahoe -x Seconds -y ConjestionWindowSize

   exit 0

}

#for{set i 0} {$i<12} {incr i}{

#set n($i) [$ns node]

#}

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]


#creating links

#for {set i 0} {$i<9}{incr i}{

#$ns duplex-link $n($i) $n([expr$i+1]) 1Mb 10ms DropTail

#} 

$ns duplex-link $n0 $n3 2Mb 10ms DropTail

$ns duplex-link $n1 $n3 2Mb 10ms DropTail

$ns duplex-link $n2 $n3 2Mb 10ms DropTail

$ns duplex-link $n3 $n4 3Mb 10ms DropTail

$ns duplex-link $n4 $n5 2Mb 10ms DropTail

$ns duplex-link $n4 $n6 2Mb 10ms DropTail

$ns duplex-link $n4 $n7 2Mb 10ms DropTail


$ns duplex-link-op $n0 $n3 orient right-up

$ns duplex-link-op $n1 $n3 orient middle

$ns duplex-link-op $n2 $n3 orient right-down

$ns duplex-link-op $n3 $n4 orient middle

$ns duplex-link-op $n4 $n5 orient right-up

$ns duplex-link-op $n4 $n6 orient middle

$ns duplex-link-op $n4 $n7 orient right-down



#create a tcp agent and attach it to nodes

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set packetSize_ 1000

$ftp0 set interval_ 0.001


set tcpsink0 [new Agent/TCPSink]

$ns attach-agent $n5 $tcpsink0

$ns connect $tcp0 $tcpsink0


set tcp1 [new Agent/TCP]

$ns attach-agent $n1 $tcp1

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 set packetSize_ 1000

$ftp1 set interval_ 0.001


set tcpsink1 [new Agent/TCPSink]

$ns attach-agent $n6 $tcpsink1

$ns connect $tcp1 $tcpsink1


set tcp2 [new Agent/TCP]

$ns attach-agent $n2 $tcp2

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

$ftp2 set packetSize_ 1000

$ftp2 set interval_ 0.001


set tcpsink2 [new Agent/TCPSink]

$ns attach-agent $n7 $tcpsink2

$ns connect $tcp2 $tcpsink2

#setting colour

$tcp0 set fid_ 1 #to set flow ID

$tcp1 set fid_ 2

$tcp2 set fid_ 3


#flow ID 1 --->RED

$ns color 1 Red

$ns color 2 Green

$ns color 3 Blue


proc record {} {

global ns tcp0 tcp1 tcp2 f0 f1 f2

set time 0.01

set wnd0 [$tcp0 set cwnd_]

set wnd1 [$tcp1 set cwnd_]

set wnd2 [$tcp2 set cwnd_]

set timenow [$ns now]

puts $f0 "$timenow $wnd0"

puts $f1 "$timenow $wnd1"

puts $f2 "$timenow $wnd2"

$ns at [expr $timenow + $time] "record"

}


$ns at 0.1 "record"

$ns at 0.5 "$ftp0 start"

$ns at 1.0 "$ftp1 start"

$ns at 1.5 "$ftp2 start"

$ns at 25.0 "$ftp0 stop"

$ns at 25.5 "$ftp1 stop"

$ns at 26.0 "$ftp2 stop"

$ns at 27.0 "finish"


$ns run

NS2 - Program 3

 #    pgm3DV.tcl 

#    (6)-------(5)null0,null1

#    /     /  \

#   /        /    \ 

# (7) (11) (4)

#     / / \   \

#    / / \    \

#   (8) (9) (10) (3)

#     \ /      \

#      \  /         \ (2)

#       \/        \ /

#     cbr0(0)------------(1)cbr1


# |Time| State | Nodes |

# |====| ===== | ===== |

# | 10 | Down  | 11-05 |

# | 13 | Down  | 07-06 |

# | 20 |  Up   | 07-06 |

# | 30 |  Up   | 11-05 |

# _______________________

# All 1Mb 10ms DropTail

#


set ns [new Simulator]

$ns rtproto DV

set nf [open trace1.tr w]

$ns trace-all $nf


set nm [open out1.nam w]

$ns namtrace-all $nm


#Define a 'finish' procedure

proc finish {} {

global ns nf nm

$ns flush-trace

#Close the NAM trace file

close $nf

close $nm

exec nam out1.nam 

exit 0

}

#for{set i 0} {$i<12} {incr i}{

#set n($i) [$ns node]

#}

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

set n8 [$ns node]

set n9 [$ns node]

set n10 [$ns node]

set n11 [$ns node]


#creating links

#for {set i 0} {$i<9}{incr i}{

#$ns duplex-link $n($i) $n([expr$i+1]) 1Mb 10ms DropTail

#} 

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 1Mb 10ms DropTail

$ns duplex-link $n3 $n4 1Mb 10ms DropTail

$ns duplex-link $n4 $n5 1Mb 10ms DropTail

$ns duplex-link $n5 $n6 1Mb 10ms DropTail

$ns duplex-link $n6 $n7 1Mb 10ms DropTail

$ns duplex-link $n7 $n8 1Mb 10ms DropTail

$ns duplex-link $n0 $n9 1Mb 10ms DropTail

$ns duplex-link $n10 $n11 1Mb 10ms DropTail

$ns duplex-link $n9 $n11 1Mb 10ms DropTail

$ns duplex-link $n1 $n10 1Mb 10ms DropTail

$ns duplex-link $n11 $n5 1Mb 10ms DropTail

$ns duplex-link $n8 $n0 1Mb 10ms DropTail


#create a udp agent and attach it to node n0

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1


#Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set interval_ 0.005

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 1000

$cbr1 set interval_ 0.005


#create a Null agent(a traffic sink) and attach it to node n1

set null0 [new Agent/Null]

$ns attach-agent $n5 $null0

set null1 [new Agent/Null]

$ns attach-agent $n5 $null1

#link statistics

$ns rtmodel-at 10.0 down $n11 $n5

$ns rtmodel-at 30.0 up $n11 $n5

$ns rtmodel-at 13.0 down $n7 $n6

$ns rtmodel-at 20.0 up $n7 $n6

#Connect the traffic source to the sink

$ns connect $udp0 $null0

$ns connect $udp1 $null1

$ns at 5.0 "$cbr0 start"

$ns at 5.0 "$cbr1 start"

$ns at 45.0 "$cbr0 stop"

$ns at 45.0 "$cbr1 stop"

$ns at 45.1 "finish"


$ns run


======countDV.awk

#!/usr/bin/awk -f

BEGIN{

send = 0

recv = 0

drop = 0

route = 0

#print" Count calculation in Distance Vector Algorithm"

}

{

if( $1=="+" && ($3=="1"||$3=="0") && $5=="cbr")

{

send+=1

}

if( $1=="r" && $4=="5" && $5=="cbr")

{

recv+=1

}

if( $1=="d" )

{

drop+=1

}

if( $1=="r" &&  $5=="rtProtoDV")

{

route+=1

}

}

END{

print "count of send packets"

print send

print "count of received packets"

print recv

print "count of dropped packets"

print drop

print "count of routed packets"

print route

print "Normalized Overhead"

print route/recv

print "Packet Delivery"

print recv/send

}

======

ns pgm3DV.tcl 
ns pgm3LS.tcl 
awk -f countDV.awk trace1.tr > DV.dat
awk -f countLS.awk trace2.tr > LS.dat

NS2 - Program 2

 


#  

# (0)tcp0,ftp0      (4)tcpSink0

# \       /

#   \ 1Mbps     / 2Mbps

#    \ 3Mbps    /

#    (2)----------------(3)

#    /    \

#   / 1Mbps     \ 2Mbps

# / \

# (1)udp0,cbr0      (5)null0

# [.005s]

#  udp0 [1000b]----------> null0

# [.005s]

#  tcp0 [1000b]----------> tcpsink0

#  All 10ms DropTail



set ns [new Simulator]

set nf [open trace.tr w]

$ns trace-all $nf


set nm [open out.nam w]

$ns namtrace-all $nm


#Define a 'finish' procedure

proc finish {} {

global ns nf nm

$ns flush-trace

#Close the NAM trace file

close $nf

close $nm

exec nam out.nam 

exit 0

}


set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]


#creating links

$ns duplex-link $n0 $n2 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 3Mb 10ms DropTail

$ns duplex-link $n3 $n4 2Mb 10ms DropTail

$ns duplex-link $n3 $n5 2Mb 10ms DropTail


#set up a tcp, connection

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set packetSize_ 1000

$ftp0 set interval_ 0.005


set tcpsink0 [new Agent/TCPSink]

$ns attach-agent $n4 $tcpsink0


#create a udp agent and attach it to node n1

set udp0 [new Agent/UDP]

$ns attach-agent $n1 $udp0


#Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set interval_ 0.005



#create a Null agent(a traffic sink) and attach it to node n1

set null0 [new Agent/Null]

$ns attach-agent $n5 $null0


#Connect the traffic source to the sink

$ns connect $udp0 $null0

$ns connect $tcp0 $tcpsink0


$ns at 1.0 "$ftp0 start"

$ns at 1.1 "$cbr0 start"

$ns at 4.5 "$ftp0 stop"

$ns at 4.5 "$cbr0 stop"

$ns at 5 "finish"


$ns run


====throTCP.awk

#!/usr/bin/awk -f

BEGIN{

data = 0

#print"throughput calculation"

}

{

if( $1=="r" && $4=="4" && $5=="tcp")

{

data+=$6

print $2,data*8.0/$2/1000000

}

}

END{

#print "completed"

}


=====throUDP.awk

#!/usr/bin/awk -f
BEGIN{
data=0
#print"throughput calculation"
}
{
if( $1=="r" && $4=="5" && $5=="cbr")
{
data+=$6
print $2,data*8.0/$2/1000000
}
}
END{
#print "completed"
}

======

ns pgm2.tcl
awk -f throTCP.awk trace.tr > tcp.dat
awk -f throUDP.awk trace.tr > udp.dat
xgraph tcp.dat udp.dat -bg white -t ThroughputAnalysis -x Throughput -y Seconds


NS2 - Program 1

 Click Here to download


Program 1:


# (0) tcp0, ftp0

# \

#   \ 2Mbps

#    \ 3Mbps

#    (2)----------------(3) tcpSink0,tcpSink1

#    /

#   / 1Mbps

# /

# (1) tcp1, ftp1

#  tcp0 --> tcpsink0

#  tcp1 --> tcpsink1

#  All 10ms DropTail

set ns [new Simulator]

set nf [open trace.tr w]

$ns trace-all $nf


set nm [open out.nam w]

$ns namtrace-all $nm


#Define a 'finish' procedure

proc finish {} {

global ns nf nm

$ns flush-trace

close $nf

close $nm

exit 0

}


set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]


#creating links

#$ns <link_type> $n0 $n1 <bandwidth> <delay> <queue­type>

$ns duplex-link $n0 $n2 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 3Mb 10ms DropTail


#set up a tcp, connection

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0


set tcp1 [new Agent/TCP]

$ns attach-agent $n1 $tcp1

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1


set tcpsink0 [new Agent/TCPSink]

$ns attach-agent $n3 $tcpsink0

set tcpsink1 [new Agent/TCPSink]

$ns attach-agent $n3 $tcpsink1


$ns connect $tcp0 $tcpsink0

$ns connect $tcp1 $tcpsink1


#Schedule an event: $ns at <time> <event>

$ns at 1.0 "$ftp0 start"

$ns at 1.1 "$ftp1 start"

$ns at 5.0 "$ftp0 stop"

$ns at 5.1 "$ftp1 stop"


$ns at 5.2 "finish"

$ns run



Saturday, November 7, 2020

Install MySQL on Ubuntu (18.04)

Type below commands in your terminals. 

First five commands are NOT required if you don't have any earlier version of mysql in your system. 

sudo apt-get remove --purge mysql*

sudo apt-get purge mysql*

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get remove dbconfig-mysql

sudo apt-get dist-upgrade

sudo apt-get install mysql-server


This will install mysql without prompting for a password.

Use the cat command to view the default password.

sudo cat /etc/mysql/debian.cnf

======= the sample output will be========

# Automatically generated for Debian scripts. DO NOT TOUCH!

[client]

host     = localhost

user     = debian-sys-maint

password = it3vqmn8mXIBBama

socket   = /var/run/mysqld/mysqld.sock

[mysql_upgrade]

host     = localhost

user     = debian-sys-maint

password = it3vqmn8mXIBBama

socket   = /var/run/mysqld/mysqld.sock

==================


mysql -udebian-sys-maint -p

Log in with the default password as given in above file. In this example password is it3vqmn8mXIBBama (copy and paste this password after above command)


You will enter into mysql teriminal.
Change password.  ( In this example i am setting the password to root for user root)

UPDATE mysql.user SET authentication_string=PASSWORD('root'), PLUGIN='mysql_native_password' WHERE USER='root';

Exit from the mysql terminal (type exit)

exit

Restart the service 
/etc/init.d/mysql restart

Try to login with user root  (Type the password as root)
mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.03 sec)

mysql> create database test;
Query OK, 1 row affected (0.41 sec)

mysql> use test;
Database changed
mysql> 

Try to perform some basic queries as given in this file.
(If you are a beginner in SQL)


Monday, January 16, 2017

KTU University Question Papers and Answers - Paper: BE 101-05 INTRODUCTION TO COMPUTING AND PROBLEM SOLVING (ICP)


ICP - Jan 2017 (Regular Exam)


Write a program that reads an integer N from the keyboard and then calls a user defined function to compute and displays the sum of N numbers from N to (2*N)if N is nonnegative. If N is negative, then displays the sum of the numbers from (2*N) to N. The starting and ending points are included in the sum.
Write a python program to find the sum of all odd terms in a group of n numbers enterd by the user.
Write a program to check if a string is a palindrome or not, whith out reversing the original string.
Write a program to find the quadrant of a given point(X,Y).
Write a python program to create a dictionary of phone numbers and names of five persons. Display the contents of the dictionary in alphabetical order of names .
Create a class person with attributes Name, age, salary and method display() for showing the details. Create two instances of the class and call the method for each instance.
Write a menu driven program to calculate area of circle, triangle, rectangle and square. Use a seperate function to implement each operation.
Write a python code to find transpose of a matrix using list.
Write a program to find the sum of first n positive integers using a recursive function.
Write a python program that opens a file for input and prints the count of four letter words in it.

ICP - January 2016 (Regular Exam)

Sign in with your google account and try to open with Python Editor v5

Write a python program to display all Armstrong numbers in a given range.
Differentiate between break and continue statements with proper examples.
Create a class Car with attributes Model, year and price and a method cost() for displaying price. Create two instance of the class and call the method for each instance.
Write a python program to count the number of vowels, consonants , words and question marks in a given string.
Write a python program to count the number of zeros and negative terms in a given set of n numbers.
Write a python program to input a list of N numbers. Calculate and display the average of numbers. Also display the cube of each value in the list.
Write a python program to create a dictionary of roll numbers and names of five students. Display the contents of dictionary in alphabetical order of names.
Write a python program to compute the nth Fibonacci number, Use a recursive function for the implementation.
Write a python program to create a file conatiing 10 numbers. Read the contents of file and display the square of each number.
Write a python program to create a text file and to input a line of text to it.
Write a python program to simulate a menu driven calculator with addition, subtraction, multiplication, division and exponentiation operations. Use a separate function to implement each operation.
Write a python program to find the sum of digits of a number using functions (preferably a recursive function).
Write a python program to find the sum of all even terms in a group of n numbers enterd by the user.



ICP - June 2016 (Supplementary Exam)


A book shop details contains the title of book and number of copies of each title. As books are added to shop the number of copies in each should increase and as books are sold the number of copies in each should decrease. Implement this scenario using dictionary datatype in python.
Write a recursive function to find the factorial of a number.
Write a program to generate fibonacci series upto a limit.
Write a python code to read a text file and copy the contents to another file after removing the blank lines.
Write a python code to search an element in a list.
Write a python program to add two matrices using list.
Write a python code to print following pattern.
Write a python code to check whether two strings are equal or not.
Write a python program to reverse a string and print whether its palindrome or not.
Write a function to find the sum of numbers between a lower bound and upper bound.
Write a python program using function to check the types of a triangle(Scalene,Isosceles,Equilateral) by getting the vertices from user.

Thursday, April 28, 2016

Database Management Systems

Module I - Slides

Data models - schemas and instances - Three-schema architecture and data independence - Database languages and interfaces - The database system environment - Centralized and client-server architectures - Classification of Database Management systems, Entity-Relationship Model - Entity Types, Entity Sets, Attributes and Keys - Relationship types, Relationship Sets, Roles and Structural Constraints - Weak Entity Types - Refining the ER Design - ER Diagrams and Naming Conventions - Example of Other Notation: UML Class Diagrams

Module II - Slides

Relational Model and Relational Algebra Relational Model Concepts - Constraints - Relational Database Schemas, Relational Algebra: Unary Operations - Set Theoretic operations - Binary Operations - Aggregate functions and grouping – Outer Join and Outer Union - Examples of Queries - The Tuple Relational Calculus - The Domain Relational Calculus.
SQL - Data Definition and Data Types - Specifying constraints - Schema change statements - Basic queries – Aggregate functions and grouping - Insert, Delete and Update statements - Assertions and Triggers - View
Database Design - Informal Design Guidelines for Relation Schemas - Functional Dependencies - Normal Forms Based on Primary Keys (Up to BCNF), Properties of Relational Decompositions - Algorithms for Relational Database Schema Design. The Database Design and Implementation Process - Use of UML Diagrams in database design.

Module III - Slides

Parallelizing Disk Access Using RAID Technology - New Storage Systems, Indexing Structures for Files - Types of Single-Level Ordered Indexes - Multilevel Indexes - Dynamic Multilevel Indexes Using B-Trees and B+ Trees - Indexes on Multiple Keys

Module IV - Slides

Transaction Management - Transaction and System Concepts – ACID Properties - Schedules - Characterizing Schedules Based on Recoverability and Serializability - Transaction Support in SQL
Concurrency Control Techniques - Locking Techniques - Timestamp Ordering - Multiversion Concurrency Control - Optimistic Concurrency Control - Using Locks for Concurrency Control in Indexes
Database Recovery Techniques - Recovery Concepts - Recovery Techniques Based on Deferred and Immediate Updates - Shadow Paging - Recovery in Multidatabase Systems - Backup and Recovery from Catastrophic Failures.

Friday, September 5, 2014

Trigger Example on Oracle



Question:
Calculate fine in a library management system using following condition.
For the first 3 days of delay 10 RS per day; for following 3 days 20 RS per day and after 6
days fine of 30 RS per day.
Click Here to Download 

Saturday, July 26, 2014

Software Architecture and Project Management

Module I - Slides

Component-and-Connector Viewtype, Styles of Component-and-Connector Viewtype, Allocation Viewtype and Styles, Documenting Software Interfaces, Documenting Behavior, Building the Documentation Package, IS2000 The Advanced Imaging Solution, Global Analysis

Module II - Slides

Archetypes and Archetype Patterns, Model Driven Architecture with Archetype Patterns, Literate Modeling, Customer Relationship Management Archetype Pattern, Product Archetype Pattern, Quantity Archetype Pattern, Rule Archetype Pattern

Module IV - Slides

Module IV - Part 1.

Defining EAI, Data-Level EAI, Application Interface-Level EAI, Method- Level EAI, User Interface-Level EAI, The EAI Process, An Introduction to EAI and Middleware, Transactional Middleware and EAI, RPCs Messaging and EAI, Distributed Objects and EAI, Database Oriented Middleware and EAI, Java Middleware and EAI, Message Brokers—The Preferred EAI Engine, Process Automation and EAI, Implementing and Integrating Packaged Applications—The General Idea, XML and EAI

Module IV - Part 2.

Layering, Organizing Domain Logic & Domain Logic Patterns, Data Source Architectural Patterns, Object-Relational Behavioral Patterns, Object-Relational Behavioral Patterns, Mapping to Relational Databases, Object-Relational Metadata Mapping Patterns, Offline Concurrency Patterns