Example #1
0
    def __init__(self, ipAddr, context):

        if not ipAddr.isalpha():
            raise EnvironmentError, "control-rad.py: Expected host name, got address"

        self.shell = session.LocalShell()
        self.ostype = posix.uname()[0]
        ipm = ipsetup.IPManager()

        # 22726 - Radius Access Response needs to be received by the MSW on the same interface on
        # on which the request was sent. Radius Request messages will be sent on the management
        # interface.
        self.network = context['userConfig.radius_eth_iface']
        self.ipAddr = socket.gethostbyname(ipAddr)

        if self.network == '-1':
            raise OSError, 'IP address %s not found in ipsetup.py' % self.ipAddr

        if self.ostype == 'Linux':
            self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \
                            % (self.ipAddr, self.network))
        elif self.ostype == 'SunOS':
            self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \
                            % (self.network,self.ipAddr))
        else:
            raise NotImplementedError, 'Endpoint resource not implemented for %s' % self.ostype
Example #2
0
    def __init__(self, rtpsendAddr, file, ctxt=None):
        """
          In this function we initialize all the variables to be used in the 
          class RogueRtp
          Parameters supplied to the __init__ functions are.

          rtpsendAddr ---- The IP address of machine from where we inject rogue rtp packets
	  serverAddr  ---- IP address of the SUT machine.
	  file        ---- Input file for the tool having the rtp packets to be sent

        """
        self.rtpfile = file + '.tmp'

        self.myAddr = rtpsendAddr
        self.myPort = '50000'
        self.log = logging.getLogger('nextestlog')
        self.localShell = session.LocalShell()
        self.pktsInFile = 0
        if os.path.isfile(self.rtpfile):
            self.pktsInFile = self.readNum()
        else:
            replaceIpPort(file, rtpsendAddr)
            self.pktsInFile = self.readNum()

        self.context = ctxt
        try:
            if self.context.has_key('msw'):
                self.msw = self.context['msw']
        except Exception, e:
            raise RogueRtpError("Context variable 'msw' not defined")
Example #3
0
    def SetUp(self, context, result):
        """
        Set up the resource.

        Create a generic endpoint object.  Resolve the address prior to
        creating the gen.
        """
        self.log = logging.getLogger('nextestlog')
        self.shell = session.LocalShell()

        self.ostype = posix.uname()[0]
        ipm = ipsetup.IPManager()
        self.network = ipm.getNetwork(self.ipaddr)
        self.log.debug('NETWORK ---------%s' % self.network)
        self.ipAddr = socket.gethostbyname(self.ipaddr)

        if self.network == '-1':
            raise OSError, 'IP address %s not found in ipsetup.py' % self.ipaddr

        # Ticket 14783 changes
        if self.network == '0':
            port = context['userConfig.eth_pub_iface']
        else:
            port = context['userConfig.eth_pri_iface']

        if self.ostype == 'Linux':
            self.ethport = "eth%s" % port
            self.shell.assertCommand('sudo ip addr add %s/16 dev %s > /dev/null 2>&1' \
                            % (self.ipAddr, self.ethport))
        elif self.ostype == 'SunOS':
            self.ethport = "e1000g%s" % port
            self.shell.assertCommand( 'sudo ifconfig %s addif %s/16 up > /dev/null 2>&1' \
                            % (self.ethport,self.ipAddr))
        else:
            raise NotImplementedError, 'Endpoint resource not implemented for %s' % self.ostype

        self.log.debug('Creating endpoint resource: property: %s, ip: %s, mask: %s eth: %s' % \
                                  (self.property, self.ipaddr, self.mask, self.ethport))

        #Create a generic endpoint object.
        if len(self.mask) == 0: self.mask = None
        if len(self.ethport) == 0: self.ethport = None
        try:
            ip = socket.gethostbyname(self.ipaddr)
        except socket.gaierror, exc:
            errno, errstr = exc
            result.Annotate({
                'Endpoint name': self.property,
                'Endpoint address': self.ipaddr,
                'Exception': str(exc)
            })
            result.Fail('Could not resolve endpoint IP address')
Example #4
0
    def __init__(self, mswIP, scmConf="OFF"):
        """Construct a new MswConfig object used for reading and modifying 
        certain configuration parameters of the MSW.

        mswVersion -- Version of the MSW
        mswIP      -- IP of the MSW
        scmConf    -- Value of context variable 'nextest.scm_configuration'
        """

        self.logObj = logging.getLogger('nextestlog')
        self.mswVersion = ""
        self.msw = None
        self.mswIP = mswIP
        self.localShell = session.LocalShell()

        # 26333 - Get the SCM configuration information and store it
        if scmConf == "ON":
            self.scm = True
        else:
            self.scm = False
Example #5
0
    def SetUp(self, context, result):
        """
        Create NAT table rules to convert fixed internal addresses into fixed external addresses. 
        """
        #get nat addresses
        pubNat = socket.gethostbyname('pub_nat')
        prvNat = socket.gethostbyname('prv_nat')
        # 54804: Add new nat device prv_nat1
        prvNat1 = socket.gethostbyname('prv_nat1')
        # 38969: Add a new NAT device pubNat1
        pubNat1 = socket.gethostbyname('pub_nat1')
        #pubNat2 = socket.gethostbyname('pub_nat2')
        #prvNat2 = socket.gethostbyname('prv_nat2')
        if (len(pubNat) < 8) or (len(prvNat) < 8) or (len(pubNat1) < 8):
            raise EnvironmentError, 'Check pub_nat/prv_nat addresses in /etc/hosts file'

        #self.intAddresses = { '192.168.0.100':'0',
        #                      '192.168.0.101':'0',
        #                      '192.168.1.100':'1',
        #                      '192.168.1.101':'1',
        #                    }

        # 38969: New NAT device pubNat1
        # 54804: Add new nat device prv_nat1
        self.ExtAddresses = [pubNat, prvNat, pubNat1, prvNat1]
        self.If = [context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface'],\
                   context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface']]
        self.shell = session.LocalShell()

        #get os type
        ostype = posix.uname()[0]

        if ostype == 'Linux':
            # Add the NAT endpoint addresses
            # 38969: Add the new nat device
            # 54804: Add new nat device prv_nat1
            for ipAddr in range(0, 4):
                self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \
                                % (self.ExtAddresses[ipAddr], self.If[ipAddr]))

            # Add NAT configuration
            # 38969: Set NAT rules for the new nat device
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.0.100/24 -j SNAT ' + \
                            '--to-source %s:20000-25000' % pubNat
            self.shell.assertCommand(commandLine)
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.2.100/24 -j SNAT ' + \
                            '--to-source %s:25001-29999' % pubNat1
            self.shell.assertCommand(commandLine)
            # 43494: Modified the port range
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.1.100/24 -j SNAT ' + \
                            '--to-source %s:30000-35000' % prvNat
            self.shell.assertCommand(commandLine)

            # 43494: Add NAT rule for tcp
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.100/24 -j SNAT ' + \
                            '--to-source %s:35001-39999' % prvNat
            self.shell.assertCommand(commandLine)

            # 51005: Add NAT TCP rule for pubNat
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.0.100/24 -j SNAT ' + \
                            '--to-source %s:40000-45000' % pubNat
            self.shell.assertCommand(commandLine)

            #PR 137224 Add rules for new NAt device in nat_enhancements
            commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.3.100/24 -j SNAT ' + \
                            '--to-source %s:20000-25000' % prvNat1
            self.shell.assertCommand(commandLine)

        elif ostype == 'SunOS':
            #Package installation should be done at the install time.
            #self.shell.assertCommand('cd /opt/nextest/etc')
            #self.shell.assertCommand('sudo pkgrm nsf')
            #self.shell.assertCommand('sudo pkgadd -d ipfilter_3.4.27_stock.pkg')
            # Add the NAT endpoint addresses
            for ipAddr in 0, 1:
                self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \
                                % (self.If[ipAddr],self.ExtAddresses[ipAddr]))

            # Add nat configuration in /etc/opt/ipf/ipnat.conf
            fileName = '/etc/opt/ipf/ipnat.conf'
            try:
                natFile = open(fileName, 'r')
                natFileLines = natFile.readlines()
                natFile.close()
            except:
                #file does not exist, we will create it later
                natFileLines = []

            # Ticket 14783 changes
            self.solNatNewLines = [
                'map e1000g%s 192.168.0.0/16 -> %s/32 portmap udp 20001:30000\n'
                % (context['pub_eth_iface'], pubNat),
                'map e1000g%s 192.168.1.0/16 -> %s/32 portmap udp 30001:40000\n'
                % (context['pri_eth_iface'], prvNat),
            ]

            natFileLinesCleaned = [
                x for x in natFileLines if x not in self.solNatNewLines
            ]

            self.shell.assertCommand('sudo touch %s' % fileName)
            self.shell.assertCommand('sudo chmod 777 %s' % fileName)
            natFile = open(fileName, 'w')
            natFile.writelines(natFileLinesCleaned)
            natFile.writelines(self.solNatNewLines)
            natFile.close()
            self.shell.assertCommand('sudo chmod 644 %s' % fileName)

            self.shell.assertCommand('sudo /etc/init.d/ipfboot stop')
            self.shell.assertCommand('sudo /etc/init.d/ipfboot start')

        else:
            raise NotImplementedError, 'Nat resource not implemented for %s' % ostype

        context[self.property] = 'created'