ln.snmp/types/PDU.cs

104 lines
2.5 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;
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);
Error = new Integer();
ErrorIndex = new Integer();
VarBinds = new Sequence();
items = new Variable[] { RequestID, Error, ErrorIndex, VarBinds };
}
public override Variable[] Items => items;
public override void Add(Variable item)
{
VarBinds.Add(item);
}
public override void Remove(Variable item)
{
VarBinds.Remove(item);
}
public override byte[] Bytes
{
set
{
MemoryStream bytes = new MemoryStream(value);
RequestID = Variable.Read(bytes) as Integer;
Error = Variable.Read(bytes) as Integer;
ErrorIndex = Variable.Read(bytes) as Integer;
VarBinds = Variable.Read(bytes) as Sequence;
}
}
}
public class GetRequest : PDU
{
public GetRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x00))
{
}
}
public class GetNextRequest : PDU
{
public GetNextRequest() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x01))
{
}
}
public class GetResponse : PDU
{
public GetResponse() : base(new Identifier(IdentifierClass.CONTEXT, true, 0x02))
{
}
}
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))
{
}
}
}