134 lines
3.1 KiB
C#
134 lines
3.1 KiB
C#
// /**
|
|
// * File: PDU.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using System.IO;
|
|
using ln.snmp.asn1;
|
|
namespace ln.snmp.types
|
|
{
|
|
public class PDU : AbstractSequence
|
|
{
|
|
public Integer RequestID { get; private set; }
|
|
public Integer Error { get; private set; }
|
|
public Integer ErrorIndex { get; private set; }
|
|
|
|
public Sequence VarBinds { get; private set; }
|
|
|
|
private Variable[] items;
|
|
|
|
public PDU(Identifier identifier)
|
|
: base(identifier)
|
|
{
|
|
//RequestID = new Integer(Environment.TickCount);
|
|
RequestID = new Integer(0xDEADBEEF);
|
|
Error = new Integer();
|
|
ErrorIndex = new Integer();
|
|
|
|
VarBinds = new Sequence();
|
|
|
|
items = new Variable[] { RequestID, Error, ErrorIndex, VarBinds };
|
|
}
|
|
|
|
public PDU(ASN1Value value)
|
|
: base(value.Identifier)
|
|
{
|
|
RequestID = (Integer)value.Items[0];
|
|
|
|
Error = (Integer)value.Items[1];
|
|
Error = (Integer)value.Items[2];
|
|
VarBinds = (Sequence)value.Items[3];
|
|
}
|
|
|
|
public override Variable[] Items
|
|
{
|
|
get => items;
|
|
set
|
|
{
|
|
RequestID = value[0] as Integer;
|
|
Error = value[1] as Integer;
|
|
ErrorIndex= value[2] as Integer;
|
|
VarBinds = value[3] as Sequence;
|
|
}
|
|
}
|
|
|
|
public override void Add(Variable item)
|
|
{
|
|
VarBinds.Add(item);
|
|
}
|
|
|
|
public override void Remove(Variable item)
|
|
{
|
|
VarBinds.Remove(item);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public class GetRequest : PDU
|
|
{
|
|
public GetRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x00))
|
|
{
|
|
}
|
|
public GetRequest(ASN1Value value)
|
|
: base(value)
|
|
{ }
|
|
|
|
}
|
|
public class GetNextRequest : PDU
|
|
{
|
|
public GetNextRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x01))
|
|
{
|
|
}
|
|
public GetNextRequest(ASN1Value value)
|
|
: base(value)
|
|
{ }
|
|
|
|
}
|
|
public class GetResponse : PDU
|
|
{
|
|
public GetResponse() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x02))
|
|
{
|
|
}
|
|
// public GetResponse(ASN1Value value)
|
|
//: base(value)
|
|
//{ }
|
|
|
|
}
|
|
public class GetBulkRequest : PDU
|
|
{
|
|
public Integer NonRepeaters => Error;
|
|
public Integer MaxRepetitions => ErrorIndex;
|
|
|
|
public GetBulkRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x05))
|
|
{
|
|
NonRepeaters.LongValue = 0;
|
|
MaxRepetitions.LongValue = 32;
|
|
}
|
|
|
|
}
|
|
public class SetRequest : PDU
|
|
{
|
|
public SetRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x03))
|
|
{
|
|
}
|
|
|
|
}
|
|
|
|
public class Report: PDU
|
|
{
|
|
public Report() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x08))
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
}
|