Esempio n. 1
0
 def set_counter(self, counter_name, idx, pkts, byts):
     counter = self.stateInfo.get_counter_info(counter_name)
     if counter.is_direct:
         table_name = counter.binding
         self.client.bm_mt_write_counter(
             0, table_name, idx,
             Standard.BmCounterValue(bytes=byts, packets=pkts))
     else:
         self.client.bm_counter_write(
             0, counter_name, idx,
             Standard.BmCounterValue(bytes=byts, packets=pkts))
Esempio n. 2
0
 def __add_table_entry(self, ip: bytes, _action: bytes, prefix_length: int):
     match = [
         st.BmMatchParam(type=1,
                         exact=None,
                         lpm=st.BmMatchParamLPM(
                             key=ip, prefix_length=prefix_length),
                         ternary=None)
     ]
     action = [bytearray(_action)]
     entry_handle = self.client.bm_mt_add_entry(
         0, 'my_ingress.ipv4_match', match, "my_ingress.to_port_action",
         action, st.BmAddEntryOptions(priority=0))
     print(entry_handle)
Esempio n. 3
0
def thrift_connect_standard(thrift_ip, thrift_port, out=sys.stdout):
    def my_print(s):
        out.write(s)

    # Make socket
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)

    protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "standard")
    client = Standard.Client(protocol)

    # Connect!
    try:
        transport.open()
    except TTransport.TTransportException:
        my_print("Could not connect to thrift client on port {}\n".format(
            thrift_port))
        my_print("Make sure the switch is running ")
        my_print("and that you have the right port\n")
        sys.exit(1)

    return client,transport
Esempio n. 4
0
def thrift_connect(thrift_ip, thrift_port):
    transport = TSocket.TSocket(thrift_ip, thrift_port)
    transport = TTransport.TBufferedTransport(transport)
    bprotocol = TBinaryProtocol.TBinaryProtocol(transport)
    protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "standard")
    client = Standard.Client(protocol)
    transport.open()
    return client
Esempio n. 5
0
    def __init__(self, port):
        transport = TSocket.TSocket('127.0.0.1', port)

        # Buffering is critical. Raw sockets are very slow
        transport = TTransport.TBufferedTransport(transport)

        # Wrap in a protocol
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        protocol = TMultiplexedProtocol.TMultiplexedProtocol(
            protocol, "standard")
        self.client = Standard.Client(protocol)
        self.transport = transport
        transport.open()
def thrift_connect(pre_type):
    # Make socket
    transport = TSocket.TSocket('localhost', THRIFT_PORT)
    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)
    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    standard_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "standard")
    standard_client = Standard.Client(standard_protocol)

    if pre_type == PreType.SimplePre:
        mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "simple_pre")
        mc_client = SimplePre.Client(mc_protocol)
    elif pre_type == PreType.SimplePreLAG:
        mc_protocol = TMultiplexedProtocol.TMultiplexedProtocol(protocol, "simple_pre_lag")
        mc_client = SimplePreLAG.Client(mc_protocol)
    else:
        mc_client = None

    # Connect!
    transport.open()

    return standard_client, mc_client