diff options
author | Ashlee Young <ashlee@onosfw.com> | 2015-10-19 10:14:31 -0700 |
---|---|---|
committer | Ashlee Young <ashlee@onosfw.com> | 2015-10-19 10:14:31 -0700 |
commit | e9bb60be43af477f17b30ee1f2ba205565b7fa15 (patch) | |
tree | 981fd759a44b751fc45cde774f46fda37c11c257 /framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java | |
parent | 74f3941756a1386cbc1fa99ee73fdc8376a0b6a0 (diff) |
Updated onos src tree to commit id 1e60f97ae50c05b94fcb6a10520738bfb5efdfd1
Diffstat (limited to 'framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java')
-rwxr-xr-x | framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java new file mode 100755 index 00000000..1c95804a --- /dev/null +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java @@ -0,0 +1,72 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.bgp.controller.impl; + +import java.util.Timer; +import java.util.TimerTask; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Implement sending keepalive message to connected peer periodically based on negotiated holdtime. + */ +public class BGPKeepAliveTimer { + + private Timer keepAliveTimer; + private BGPChannelHandler handler; + private static final Logger log = LoggerFactory.getLogger(BGPKeepAliveTimer.class); + + /** + * Gets keepalive timer object. + * + * @return keepAliveTimer keepalive timer. + */ + public Timer getKeepAliveTimer() { + return keepAliveTimer; + } + + /** + * Initialize timer to send keepalive message periodically. + * + * @param h channel handler + * @param seconds time interval. + */ + public BGPKeepAliveTimer(BGPChannelHandler h, int seconds) { + this.handler = h; + this.keepAliveTimer = new Timer(); + this.keepAliveTimer.schedule(new SendKeepAlive(), 0, seconds * 1000); + } + + /** + * Send keepalive message to connected peer on schedule. + */ + class SendKeepAlive extends TimerTask { + @Override + public void run() { + log.debug("Sending periodic KeepAlive"); + + try { + // Send keep alive message + handler.sendKeepAliveMessage(); + handler.getBgpPacketStats().addOutPacket(); + } catch (Exception e) { + log.info("Exception occured while sending keepAlive message" + e.toString()); + } + } + } +} |