Showing posts with label onePK. Show all posts
Showing posts with label onePK. Show all posts

Tuesday, 22 October 2013

Basic pom.xml file for building a bundle in Open DayLight

Maven is something like makefile in linux. Maven helps in compilation. when you say 'mvn install' it reads the pom.xml file. pom.xml have various tags essential tags for creating basic pom.xml are as below. Please note i have put comments between <!-- --> which is standard xml comment tag.
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

<!-- Do not change above lines. They provide xml version and maven version info -->
    <parent>
<!-- Everything inside this tab is your parents, i.e on top of which you will make your application   --> 
    <groupId>org.opendaylight.controller</groupId>
    <!-- its the project where your parent is located-->
    <artifactId>commons.opendaylight</artifactId>
    <!-- Parent application name-->
    <version>1.4.0-SNAPSHOT</version>
    <!-- Parents version-->
    <relativePath>../../commons/opendaylight</relativePath>
    <!-- Path where parent pom file is located-->
  </parent>
  <scm>
    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
  </scm>
    <!-- Everything inside scm tag is for version controlling you can delete this tag if you want-->

  <artifactId>samples.userinfo</artifactId>
  <!-- this is your application name.  -->
  <version>0.0.1-SNAPSHOT</version>
  <!-- Your application version.  -->

  <packaging>bundle</packaging>
  <!-- Tells maven you want to create OSGi bundle.   -->


  <build>
  <!-- Information on how to build the code-->
    <plugins>
      <plugin>
      <!-- Info on which plugin to use from maven   -->
        <groupId>org.apache.felix</groupId>
        <!-- Project name for that plugin-->
        <artifactId>maven-bundle-plugin</artifactId>
        <!-- Kind of obvious we are making an OSGi bundle-->
        <version>2.3.6</version>
        <!-- Plugins option-->
        <extensions>true</extensions>
        <!-- Use extension for this project-->
        <configuration>
          <instructions>
            <Import-Package>
              org.opendaylight.controller.sal.core,
              org.slf4j,
            </Import-Package>
            <!-- Which package to import for building the code-->
            <Export-Package>
              org.opendaylight.controller.samples.userinfo
            </Export-Package>
          <!-- Name of the package, which will be exported-->
            <Bundle-Activator>
              org.opendaylight.controller.samples.userinfo.internal.Activator
            </Bundle-Activator>
           <!-- Address where OSGi activator is located -->


          </instructions>
          <manifestLocation>${project.basedir}/META-INF</manifestLocation>
           <!-- Address of OSGi META file -->
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  <!-- Dependencies on exiting code>
    <dependency>
      <groupId>org.opendaylight.controller</groupId>
      <artifactId>sal</artifactId>
      <version>0.5.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

For more information on how to make a simple application in open daylight controller click here

Wednesday, 16 October 2013

Running a custom bundle in Open Day light controller

I have copied one of the sample application int the opendaylight controller and named it as userinfo by changing artifact id in pom file. In this post i will show you how can i add my application while controller is running.
First of all build the bundle by command "mvn install". If everything is well go to command line of controller. But before that let me shed some light on how OSGi works. Life cycle of any app is 1. install 2. resolve 3.uninstall. First and last is self explanatory. A bundle will be in resolved state when all the dependencies are resolved and that's when you can start a service. 

osgi> install file:/home/ubuntu/workspace/controller/opendaylight/samples/userinfo
Bundle id is 150
< output omitted>
Version              0.0.1.SNAPSHOT
BundleDescription    org.opendaylight.controller.samples.userinfo_0.0.1.SNAPSHOT
Framework            org.eclipse.osgi.framework.internal.core.Framework@164e955
ResolutionFailureException org.osgi.framework.BundleException: The state indicates the bundle is resolved
Revisions            [org.opendaylight.controller.samples.userinfo_0.0.1.SNAPSHOT]
BundleContext        null
BundleId             150
StartLevel           1
SymbolicName         org.opendaylight.controller.samples.userinfo
BundleData           org.opendaylight.controller.samples.userinfo_0.0.1.SNAPSHOT
KeyHashCode          150
StateChanging        null

as you can see once installed osgi gives you a bundle id. now you can start or stop this bundle with this id.
To check currently installed bundle and its id/state say 'ss'

osgi> ss
"Framework is launched."


id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.8.1.v20120830-144521
<OUTPUT ommited>
150     RESOLVED    org.opendaylight.controller.samples.userinfo_0.0.1.SNAPSHOT

As you can see state is resolved. Good now let you can start the bundle by giving command 'start 150'. But it will give you error as the controller don't have binaries. For that you need to copy your binary (i.e. jar) to
/home/ubuntu/workspace/controller/opendaylight/distribution/opendaylight/target/distribution.opendaylight-0.1.0-SNAPSHOT-osgipackage/opendaylight/plugins

ok. Now say start 150 and njoy your code !

To create a simple application click here






Friday, 4 October 2013

User levels in OpenDayLight controller

I have been playing around Open Daylight Controller from a while now. OD controller divides user in 6 types mainly

1. SYSTEMADMIN - This user is the GOD of OD. He has no restrictions.
2.  NETWORKADMIN - It can do everything but setting a system admin user profile. Still he has lots of power.
3. NETWORKOPERATOR - It can only see what is configured anywhere;
4. CONTAINERUSER - container context user
5. APPUSER - application context user
 6. NOUSER - Get out ! He is not authorized.

I am yet to figure out what user level 4 and 5 can do. Please let me know if you figure it out :)

Definition of these are in UserLevel.java file.

    SYSTEMADMIN(0, "System-Admin", "System Administrator"),
    NETWORKADMIN(1, "Network-Admin", "Network Administrator"),
    NETWORKOPERATOR(2, "Network-Operator", "Network Operator"),
    CONTAINERUSER(4, "Container-User", "Container User"),  
    APPUSER(5, "App-User", "Application User"),
    NOUSER(255, "Not Authorized", "Not Authorized");

Next I will show how to set up an AAA server for OD controller.