//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / ILMI
//
//File: ilmiaddressregistration.h
//
//Version: $Revision: 1.16 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/10/19 18:12:50 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Pärnänen
//
//Description:
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 

#ifndef __ILMI_ADDRESSREGISTRATION_H__
#define __ILMI_ADDRESSREGISTRATION_H__

#include <typeinfo>
#include <string>
#include <list>

#include <asn-incl.h>

#include "asn/rfc1155-smi.h"
#include "asn/rfc1157-snmp.h"

#include "pf/protocol.h"
#include "pf/types.h"
#include "mib/mibdestination.h"

class ilmiProtocol;
class ilmiARState;
class mgmtCommand;

//
//Class: ilmiAddressRegistration
//
//Description:
//

class ilmiAddressRegistration : public pfProtocol,
                                public mibDestination
{
    public:
        // Public static const variables
        static const int VALID;
        static const string VALID_STRING;        
        static const int INVALID;

        // Constructor and destructor
        ilmiAddressRegistration(ilmiProtocol *protocol_);
        virtual ~ilmiAddressRegistration(void);

        // Initialization
        void initialize(void);
        
        // Timers
        void startResponseTimer(void);
        void stopResponseTimer(void);
        void startPollTimer(void);
        void stopPollTimer(void);

        // Inputs from switch
        void start(void);
        void stop(void);
        void listPrefixes(mgmtCommand &command_);

        // Inputs from network
        void receiveColdStartTrap(VarBindList &list_);
        void receiveGetResponse(PDUInt &errorStatus_,
                                AsnInt &errorIndex_,
                                VarBindList &list_);
        
        // MibDestination interface
        virtual string getValue(const string &name_);
        virtual void setValue(const string &name_, const string &value_);

        // Send methods
        void sendGetNextRequest(string name_);
        void sendColdStartTrap(void);
        void sendListAddresses(void);
        
        // Action methods called by states
        bool isResending(void);
        void clearCommandMap(void);
        void clearLocalPrefixes(void);
        void clearTables(void);
        void storeLocalPrefixes(mgmtCommand &command_);
        string getAddressStatus(const string &name_) const;
        void addAddress(const string &address_);
        void removeAddress(const string &address_);
        void registerPrefixes(void);

        
    private:
        // Private static const variables
        static const string ATM_NETPREFIX_BASE;
        
        static const int PORT_INDEX;
        static const int LOCAL_UNI;
        static const int ADDRESS_INDEX;
        static const int ADDRESS_LENGTH;

        static const int MAX_POLL_TIMES;
        
        // Private methods
        ilmiARState *getCurrentState(void) const;
        void fillVarBind(VarBind *var_, string &name_, int value_ = VALID);

        // typedefs
        typedef map<string, string, less<string> > mapType;
        typedef mapType::iterator mapIterType;
        typedef mapType::const_iterator mapConstIterType;
        
        // Useful typedefs for STL list.
        typedef list<string> tableType;
        typedef tableType::iterator tableIterator;
        typedef tableType::const_iterator tableConstIterator;

        tableType _localPrefixTable;
        tableType _prefixTable;
        mapType _addressMap;
        int _retries;
        
        ilmiProtocol *_ilmi;
};

#endif // __ILMI_ADDRESSREGISTRATION_H__

