0% found this document useful (0 votes)
46 views

CC Lab Manual - PART I

Uploaded by

jagadeesh210802
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

CC Lab Manual - PART I

Uploaded by

jagadeesh210802
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 92

Ex:1a Installing Virtual Box

Aim: To install virtual box on windows.

Step 1 – Download VirtualBox

You can download VirtualBox from the official Oracle VirtualBox website. VirtualBox can be
installed in Linux based operating systems such as Ubuntu, centOS etc., MacOS and
Windows. Download Windows version from here as I will be using Windows 10 to install
VirtualBox.

VirtualBox Web Page


The file size of VirtualBox installer for Windows is around 101 MB.

Step 2 – Start the Installation process

The file downloaded will have the file name format like VirtualBox-VersionNumber-
BuildNumber-Win.exe. Something like this: VirtualBox-6.1.6-137129-Win.exe. Double click on
the installer to launch the setup Wizard. Click on Next to continue.

1
VirtualBox Installation – Setup Wizard

Step 3 – Custom setup dialog box

You will see custom setup dialog box. There is not much to choose from. You can accept the
default and click next.

If you wish to change the installation directory, you van change it by clicking on the browse
button and selecting the new directory and clicking OK. Normally I leave it as the default as the
whole installation process does not take much space on your hard drive.

2
VirtualBox Installation – Custom setup dialog box screenshot

Step 4 – Custom setup dialog box – Feature to install

In this dialog box you can choose which features to install. As you can see, there is not much to
choose. You can accept the default and click next. Normally I uncheck Create a shortcut in the
quick launch bar and register file association.

3
VirtualBox Installation – Custom Setup – Select feature to Install

Step 5 – Network Interface setup

This dialog box warns you about setting up a Network Interface. what this means that VirtualBox
will install network interfaces that will interact with the installed virtual machines and the host
operating system which in our case is windows. This will temporarily disconnect you from the
internet but that OK, nothing to worry.

4
VirtualBox Installation – Network Interface warning

Step 6 – Ready to Install

You will see ready to install dialog box.

5
VirtualBox Installation – Ready to Install

Step 7 – Installation begins

After clicking install, you will mostly probably see User access control confirmation dialog box
from Windows OS. This is a security feature in Windows that wants to confirm if the application
should be allowed to proceed with the installation process. Click Yes to continue and you will
see that the installation process will begin. Wait for the installation to complete.

If you see Windows User Account Control Warning, click yes to accept and continue.

6
VirtualBox Installation – Windows User Account Control warning screenshot

7
VirtualBox Installation in Progress

Step 8 – Installation Completes

After the installation completes, you will see installation completion dialog box. Click finish. If
you leave Start Oracle VM VirtualBox after installation checked, VirtualBox will launch
automatically. If you uncheck it, you will have to launch Virtualbox manually. Its not big deal
anyways. Click finish to exit installation.

8
VirtualBox Installation complete

Step 9 – Launch VirtualBox application

Your newly installed VirtualBox is ready to go. You can search for VirtualBox in windows
search in taskbar. You will see the Virtual Box Icon on top. Click that to open VirtualBox.

9
10
VirtualBox Windows start menu search screenshot

Oracle VM VirtualBox Manager

11
Step 10 – Install VirtualBox Extension pack

After the installation of VirtualBox is complete, please install VirtualBox Extension pack which
will enable support for USB 2.0 and USB 3.0 devices, VirtualBox RDP, disk encryption, NVMe
and PXE boot for Intel cards.

VirtualBox Extension pack can be downloaded from here. Look for extension pack on the page,
click on all supported platform to start the download process. The name of the file will be
something like Oracle_VM_VirtualBox_Extension_Pack-6.1.6.vbox-extpack and around 10.5
MB in size.

VirtualBox – Download Extension

12
To install extensions pack, open VirtualBox, go to File -> Preference -> Extensions -> Add
new package (click on the + sign and browse to the downloaded file) and click Install.

VirtualBox – Preference – Extensions


Installation will start, wait for the process to complete.

13
VirtualBox Extension Pack installation in progress
You will see installation complete message. Click on OK to exit.

14
VirtualBox Extension pack Installation – success message

Result:
Thus the virtualbox is installed on windows.

15
Ex No: 1b Install Ubuntu-16.04 LTS on Virtual Box (Desktop version)

Aim: To install Ubuntu on virtual box.

1. Download the .iso image for Ubuntu-16.04-desktop version.

2. Open Oracle Virtual Box and click on “New”.

3. Enter the Name for your VM. Then select Type as Linux and Version as Ubuntu (64-bit) from
the drop-down. Click “Next”.

16
4. Allocate RAM as per your usage. 1024 MB is the recommended memory size. (Using the
recommended RAM here)

17
5. Select “Create a virtual hard disk now” as we are installing Ubuntu on Virtual Box for first
time.

18
6. Select “VDI(Virtual Box Disk Image)” as the type for your Virtual Hard Diskfile.

19
7. Select “Dynamically Allocated” as we don’t want to keep restriction on the virtual hard disk
file size.

20
8. Enter the name for the Virtual Hard Disk file. (we can also leave it as default name same as
VM name).

21
9. Your VM will now be created with the above configuration. (Visible on the left panel of Virtual
Box).

Select the VM and click on “Start”.

22
10. Now click on the icon as highlighted below.

23
11. Go to the path of your Ubuntu-16.04-desktop-amd64.iso image and select it. Click “Open”.

24
12. Now Ubuntu will boot up and ask for Installation details. Click on “InstallUbuntu”.

25
13. Don’t select the checkbox as we don’t want to install any 3rd party software while Ubuntu
Installation.

14. As we are making Ubuntu VM for the 1st time on our Virtual Box, we will select the 1st
option i.e. “Erase disk and install Ubuntu”.

26
15. Select your location for time zone settings. I am selecting India (Kolkata) as my region.

27
16. Select your keyboard layout. I am selecting as “English (US)” as per my usability.

17. Fill in the below fields for Name, Username, Password and Computer’s Name.

28
18. Wait for the Installation to complete.

29
19. Enter your password for logging into the Ubuntu-16.04 VM Desktop.

30
Ubuntu 16.04 LTS is now running on your Oracle Virtual Box.

Result:
Thus the Ubuntu desktop version is installed successfully on virtual box.

31
Ex:No 2 Installing GCC C compiler in Ubuntu OS and execute
simple programs

Objective

The objective is to install GCC the C compiler on Ubuntu 18.04 Bionic Beaver

Operating System and Software Versions

 Operating System: - Ubuntu 18.04 Bionic Beaver

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Conventions

 # - requires given linux commands to be executed with root privileges either directly as a
root user or by use of sudo command
 $ - requires given linux commands to be executed as a regular non-privileged user

Other Versions of this Tutorial

Ubuntu 20.04 (Focal Fossa)

Instructions

Install GCC

The following linux command will install gcc compiler on on Ubuntu 18.04 Bionic
Beaver. Open up terminal and enter:

$ sudo apt install gcc

Install build-essential
Another way to install gcc compiler is to install it as part of build-essential package. build-
essential package will also install additional libraries as well as g++ compiler. In most cases or
if unsure this is exactly what you need:

$ sudo apt install build-essential

32
Check GCC version
Confirm your installation by checking for GCC version:

$ gcc --version

gcc (Ubuntu 7.2.0-18ubuntu2) 7.2.0

Copyright (C) 2017 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C Hello World
Compile a simple C "Hello World" code:
#include <stdio.h> hello.c

int main()

printf("Hello, World!");

return 0;

}
Save the above code within file, compile and execute it:

$ gcc -o hello hello.c

$ ./hello

Hello, World!

33
Result:
Thus the gcc compiler is installed and the required binaries have been configured and
finally we have executed programs using C compiler.

34
Ex: No 3 Installing and Creating Application in GAE

Aim: Install Google App Engine. Create hello world app and other simple web applications
using python/java

Sign up for Google App Engine

You need to first sign up for the Google App Engine Account. This is easy and is a breeze in case
you already have a Google Account (Gmail, Apps, etc) in which case it is best that you use that
straight away. Go to http://appengine.google.com and simply login with your account. Even if
you do not have an account, you can sign up for a Google Account, a link for which is provided
on the page.

Whether you already have a Google Account or have signed up for a new one, do login first. Once
you are logged in, you will be presented with a list of applications that you are currently running
on the Google App Engine under the account which we logged in with. Google provides a total of
10 applications that you can deploy under a single account. Please be aware that as of this date,
there is no way to delete an application and use that slot for another application — so use with
care.

Here is a screen shot of my account page at the Google App Engine after login:

It shows that I have 4 applications registered on Google App Engine and have 6 more to go. You
might have no applications listed if you are logging in for the first time and/or have not created
any application.

35
Note: If you are registering your 1st application, the process is as follows:

1. Click on Create an Application.

2. Once you have selected a name, then you will be prompted for your Mobile Number. Enter
your mobile number (with country code, etc).

3. Google will send you a SMS with an code. You will be prompted on the next screen to enter
the code that you received on SMS. Enter that to confirm theprocess.

This is only required for registering your 1st application and once the SMS verification
process is complete, you will not be prompted again when you create your 2nd application
and so on.

Registering your Application

Cool, let’s create an application then but before that we must tell your application to show its ID.
So let us talk about Identity first.

Identity, Identity, Identity….

Yes, everyone needs to show an ID. And the same applies to your application too that is hosted in
the cloud.

Let me explain that a little. As you know Google App Engine is a PaaS (Platform as a Service),
which means that you can develop and deploy your application (following some specification)
into their infrastructure (in the cloud). Now what this means is that while it would be nice for you
to get an application name of your choice, it is not feasible in a hosted environment where you are
sharing all resources with other applications too.

By default, your application needs to be unique within this so called name space:

YOUR_APPLICATION_ID.appspot.com

where YOUR_APPLICATION_ID can be any name that you wish for your application, that has
not already been taken by someone else. So before you start with an application in mind, it pays to
plan it out a little first and that includes what name you would like for your application and then
registering it as quickly as possible so that you have it.

36
Note: Please keep in mind that what I am discussing here is the basic facilities provided by
Google. It is perfectly possible for you to purchase a domain name and then point it to the URL
where your application is hosted in the Google App Engine cloud. But we will not discuss all that
know and will keep the discussion to what is provided straight of the bat.

OK. So you have thought of the application name and wish to register it. So since we are going to
write a “Hello World” sort of an application — we should go ahead and create an application
identifier first.

Let us actually do that before moving on. Assuming that you are logged in as described earlier,
click on the Create An Application button. This will bring up a page as shown below:

This page will allow you to select an Application Identifier that we have been talking about. Go
ahead. Try out a few names like myhelloworld, myfirstapp, etc and see which one is available.
Give any string for the Application Title and go with the default options for the Account options
(we can skip it for now). Click on the Save button. If all is well, the application identifier will be

37
created and your first application is registered. Congratulations! But we have a lot to do including
writing the application.

Please make sure that you note down your Application Identifier since this will be used later on to
verify your entire setup. OK, let me not scare you — you can always go back to the Google
AppEngine account and see the applications listed :-)

Do check out the excellent monitoring portal that Google App Engine provides to view/monitor a
number of things about your application. Just click on the registered application in the application
list and you will be lead to the portal where you can check the logs/quotas and configure several
other stuff. As this blog develops, I will cover more of this but for now, just browse around and
familiarize yourself.

Downloading, Installing and setting up the Eclipse IDE for GAEJ

We will need the following software to be present on your development machine. I am assuming
that you are comfortable with downloading and setting up of the software from public sites.

1. Java Development Kit 1.6.x or Java Development 1.7.x : Please ensure that the JDK
version is setup appropriately on your machine. Do note that you should setup the Java
Development Kit and not the Java Runtime Environment (JRE). The JDK is required
for compilation of your JSP files, should you use them in your Web Application Project.

2. Eclipse 3.8 / 4.2 / 4.3 : Choose any Eclipse IDE version that you want. I am using the Eclipse
3.8 Juno Release.

3. GAEJ Plug-in: Go to the following


page: https://developers.google.com/eclipse/docs/getting_started. This page contains links to
the GAEJ plugin for Eclipse download/installation. I list below the update site URL for the
GAEJ Eclipse plugin from that page:

 Eclipse 4.3 (Kepler)


http://dl.google.com/eclipse/plugin/4.3

 Eclipse 3.8 / 4.2 (Juno)


http://dl.google.com/eclipse/plugin/4.2

 Eclipse 3.7 (Indigo)


http://dl.google.com/eclipse/plugin/3.7

38
1. Depending on the version of Eclipse that you have, I reproduce from the Google site the links
for installing the plugin depending on the version of Eclipse that you have. Please follow the
instructions on the page, it is straightforward and I do not wish to replicate it here.

 Google Plugin for Eclipse 4.3 (Kepler)

 Google Plugin for Eclipse 3.8/4.2 (Juno).

 Google Plugin for Eclipse 3.7 (Indigo).

Once you have finished the setup and restarted your Eclipse IDE, you should see the following
Google Icon in the toolbar of the Eclipse IDE. Click on that and you will see the different options
as listed below:

If not, please refer to the troubleshooting options that are described in each of the above links.

Writing our first GAEJ application

So far we have signed up for Google App Engine, registered our Application Id and setup the
GAEJ plug-in for Eclipse. We are ready to write our application now. The Gods always tell us to
start any new thing on an auspicious note by crying out ―Hello World‖ and we shall stick to the
tradition.

As we shall see things unfold, GAEJ plug-in for Eclipse makes things very simple. It does all the
hard work after we give it some inputs and then it generates an entire web application for us along
with sample servlet that pretty much does just that i.e. says ―Hello World‖. What we will be
writing no code, you say? Yes. All this code is generated for us and is pretty much a template that
we can take and put our application logic in there.

39
So let us move forward and generate our first project now (steps along with explanation follow):

1. Launch your Eclipse (if not started).

2. Either click on File → New → Other or press Ctrl-N to create a new project.
Select Google and then Web Application project. Alternately, you could also click on the New
Web Application Project Icon [part of GAEJ Eclipse Plugin] in the Toolbar:

3. This will bring up a New Web Application Project page as shownbelow:

40
41
Enter the details as given below:

* Project Name : MyFirstGAEJProject. You can select any name that you like.

* Package : com.gaej.firstproject. You can select any name that you like. I will go with this and
use it for the rest of the blog post, so it is advisable to stick to this one for now.

* Deselect the Use Google Web Toolkit option.

4. Click on Finish. This will generate an entire project for you which is ready to be deployed.

5. But before that, let us look at the files that have been generated. I reproduce for you the screen
from my Package Explorer as shown below:

42
6. If you are familiar with Java Web applications, this should be straightforward stuff with
directories like WEB-INF, WEB-INF\classes, WEB-INF\lib, etc. But let us cover it in brief:

 src : This contains the source files. You will find that it has generated a sample file
name MyFirstGAEJProjectSerlvet.java for you. It has been created as per the package
hierarchy that you selected. You can keep all your source files over here as you develop
more.

 war : This is the war file structure i.e. Web Application Archive. This if you recollect will be
deployed into the Servlet Container of the App Engine that will eventually host your Java
Web Application. In this directory, you have the following:

43
 WEB-INFlib: All appropriate JAR files that provide the Java SDK libraries along with
Google Java APIs for the App Engine have been linked correctly into the project build
path and the necessary JAR files are also present in the WEB-INF\lib folder

 index.html : This is the first page served. You can actually customize it to any that you want.
All your additional html files/resources could go in here.

 logging.properties: If you are familiar with Java logging, you should be able to make sense
of this file and tweak your logging preferences over here.

 web.xml : This is a standard web application configuration file. You will find
the Servlet entries present here for the sample servlet that is generated for us.

 appengine-web.xml : This is a Google App Engine specific configuration file. And the main
element here of interest to us is the application element that will contain the Application
ID of the application that we registered for Google and which will be pointing to a hosted
version of this WAR. We will set this up at the time of deploying the application, which we
will cover later.

7. MyFirstGAEJProjectServlet : Let us cover this in brief, which can also act as a refresher for
writing and setting up a servlet configuration in case you are little rusty (happens to the best of
us!).

The servlet code is straightforward as shown below[Omitting package and import declarations]:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}

It extends the javax.servlet.http.HttpServlet class and implements the GET method. You could
parse out the request parameters if needed (in this case there are none of interest). All that the
servlet does is to get a handle to the response stream and then mention its content type and send
across the text Hello World to the client.

Now, we need to set the servlet url and its java class in the web.xml configuration file. Open up
the web.xml file and you will find the appropriate entries as shownbelow:
<servlet>
<servlet-name>MyFirstGAEJProject</servlet-name>

44
<servlet-class>com.gaej.firstproject.MyFirstGAEJProjectServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyFirstGAEJProject</servlet-name>
<url-pattern>/myfirstgaejproject</url-pattern>
</servlet-mapping>

And finally, if you open index.html, you will find a link that references the servlet as shown
below:
<td><a href="myfirstgaejproject"/>MyFirstGAEJProject</td>

so that when the index.html page is served, you will see


a Hyperlink named MyFirstGAEJProject and on clicking it will invoke the
MyFirsGAEProject servlet implemented
in com.gaej.firstproject.MyFirstGAEJProjectServlet which will then print out Hello World.

Testing it locally

GAEJ Eclipse plug-in ships with a local server, where you can deploy your application and test it
out. Ensure that port 8888 is free on your machine and that no other web server is running on it.

To test the application, all you need to do is the following:

1. Select the project and then Run As → Web Application

2. This will compile/deploy your application the local server and the server will be started on port
8888. You will see the server starting in the console window as shown below:

45
3. If all is well, you will get the message that the server is running at http://localhost:8888 as
shown above.

4. Once that notification is shown, launch your browser and navigate to the url
: http://localhost:8888. This will bring up a default JSP page that is generated for you with the
servlet URL in it as shown below:

5. Click on the link and you will see your servlet getting invoked and telling you ―Hello World‖.

46
Now that things work, we need to deploy this application into the Google App Engine
infrastructure. So lets go to that.

Deploying it into the Cloud

First ensure that you are logged in to your Google Account via which you signed up for Google
App Engine earlier. In Eclipse, you will find on the bottom right of the screen, a “Sign in to
Google” … button present as shown below:

Click on that, it will bring up the standard Google Account login. Provide your username and
password. Google will also ask for permission to allow access, please go ahead and give it all the
permission.

Once logged in successfully, you will see your user id shown at the bottom right of the screen
instead of the ―Sign in to Google…‖ button.

To deploy the application in the cloud, simply click on the Deploy App Engine Project
Icon available in Toolbar[part of GAEJ Eclipse Plugin].

47
This will bring up a dialog where you will need to provide your Google Account credentials
(username and password). Do not click on Deploy yet.

48
The dialog says that it does not have an application ID. What this means is that AppEngine
needs to know under which of your 10 applications shown the application be hosted under. So
you have to provide the name here.

Click on the App Engine Project settings link in the above dialog. This will bring up a properties
page as shown where you need to entire the Application ID. Remember the Application ID that
we discussed earlier and you registered one for you. Well that is the Application Id that you need
enter over here. Enter that and click OK as shown below [Remember to enter your Application ID
before clicking OK]:

49
This will lead you back to the Deploy Project to Google App Engine dialog box. Now simply
click Deploy. This will connect to Google App Engine and deploy your application and register it
with the Application Id that you used. A snapshot of the Progress dialog on my machine is shown
below:

You will a lot of activity in your Console bar (a snapshot is shown) and at the end of it you should
see a message saying that the application is available.

You can deploy your application several times as you make changes. There is a certain quota limit
to how many times you can deploy it in a day and you can read that up but for the moment, you
can rest assured that the number is quite huge.

50
Congratulations! You now have your own application hosted on the Google App Engine. It is
already available to the world and that is what we will verify in the next section.

Testing the hosted/online version of our application

Your application is available under the url


: http://YOUR_APPLICATION_ID.appspot.com. So if you Application ID is myapp, the url
is http://myapp.appspot.com. Go ahead and access your URL. :-)

Technically it is even possible to have different versions running, but for the purposes of this
article we will limit it to the latest version that you deploy and which is available under the url
that I have mentioned above.

Next Steps

So we have ended our mini journey for now in which we did the following:

 Registered for Google App Engine

 Registered our first application

 Setup the Developer Environment for developing and deploying GAEJ Javaapplications

 Used the Google Eclipse Plug-in to develop our first GAEJ application

 Tested and deployed our first GAEJ application

Result:
Thus the Google App Engine is installed and a sample application is launched using Google
App Engine Launcher.

51
Ex No: 4(a) CloudSim Installation

Aim:
To install CloudSim in Windows.

Procedure:

Step 1: Setting up the Prerequisites

1. First of all we need to download the CloudSim and latest version of the Java Development
Toolkit (JDK). These can be found here:
CloudSim 3.0.3
JDK latest version for Windows

2. CloudSim requires a working JRE, so install the JDK.

3. Now its time to install the CloudSim. Unpack the downloaded 'CloudSim-3.0.3.tar.gz' or
'CloudSim-3.0.3.zip' (let the name of the unpacked folder be 'cloudsim-3.0.3'). As you can see
there is no executable file inside the folder so there is no special program to install the CloudSim.
Later if you want to remove the CloudSim, then remove the whole 'cloudsim-3.0.3' directory.

Step 2: Setting up the Environment


Now comes the critical part, the most important part of the CloudSim setup is the setting up the
paths to different classes and jar files correctly or you won't be able to run your programs
efficiently.

1. The first path to be set is the 'Path' variable which will contain the location of executable java
files such as 'javac' and 'java' and will be used by the CloudSim while compiling and running a
CloudSim or Java program.
2. The second path to be set is the 'CLASSPATH' variable which will contain the location of the
class files and will be used by the CloudSim while executing an application. So we have to set
three consecutive values first one for location of JDK executables, second one is the location of
jar files provided in the CloudSim and is used exclusively by the CloudSim applications and third
one is the location where we have stored our programs.
To set the paths go to the properties of 'My Computer' —> 'Advanced system settings' —
>'Advanced' tab —> 'Environment Variables...' —> under the 'System variables' —> 'New...' —
> in the popped up box set the 'Variable name' and 'Variable Value' as shown and click 'OK'.

Variable name Variable value


1 Path C:\Program Files\Java\jdk1.8.0_11\bin;

52
C:\Program Files\Java\jdk1.8.0_11\bin;
2 CLASSPATH C:\Users\michael\Desktop\cloudsim-3.0.3\jars\*;
C:\Users\michael\Desktop\cloudsim-3.0.3\examples;

Note: We have to close all the opened command prompt windows, if any.

Step 3: Testing the Setup (Compiling and Executing a CloudSim Application)

Finally now we can test whether our installation is successful or not. CloudSim includes some test
example programs in the 'CloudSim\examples\gridsim\' folder that we can use to test our setup.

1. Compiling a CloudSim program: If you have followed this DIY then compiling a CloudSim
program is pretty straightforward; the basic syntax for compilation is just similar to that of Java
programs i.e. javac filename.java or javac file_location\filename.java. Let us compile the
Example2.java included in 'CloudSim\examples\gridsim\example02\' folder. We will now runthe
following command in a new command prompt

javac C:\Users\Dhyan\Desktop\cloudsim-
1
3.0.3\examples\org\cloudbus\cloudsim\examples\CloudSimExample1.java

2. Running the compiled program: The syntax for running a compiled CloudSim program is similar
to that of running a program in Java i.e. java filename. In our case we have to type (see image 1)
1 java org.cloudbus.cloudsim.examples.CloudSimExample1

Result:
A Study on CloudSim and its execution was successful.

53
Ex No: 4(b) Creation of Data Center with one Host and one Cloudlet

Aim:
To create a datacenter with one host and run one cloudlet on it.

Algorithm:
1. Initialize the CloudSim library.
2. Create Data Centers
3.Create Broker
4. Add the VMs to the VM List
5. Create one host and one Cloudlet
6. Starts the simulation

Program:
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

/**

54
* A simple example showing how to create a data center with one host and run one cloudlet on
it.
*/
public class CloudSimExample1 {
/** The cloudlet list. */
private static List<Cloudlet> cloudletList;
/** The vmlist. */
private static List<Vm> vmlist;

/**
* Creates main() to run this example.
*
* @param args the args
*/
@SuppressWarnings("unused")
public static void main(String[] args) {
Log.printLine("Starting CloudSimExample1...");

try {
// First step: Initialize the CloudSim package. It should be called before
creating any entities.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance(); // Calendar whose fields have

been initialized with the current date and time.


boolean trace_flag = false; // trace events

/* Comment Start - Dinesh Bhagwat


* Initialize the CloudSim library.
* init() invokes initCommonVariable() which in turn calls initialize() (all these 3 methods are
defined in CloudSim.java).
* initialize() creates two collections - an ArrayList of SimEntity Objects (named entities which
denote the simulation entities) and
* a LinkedHashMap (named entitiesByName which denote the LinkedHashMap of the same
simulation entities), with name of every SimEntity as the key.
* initialize() creates two queues - a Queue of SimEvents (future) and another Queue of
SimEvents (deferred).
* initialize() creates a HashMap of of Predicates (with integers as keys) - these predicates are
used to select a particular event from the deferred queue.
* initialize() sets the simulation clock to 0 and running (a boolean flag) to false.
* Once initialize() returns (note that we are in method initCommonVariable() now), a
CloudSimShutDown (which is derived from SimEntity) instance is created
* (with numuser as 1, its name as CloudSimShutDown, id as -1, and state as RUNNABLE).
Then this new entity is added to the simulation
* While being added to the simulation, its id changes to 0 (from the earlier -1). The two
collections - entities and entitiesByName are updated with this SimEntity.
* the shutdownId (whose default value was -1) is 0

55
* Once initCommonVariable() returns (note that we are in method init() now), a
CloudInformationService (which is also derived from SimEntity) instance is created
* (with its name as CloudInformatinService, id as -1, and state as RUNNABLE). Then this new
entity is also added to the simulation.
* While being added to the simulation, the id of the SimEntitiy is changed to 1 (which is the next
id) from its earlier value of -1.
* The two collections - entities and entitiesByName are updated with this SimEntity.
* the cisId(whose default value is -1) is 1
* Comment End - Dinesh Bhagwat
*/
CloudSim.init(num_user, calendar, trace_flag);
// Second step: Create Datacenters
// Datacenters are the resource providers in CloudSim. We need at
// list one of them to run a CloudSim simulation
Datacenter datacenter0 = createDatacenter("Datacenter_0");

// Third step: Create Broker


DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

// Fourth step: Create one virtual machine


vmlist = new ArrayList<Vm>();

// VM description
int vmid = 0;
int mips = 1000;
long size = 10000; // image size (MB)
int ram = 512; // vm memory (MB)
long bw = 1000;
int pesNumber = 1; // number of cpus
String vmm = "Xen"; // VMM name
// create VM
Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new
CloudletSchedulerTimeShared());

// add the VM to the vmList


vmlist.add(vm);
// submit vm list to the broker
broker.submitVmList(vmlist);
// Fifth step: Create one Cloudlet
cloudletList = new ArrayList<Cloudlet>();

// Cloudlet properties
int id = 0;
long length = 400000;
long fileSize = 300;

56
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize,
outputSize, utilizationModel, utilizationModel,
utilizationModel);
cloudlet.setUserId(brokerId);
cloudlet.setVmId(vmid);

// add the cloudlet to the list


cloudletList.add(cloudlet);
// submit cloudlet list to the broker
broker.submitCloudletList(cloudletList);
// Sixth step: Starts the simulation
CloudSim.startSimulation();

CloudSim.stopSimulation();

//Final step: Print results when simulation is over


List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);

Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}

/**
* Creates the datacenter.
*
* @param name the name
*
* @return the datacenter
*/
private static Datacenter createDatacenter(String name) {

// Here are the steps needed to create a PowerDatacenter:


// 1. We need to create a list to store
// our machine
List<Host> hostList = new ArrayList<Host>();

// 2. A Machine contains one or more PEs or CPUs/Cores.


// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();

57
int mips = 1000;

// 3. Create PEs and add these into a list.


peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and
MIPS Rating

// 4. Create Host with its id and list of PEs and add them to the list
// of machines
int hostId = 0;
int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage
int bw = 10000;

hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList)
)
); // This is our machine

// 5. Create a DatacenterCharacteristics object that stores the


// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located
double cost = 3.0; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this
// resource
double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not
adding SAN

// devices by now

DatacenterCharacteristics characteristics = new DatacenterCharacteristics(


arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);

58
// 6. Finally, we need to create a PowerDatacenter object.
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new
VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}

return datacenter;
}

// We strongly encourage users to develop their own broker policies, to


// submit vms and cloudlets according
// to the specific rules of the simulated scenario
/**
* Creates the broker.
*
* @return the datacenter broker
*/
private static DatacenterBroker createBroker() {
DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}

/**
* Prints the Cloudlet objects.
*
* @param list list of Cloudlets
*/
private static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;

String indent = " ";


Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent
+ "Start Time" + indent + "Finish Time");

59
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);

if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.print("SUCCESS");

Log.printLine(indent + indent + cloudlet.getResourceId()


+ indent + indent + indent + cloudlet.getVmId()
+ indent + indent
+ dft.format(cloudlet.getActualCPUTime()) +
indent
+ indent + dft.format(cloudlet.getExecStartTime())
+ indent + indent
+ dft.format(cloudlet.getFinishTime()));
}
}
}
}

OUTPUT:

60
Result:
Thus the program to create one host and one cloudlet using cloudsim was executed successfully.

61
Ex.No: 5 Transfer files from VM to VM
Aim:
To transfer files between VM’s.

Once you’ve installed the guest additions, enable shared folders by adding a folder from your
host machine in the settings for the guest machine. To do this, first make sure the guest machine
is powered off. Then, select the guest machine in the list on the left of the VirtualBox Manager
and click Settings on the toolbar.

On the Settings dialog box, click Shared Folders in the list of options on the left. On the Shared
Folders screen, click the folder button with the plus sign to add a folder.

62
On the Add Share dialog box, select Other from the Folder Path drop-down list.

63
The Browse For Folder dialog box displays. Navigate to the folder you want to share between
the host and the guest, select it, and click OK.

64
The path to the selected folder is inserted in the Folder Path edit box. The name of the folder
automatically becomes the Folder Name, but you can change this name if you want. If you don’t
want to be able to change items in this folder in the guest machine, select the Read-only check
box. To have the selected folder automatically mounted in the guest machine when you boot it,
select the Auto-mount check box. Click OK once you’ve finished choosing your settings for the
shared folder.

65
The selected folder displays in the Folders List. Click OK to close the dialog box.

66
Now, make sure the guest machine is still selected in the VirtualBox Manager and click Start to
boot it.

Once the guest machine is booted, open Nautilus (File Manager) by clicking the file cabinet on
the Unity bar on the left side of the desktop.

67
In the Devices list on the left, click Computer and then double-click the Media folder on the
right. You’ll see a folder named similarly to the folder you selected to share on your host
machine with ―sf_‖ added to the beginning of the name.

If you double-click on that folder, the following dialog box displays. This is because there is one
more task to perform before you can access the shared folder.

68
In addition to users in Ubuntu, there are also groups. When VirtualBox installed the Ubuntu
operating system, it added a group called ―vboxsf‖. Before you can access any shared folders,
you must add yourself to the vboxsf group. To do this, press Ctrl + Alt + T to open a Terminal
window. Type the following at the prompt, replacing ―[username]‖ with your username, and
press Enter.

sudo adduser [username] vboxsf

Type your password when prompted and press Enter again. Messages display as you are being
added to the group and ―Done.‖ displays when the process has been successfully completed.

To close the Terminal window, type ―exit‖ (without the quotes) at the prompt and press Enter.

To verify you are in the vboxsf group, you can type ―id [username]‖ (without the quotes, and
replacing ―[username]‖ with your username) at the prompt and press Enter. All the groups of
which the specified user is a member display.

69
Now, when you access the shared folder in the Media folder as described above, you should see
any files in that exist in that folder on the host machine.

You can edit these files directly in this folder if you DID NOT select the ―Read-only‖ option
when selecting the folder in the Settings. You can also copy files into and out of this folder. If
the folder was set to ―Read-only‖, you can only copy files from this folder and cannot copy files
into it.

Result:
Thus the files are shared between two VM’s.

70
Ex.No: 6 Single-node OpenStack deployment

Aim:
Install single node openstack in ubuntu.

Downloading CentOS 7 ISO Image:


First, you have to download the CentOS 7 ISO installation image from the official website of
CentOS 7.

To do that, visit https://www.centos.org/download/ and click on Minimal ISO as marked in the


screenshot below.

Now, click on any of the link.

71
Your browser should prompt you to save the file. Select Save File and click on OK.

CentOS 7 ISO installation media is being downloaded.

72
Creating a Virtual Machine:
Once the CentOS 7 ISO installation image is downloaded, open VirtualBox and click
on Machine > New… as marked in the screenshot below.

Now, type in a name for the VM. Then, select Linux and Red Hat (64-bit) as the Type and
Version respectively. Then, click on Next.

73
You need at least 16 GB of RAM in order to run OpenStack. So, make sure you assign 16 GB
(16384 MB) of RAM to your VM. Once you’ve set the memory size, click on Next.

Now, click on Create.

74
Now, click on Next >.

Now, click on Next >.

75
Now, set 100 GB as the hard disk size and click on Create.

OpenStack VM should be created. Now, select the OpenStack VM and click on Settings.

76
Now, select USB Tablet as the Pointing Device from System > Motherboard as marked in the
screenshot below.

Now, check Enable Nested VT-x/AMD-v from System > Processor as marked in the
screenshot below.

77
Now, from the Network section, change Attached to to Bridged Adapter, Adapter
Type to Paravirtualized Network (virtio-net) and Promiscuous Mode to Allow All.

78
Now, you have to set the CentOS 7 ISO installation image as the Optical drive. To do that,
follow the procedures as marked in the screenshot below.

Now, select the CentOS 7 ISO installation image and click on Open.

Now, click on OK.

79
The VM is now ready to install CentOS 7.

Installing CentOS 7 on the Virtual Machine:


Now, select the OpenStack VM and click on Start.

80
The VM should boot from the ISO installation image. Now, select Install CentOS 7 and
press <Enter>.

The CentOS 7 GUI installer should start. Now, install CentOS 7 as usual. Make sure to set
a root password during installation.

81
Once CentOS 7 is installed, you should be able to log in as the user root using the password that
you’ve set during installation.

Configuring Network:
Now, disable firewalld service with the following command:
# systemctl disable firewalld

82
Now, stop the firewalld service with the following command:
# systemctl stop firewalld

Now, disable NetworkManager service with the following command:


# systemctl disable NetworkManager

Now, stop NetworkManager service with the following command:


# systemctl stop NetworkManager

Now, enable network service with the following command:


# systemctl enable network

Now, start network service with the following command:


# systemctl start network

Now, check the name of your network interface as follows:

83
$ ip a
The name of the network interface of my CentOS 7 VM is eth0.

Now, run the following command to configure the network interface eth0 to automatically get IP
address via DHCP:
# echo -e 'DEVICE=eth0\nBOOTPROTO=dhcp\n' > /etc/sysconfig/network-scripts/ifcfg-eth0

Now, reboot your CentOS 7 VM as follows:

$ sudo reboot

Once it boots, the network interface eth0 should have an IP address.

84
Installing OpenStack:
Before you do anything, make sure to set the LANG and LC_ALL environment variables
correctly with the following command:
# echo -e "LANG=en_US.utf-8\nLC_ALL=en_US.utf-8\n" > /etc/environment

Now, to make sure all the CentOS 7 packages are up to date, run the following command:

# yum update -y

CentOS packages are being updated.

All the CentOS 7 packages should be updated.

85
Now, add the OpenStack Rocky package repository with the following command:

# yum install -y centos-release-openstack-rocky

The OpenStack Rocky package repository should be added.

Now, update the CentOS 7 system packages again with the following command:

# yum update -y

All the system packages should be updated.

86
Now, install PackStack with the following command:

# yum install -y openstack-packstack

PackStack is being installed. It may take a while to complete.

PackStack should be installed.

87
Now, install all the components of OpenStack on CentOS 7 with the following command:

# packstack --allinone

OpenStack is being installed.

PackStack is configuring required components with Puppet. It will take a long time to complete.

88
OpenStack is installed.

Testing OpenStack:
You need the IP address of your CentOS 7 machine in order to access OpenStack Horizon
dashboard.

To find the IP address of CentOS 7, run the following command:

# ip a
As you can see, the IP address of my CentOS 7 machine is 192.168.21.200. It will be different
for you. So, make sure to replace it with yours from now on.

89
Now, to find the OpenStack Horizon dashboard password, run the following command:

# cat keystonerc_admin | grep PASSWORD


As you can see, df29616110934166 is the password for my OpenStack Horizon dashboard.

Now, from your favorite web browser, visit http://192.168.21.200 and you should see the
OpenStack login page. Type in the username admin and the
password df29616110934166 (password should be different for you. So, replace it with yours.).
Then, click on Sign In.

90
a
You should be logged in to OpenStack Horizon dashboard. Now, you can configure OpenStack
any way you like from here.

91
Result:
Thus the one node openstack is installed on ubuntu.

92

You might also like