001: /*_############################################################################
002: _##
003: _## SNMP4J - UsmTimeEntry.java
004: _##
005: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.security;
022:
023: import java.io.Serializable;
024: import org.snmp4j.smi.OctetString;
025:
026: /**
027: * The <code>UsmTimeEntry</code> class represents time synchronization
028: * information associated with an engine ID.
029: *
030: * @author Frank Fock
031: * @version 1.0
032: */
033: public class UsmTimeEntry implements Serializable {
034:
035: private static final long serialVersionUID = -8064483016765127449L;
036:
037: private OctetString engineID;
038: private int engineBoots;
039: private int timeDiff;
040: private int latestReceivedTime;
041:
042: /**
043: * Creates a time entry with engine ID, engine boots and time.
044: *
045: * @param engineID
046: * the engine ID for which time synchronization information is created.
047: * @param engineBoots
048: * the number of engine boots of the engine.
049: * @param engineTime
050: * the time in seconds elapsed since the last reboot of the engine.
051: */
052: public UsmTimeEntry(OctetString engineID, int engineBoots,
053: int engineTime) {
054: this .engineID = engineID;
055: this .engineBoots = engineBoots;
056: setEngineTime(engineTime);
057: }
058:
059: public OctetString getEngineID() {
060: return engineID;
061: }
062:
063: public int getEngineBoots() {
064: return engineBoots;
065: }
066:
067: public void setEngineBoots(int engineBoots) {
068: this .engineBoots = engineBoots;
069: }
070:
071: public int getTimeDiff() {
072: return timeDiff;
073: }
074:
075: public void setTimeDiff(int timeDiff) {
076: this .timeDiff = timeDiff;
077: }
078:
079: /**
080: * Gets the time when a message has been received last from the associated
081: * SNMP engine.
082: * @return
083: * the engine time in seconds.
084: */
085: public int getLatestReceivedTime() {
086: return latestReceivedTime;
087: }
088:
089: /**
090: * Sets the time when a message has been received last from the associated
091: * SNMP engine.
092: * @param latestReceivedTime
093: * the engine time in seconds.
094: */
095: public void setLatestReceivedTime(int latestReceivedTime) {
096: this .latestReceivedTime = latestReceivedTime;
097: }
098:
099: /**
100: * Sets the engine time which also sets the last received engine time
101: * to the supplied value.
102: * @param engineTime
103: * the time in seconds elapsed since the last reboot of the engine.
104: */
105: public void setEngineTime(int engineTime) {
106: this .latestReceivedTime = engineTime;
107: this .timeDiff = engineTime
108: - (int) (System.currentTimeMillis() / 1000);
109: }
110: }
|