Ejemplo n.º 1
0
    def test_want_stats(self):
        pid = 123
        vpp_papi.register_event_callback(papi_event_handler)
        papi_event.clear()

        # Need to configure IPv6 to get som IPv6 FIB stats
        t = vpp_papi.create_loopback('')
        print(t)
        self.assertEqual(t.retval, 0)

        ifindex = t.sw_if_index
        addr = str(IPv6Address('1::1').packed)
        t = vpp_papi.sw_interface_add_del_address(ifindex, 1, 1, 0, 16, addr)
        print(t)
        self.assertEqual(t.retval, 0)

        # Check if interface is up
        # XXX: Add new API to query interface state based on ifindex, instead of dump all.
        t = vpp_papi.sw_interface_set_flags(ifindex, 1, 1, 0)
        self.assertEqual(t.retval, 0)

        t = vpp_papi.want_stats(True, pid)

        print(t)

        #
        # Wait for some stats
        #
        self.assertEqual(papi_event.wait(15), True)
        t = vpp_papi.want_stats(False, pid)
        print(t)
Ejemplo n.º 2
0
 def test_want_interface_events(self):
     pid = 123
     vpp_papi.register_event_callback(papi_event_handler)
     papi_event.clear()
     t = vpp_papi.want_interface_events(True, pid)
     print(t)
     print('Setting interface up')
     t = vpp_papi.sw_interface_set_flags(0, 1, 1, 0)
     print(t)
     self.assertEqual(papi_event.wait(5), True)
     t = vpp_papi.sw_interface_set_flags(0, 0, 0, 0)
     print(t)
     self.assertEqual(papi_event.wait(5), True)
Ejemplo n.º 3
0
    def test_want_stats(self):
        pid = 123
        vpp_papi.register_event_callback(papi_event_handler)
        papi_event.clear()
        t = vpp_papi.want_stats(True, pid)

        print(t)

        #
        # Wait for some stats
        #
        self.assertEqual(papi_event.wait(30), True)
        t = vpp_papi.want_stats(False, pid)
        print(t)
Ejemplo n.º 4
0
    def test_tap(self):
        pid = 123
        vpp_papi.register_event_callback(papi_event_handler)
        papi_event.clear()
        t = vpp_papi.want_stats(True, pid)

        print(t)

        t = vpp_papi.tap_connect(1, b'tap', b'foo', 1, 0)
        print(t)
        self.assertEqual(t.retval, 0)
        swifindex = t.sw_if_index

        t = vpp_papi.sw_interface_set_flags(swifindex, 1, 1, 0)
        print(t)
        self.assertEqual(t.retval, 0)

        ip6 = IPv6Address(u'2001:db8::1').packed
        t = vpp_papi.sw_interface_add_del_address(swifindex, 1, 1, 0, 16, ip6)
        print(t)
        time.sleep(40)
Ejemplo n.º 5
0
    return str(''.join(chr(int(x, base=16)) for x in mac.split(':')))


def fix_string(s):
    return s.rstrip("\0").decode(encoding='ascii')


def _vpp_cb(*args, **kwargs):
    # sw_interface_set_flags comes back when you delete interfaces
    # print 'callback:', args, kwargs
    pass


# Sometimes a callback fires unexpectedly.  We need to catch them
# because vpp_papi will traceback otherwise
vpp_papi.register_event_callback(_vpp_cb)


class VPPInterface(object):
    def _check_retval(self, t):
        """See if VPP returned OK.

        VPP is very inconsistent in return codes, so for now this reports
        a logged warning rather than flagging an error.
        """

        try:
            self.LOG.debug("checking return value for object: %s" % str(t))
            if t.retval != 0:
                self.LOG.debug('FAIL? retval here is %s' % t.retval)
        except AttributeError as e:
Ejemplo n.º 6
0
    return str(''.join(chr(int(x, base=16)) for x in mac.split(':')))


def fix_string(s):
    return s.rstrip("\0").decode(encoding='ascii')


def _vpp_cb(*args, **kwargs):
    # sw_interface_set_flags comes back when you delete interfaces
    # print 'callback:', args, kwargs
    pass


# Sometimes a callback fires unexpectedly.  We need to catch them
# because vpp_papi will traceback otherwise
vpp_papi.register_event_callback(_vpp_cb)


class VPPInterface(object):

    def _check_retval(self, t):
        """See if VPP returned OK.

        VPP is very inconsistent in return codes, so for now this reports
        a logged warning rather than flagging an error.
        """

        try:
            self.LOG.debug("checking return value for object: %s" % str(t))
            if t.retval != 0:
                self.LOG.debug('FAIL? retval here is %s' % t.retval)