netkitty
Version:
Network tools kit
178 lines (177 loc) • 8.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IPv6 = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const NumberToHex_1 = require("../../helper/NumberToHex");
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
const BufferToNumber_1 = require("../../helper/BufferToNumber");
const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
const BufferToIP_1 = require("../../helper/BufferToIP");
const IPToBuffer_1 = require("../../helper/IPToBuffer");
class IPv6 extends BaseHeader_1.BaseHeader {
constructor() {
super(...arguments);
this.SCHEMA = {
type: 'object',
properties: {
version: {
type: 'integer',
label: 'Version',
minimum: 0,
maximum: 15,
decode: () => {
this.instance.version.setValue(this.readBits(0, 1, 0, 4));
},
encode: () => {
const version = this.instance.version.getValue(6, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.version.setValue(version);
this.writeBits(0, 1, 0, 4, version);
}
},
tclass: {
type: 'object',
label: 'Traffic Class',
properties: {
dscp: {
type: 'integer',
minimum: 0,
maximum: 63,
label: 'Differentiated Services Codepoint',
decode: () => {
this.instance.tclass.dscp.setValue(this.readBits(0, 4, 4, 6));
},
encode: () => {
const dscp = this.instance.tclass.dscp.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.tclass.dscp.setValue(dscp);
this.writeBits(0, 4, 4, 6, dscp);
}
},
ecn: {
type: 'integer',
label: 'Explicit Congestion Notification',
minimum: 0,
maximum: 3,
decode: () => {
this.instance.tclass.ecn.setValue(this.readBits(0, 4, 10, 2));
},
encode: () => {
const ecn = this.instance.tclass.ecn.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.tclass.ecn.setValue(ecn);
this.writeBits(0, 4, 10, 2, ecn);
}
}
}
},
flow: {
type: 'integer',
label: 'Flow Label',
minimum: 0,
maximum: 1048575,
decode: () => {
this.instance.flow.setValue(this.readBits(1, 3, 4, 20));
},
encode: () => {
const flow = this.instance.flow.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.flow.setValue(flow);
this.writeBits(1, 3, 4, 20, flow);
}
},
plen: {
type: 'integer',
label: 'Payload Length',
minimum: 0,
maximum: 65535,
decode: () => {
this.instance.plen.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(4, 2)));
},
encode: () => {
const plen = this.instance.plen.getValue(0);
this.instance.plen.setValue(plen);
this.writeBytes(4, (0, NumberToBuffer_1.UInt16ToBuffer)(plen));
if (!plen) {
this.addPostPacketEncodeHandler(() => {
let startCount = false;
let totalLength = 0;
this.codecModules.forEach((codecModule) => {
if (codecModule === this)
startCount = true;
if (startCount)
totalLength += codecModule.length;
});
let payloadLength = totalLength - 40;
//The length is set to zero when a Hop-by-Hop extension header carries a Jumbo Payload option
if (payloadLength > 65535)
payloadLength = 0;
this.instance.plen.setValue(payloadLength);
this.writeBytes(4, (0, NumberToBuffer_1.UInt16ToBuffer)(payloadLength));
});
}
}
},
nxt: {
type: 'integer',
label: 'Next Header',
minimum: 0,
maximum: 255,
decode: () => {
this.instance.nxt.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(6, 1)));
},
encode: () => {
const nxt = this.instance.nxt.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.nxt.setValue(nxt);
this.writeBytes(6, (0, NumberToBuffer_1.UInt8ToBuffer)(nxt));
}
},
hllm: {
type: 'integer',
label: 'Hop Limit',
minimum: 0,
maximum: 255,
decode: () => {
this.instance.hllm.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(7, 1)));
},
encode: () => {
const hllm = this.instance.hllm.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.hllm.setValue(hllm);
this.writeBytes(7, (0, NumberToBuffer_1.UInt8ToBuffer)(hllm));
}
},
sip: {
type: 'string',
label: 'Source Address',
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.IPv6,
decode: () => {
this.instance.sip.setValue((0, BufferToIP_1.BufferToIPv6)(this.readBytes(8, 16)));
},
encode: () => {
const sip = this.instance.sip.getValue('0000:0000:0000:0000:0000:0000:0000:0000', (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.sip.setValue(sip);
this.writeBytes(8, (0, IPToBuffer_1.IPv6ToBuffer)(sip));
}
},
dip: {
type: 'string',
label: 'Destination Address',
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.IPv6,
decode: () => {
this.instance.dip.setValue((0, BufferToIP_1.BufferToIPv6)(this.readBytes(24, 16)));
},
encode: () => {
const dip = this.instance.dip.getValue('0000:0000:0000:0000:0000:0000:0000:0000', (nodePath) => this.recordError(nodePath, 'Not Found'));
this.instance.dip.setValue(dip);
this.writeBytes(24, (0, IPToBuffer_1.IPv6ToBuffer)(dip));
}
}
}
};
this.id = 'ipv6';
this.name = 'Internet Protocol Version 6';
this.nickname = 'IPv6';
}
match() {
if (!this.prevCodecModule)
return false;
return this.prevCodecModule.instance.etherType.getValue() === (0, NumberToHex_1.UInt16ToHex)(0x86dd);
}
}
exports.IPv6 = IPv6;