2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netvirt.bgpmanager.thrift.client;
11 import java.io.IOException;
12 import java.net.Socket;
13 import java.net.SocketException;
14 import java.util.concurrent.atomic.AtomicInteger;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class BgpSyncHandle {
19 private static final Logger LOG = LoggerFactory.getLogger(BgpSyncHandle.class);
21 public static final int INITED = 1;
22 public static final int ITERATING = 2;
23 public static final int DONE = 3;
24 public static final int ABORTED = 4;
25 public static final int NEVER_DONE = 5;
27 public static final int DEFAULT_TCP_SOCK_SZ = 87380; //default receive buffer size on linux > 2.4
29 private final AtomicInteger state = new AtomicInteger(NEVER_DONE);
31 public int getState() {
35 public int getMaxCount() {
36 //compute the max count of routes we would like to send
37 Socket skt = new Socket();
38 int sockBufSz = DEFAULT_TCP_SOCK_SZ;
40 sockBufSz = skt.getReceiveBufferSize();
41 } catch (SocketException s) {
42 LOG.warn("Socket Exception while retrieving default socket buffer size");
46 } catch (IOException e) {
47 LOG.warn("IO Exception while closing socket for retrieving default socket buffer size");
49 return sockBufSz / getRouteSize();
52 public int getRouteSize() {
53 //size of one update structure on the wire. ideally
54 //this should be computed; or thrift sure has a nice
55 //way to tell this to the applciation, but for the
56 //moment, we just use 8 bytes more than the size of
62 public int setState(int newState) {
63 return this.state.getAndSet(newState);