def Main():
    # Create a client handler for connecting to server
    client = JetHandler()
    # Open session with Thrift Server
    try:
        client.OpenRequestResponseSession(device=DEFAULT_JSD_HOST, port=DEFAULT_JSD_PORT,
                                           user=USER, password=PASSWORD, ca_certs=None, client_id=DEFAULT_CLIENT_ID)
        evHandle = client.OpenNotificationSession(DEFAULT_JSD_HOST, DEFAULT_NOTIFICATION_PORT,
                                                  None, None, None, DEFAULT_MQTT_TIMEOUT, "", True)
        global topic
        topic = "SubscribedToBgpNotifications"
        stream = evHandle.CreateStreamTopic(topic)
        evHandle.Subscribe(stream, handleMessage, 2)
        print "Connected to Server and ",stream.topic
        bgp = client.GetRoutingBgpRoute()
        RouteInit(bgp)
        print "Verify on router using cli : show programmable-rpd clients"
        raw_input("<ENTER to Set route>")
        RouteSet(bgp)
        print "Verify on router using cli : show route protocol bgp-static"
        raw_input("<ENTER to Get route>")
        RouteGet(bgp)
        print "Compare API out put with CLI : show route protocol bgp-static"
        raw_input("<ENTER to Delete route>")
        RouteDel(bgp)
        print "Verify on router using cli : show route protocol bgp-static"
        raw_input("<Verify in router and ENTER>")
        print "Closing the Client"
        client.CloseNotificationSession()

    except Exception as tx:
        print '%s' % (tx.message)
    return
Esempio n. 2
0
                        psreq = sock.recv(HEADER_LENGTH)
                        if not psreq:
                            sock.close()
                            CONNECTION_LIST.remove(sock)
                        else:

                            # add this request to the sockdict
                            Version, req_type, payload_length, reserved = unpack(
                                '!ccll', psreq)
                            LOG.info('New Request received of size: %d' %
                                     payload_length)
                            sockdict[sock] = payload_length
                            routereqDict[sock] = ''
                except Exception as e:
                    LOG.debug('Exception: %s' % str(e.message))
                    sock.close()
                    CONNECTION_LIST.remove(sock)
                    continue
    serversocket.close()
    requestQ.join()

    # Close session
    evHandle.Unsubscribe()
    LOG.debug("Closing the Client")
    client.CloseRequestResponseSession()
    client.CloseNotificationSession()

except Thrift.TException as tx:
    LOG.critical('Exception received: %s' % (tx.message))
def Main():
    parser = argparse.ArgumentParser(prog=os.path.basename(__file__),
                                     description='Sample JET application')
    parser.add_argument(
        "--address",
        nargs='?',
        help="Address of the JSD server. (default: %(default)s)",
        type=str,
        default='localhost')
    parser.add_argument(
        "--port",
        nargs='?',
        help="Port number of the JSD notification server. default: %(default)s",
        type=int,
        default=1883)
    parser.add_argument("--bind_address",
                        nargs='?',
                        help="Client source address to bind.",
                        type=str,
                        default="")
    args = parser.parse_args()

    try:

        # Create a client handler for connecting to server
        client = JetHandler()

        # open session with MQTT server
        evHandle = client.OpenNotificationSession(
            device=args.address,
            port=args.port,
            bind_address=args.bind_address)
        # different ways of creating topic
        ifdtopic = evHandle.CreateIFDTopic(
            op=evHandle.ALL, ifd_name=DEFAULT_NOTIFICATION_IFD_NAME)
        ifltopic = evHandle.CreateIFLTopic(evHandle.ALL,
                                           DEFAULT_NOTIFICATION_IFL_NAME,
                                           DEFAULT_NOTIFICATION_IFL_UNIT)
        ifatopic = evHandle.CreateIFATopic(evHandle.DELETE)
        ifftopic = evHandle.CreateIFFTopic(evHandle.CHANGE)
        rtmtopic = evHandle.CreateRouteTableTopic(evHandle.ALL)
        rttopic = evHandle.CreateRouteTopic(evHandle.ALL)
        fwtopic = evHandle.CreateFirewallTopic(evHandle.ALL)

        # Subscribe for events
        print "Subscribing to IFD notifications"
        evHandle.Subscribe(ifdtopic, handleEvents1)
        evHandle.Subscribe(ifltopic, handleEvents2)
        #evHandle.Subscribe(ifftopic, handleEvents1)
        evHandle.Subscribe(ifatopic, handleEvents1)
        evHandle.Subscribe(rtmtopic, handleEvents2)
        evHandle.Subscribe(rttopic, handleEvents2)
        evHandle.Subscribe(fwtopic, handleEvents1)
        ret = evHandle.Unsubscribe(ifftopic)
        if ret != 0:
            print('Failed to unsubscribe %s' % ifftopic.topic)
        evHandle.Unsubscribe(ifdtopic)

        time.sleep(5)
        # Unsubscribe events
        print "Unsubscribe from all the event notifications"
        evHandle.Unsubscribe()

        # Close session
        print "Closing the Client"
        client.CloseNotificationSession()

    except Exception, tx:
        print '%s' % (tx.message)