<commit_before>#!/usr/bin/env python

"""
onos.py: A simple ONOS Controller() subclass for Mininet

We implement the following classes:

ONOSController: a custom Controller() subclass to start ONOS
OVSSwitchONOS: a custom OVSSwitch() switch that connects to multiple controllers.

We use single Zookeeper and Cassandra instances for now.

As a custom file, exports:

--controller onos
--switch ovso

Usage:

$ sudo ./onos.py

This will start up a simple 2-host, 2 ONOS network

$ sudo mn --custom onos.py --controller onos,2 --switch ovso
"""

from mininet.node import Controller, OVSSwitch
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel, info
from mininet.util import quietRun

from shutil import copyfile
from os import environ
from functools import partial


class ONOS( Controller ):
    "Custom controller class for ONOS"

    # Directories and configuration templates
    home = environ[ 'HOME' ]
    onosDir = home + "/ONOS"
    zookeeperDir = home + "/zookeeper-3.4.5"
    dirBase = '/tmp'
    logDir = dirBase + '/onos-%s.logs'
    cassDir = dirBase + '/onos-%s.cassandra'
    configFile = dirBase + '/onos-%s.properties'
    logbackFile = dirBase + '/onos-%s.logback'
    jmxbase = 7189
    restbase = 8080
    ofbase = 6633

    # Per-instance property template
    fc = 'net.floodlightcontroller.'
    proctag = 'mn-onos-id'
    jvmopts = (
        # We match on this to shut down our instances
        ( proctag, 0 ),
        ( fc + 'restserver.RestApiServer.port', restbase ),
        ( fc + 'core.FloodlightProvider.openflowport', ofbase ),
        ( fc + 'core.FloodlightProvider.controllerid', 0 ) )


    # Make mvn not suck
    mvn = 'mvn -e -X'

    def __init__( self, name, n=1, drop=True, **params):
        """n: number of ONOS instances to run (1)
           drop: drop root privileges (True)"""
        self.check()
        self.drop = drop
        self.count = n
        self.ids = range( 0, self.count )
        Controller.__init__( self, name, **params )
        # We don't need to run as root, and it can interfere
        # with starting Zookeeper manually
        if self.drop:
            self.user = quietRun( 'who am i' ).split()[ 0 ]
            self.sendCmd( 'su', self.user )
            self.waiting = False
        # Need to run commands from ONOS dir
        self.cmd( 'cd', self.onosDir )
        self.cmd( 'export PATH=$PATH:%s' % self.onosDir )
        self.cmd( 'export MVN="%s"' % self.mvn )

    def check( self ):
        "Check for prerequisites"
        if not quietRun( 'which java' ):
                raise Exception( 'java not found -'
                                 ' make sure it is installed and in $PATH' )
        if not quietRun( 'which mvn' ):
                raise Exception( 'Maven (mvn) not found -'
                                ' make sure it is installed and in $PATH' )

    def startCassandra( self ):
        "Start Cassandra"
        self.cmd( 'start-cassandra.sh start' )
        status = self.cmd( 'start-cassandra.sh status' )
        if 'Error' in status:
            raise Exception( 'Cassandra startup failed: ' + status )

    def stopCassandra( self ):
        "Stop Cassandra"
        self.cmd( 'start-cassandra.sh stop' )

    def startZookeeper( self, initcfg=True ):<commit_msg>Comment out maven debug params.<commit_after>#!/usr/bin/env python

"""
onos.py: A simple ONOS Controller() subclass for Mininet

We implement the following classes:

ONOSController: a custom Controller() subclass to start ONOS
OVSSwitchONOS: a custom OVSSwitch() switch that connects to multiple controllers.

We use single Zookeeper and Cassandra instances for now.

As a custom file, exports:

--controller onos
--switch ovso

Usage:

$ sudo ./onos.py

This will start up a simple 2-host, 2 ONOS network

$ sudo mn --custom onos.py --controller onos,2 --switch ovso
"""

from mininet.node import Controller, OVSSwitch
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel, info
from mininet.util import quietRun

from shutil import copyfile
from os import environ
from functools import partial


class ONOS( Controller ):
    "Custom controller class for ONOS"

    # Directories and configuration templates
    home = environ[ 'HOME' ]
    onosDir = home + "/ONOS"
    zookeeperDir = home + "/zookeeper-3.4.5"
    dirBase = '/tmp'
    logDir = dirBase + '/onos-%s.logs'
    cassDir = dirBase + '/onos-%s.cassandra'
    configFile = dirBase + '/onos-%s.properties'
    logbackFile = dirBase + '/onos-%s.logback'
    jmxbase = 7189
    restbase = 8080
    ofbase = 6633

    # Per-instance property template
    fc = 'net.floodlightcontroller.'
    proctag = 'mn-onos-id'
    jvmopts = (
        # We match on this to shut down our instances
        ( proctag, 0 ),
        ( fc + 'restserver.RestApiServer.port', restbase ),
        ( fc + 'core.FloodlightProvider.openflowport', ofbase ),
        ( fc + 'core.FloodlightProvider.controllerid', 0 ) )


    # For maven debugging
    # mvn = 'mvn -o -e -X'

    def __init__( self, name, n=1, drop=True, **params):
        """n: number of ONOS instances to run (1)
           drop: drop root privileges (True)"""
        self.check()
        self.drop = drop
        self.count = n
        self.ids = range( 0, self.count )
        Controller.__init__( self, name, **params )
        # We don't need to run as root, and it can interfere
        # with starting Zookeeper manually
        if self.drop:
            self.user = quietRun( 'who am i' ).split()[ 0 ]
            self.sendCmd( 'su', self.user )
            self.waiting = False
        # Need to run commands from ONOS dir
        self.cmd( 'cd', self.onosDir )
        self.cmd( 'export PATH=$PATH:%s' % self.onosDir )
        if hasattr( self, 'mvn' ):
            self.cmd( 'export MVN="%s"' % self.mvn )

    def check( self ):
        "Check for prerequisites"
        if not quietRun( 'which java' ):
                raise Exception( 'java not found -'
                                 ' make sure it is installed and in $PATH' )
        if not quietRun( 'which mvn' ):
                raise Exception( 'Maven (mvn) not found -'
                                ' make sure it is installed and in $PATH' )

    def startCassandra( self ):
        "Start Cassandra"
        self.cmd( 'start-cassandra.sh start' )
        status = self.cmd( 'start-cassandra.sh status' )
        if 'Error' in status:
            raise Exception( 'Cassandra startup failed: ' + status )

    def stopCassandra( self ):
        "Stop Cassandra"
        self.cmd( 'start-cassandra.sh stop' )

    def startZookeeper( self, initcfg=True ):
{'fraction_non_alphanumeric': 0.10466489518748155, 'fraction_numerical': 0.0070859167404783, 'mean_word_length': 2.342377898371978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6464221', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2060, 'n_words': 696}