netkitty
Version:
Network tools kit
82 lines (81 loc) • 3.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EthernetII = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const NumberToHex_1 = require("../../helper/NumberToHex");
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
class EthernetII extends BaseHeader_1.BaseHeader {
constructor() {
super(...arguments);
this.SCHEMA = {
type: 'object',
properties: {
dmac: {
type: 'string',
minLength: 17,
maxLength: 17,
label: 'Destination',
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.MAC,
decode: () => {
this.instance.dmac.setValue(Array.from(this.readBytes(0, 6)).map(value => value.toString(16).padStart(2, '0')).join(':'));
},
encode: () => {
const dmac = this.instance.dmac
.getValue('00:00:00:00:00:00', (nodePath) => this.recordError(nodePath, 'Not Found'))
.toString()
.split(':')
.map((value) => parseInt(value, 16))
.map((value) => value ? value : 0);
this.writeBytes(0, Buffer.alloc(6, Buffer.from(dmac)));
}
},
smac: {
type: 'string',
minLength: 17,
maxLength: 17,
label: 'Source',
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.MAC,
decode: () => {
this.instance.smac.setValue(Array.from(this.readBytes(6, 6)).map(value => value.toString(16).padStart(2, '0')).join(':'));
},
encode: () => {
const smac = this.instance.smac
.getValue('00:00:00:00:00:00', (nodePath) => this.recordError(nodePath, 'Not Found'))
.toString()
.split(':')
.map((value) => parseInt(value, 16))
.map((value) => value ? value : 0);
this.writeBytes(6, Buffer.alloc(6, Buffer.from(smac)));
}
},
etherType: {
type: 'string',
minLength: 4,
maxLength: 4,
label: 'EtherType',
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
decode: () => {
this.instance.etherType.setValue(this.readBytes(12, 2).toString('hex').padStart(4, '0'));
},
encode: () => {
const etherType = this.instance.etherType.getValue((0, NumberToHex_1.UInt16ToHex)(0x0000), (nodePath) => this.recordError(nodePath, 'Not Found'));
const typeBuffer = Buffer.from(etherType, 'hex');
if (typeBuffer.length < 2)
typeBuffer.fill(0, 0, 1);
this.writeBytes(12, typeBuffer.subarray(0, 2));
}
}
}
};
this.id = 'eth';
this.name = 'Ethernet II';
this.nickname = 'ETH';
}
match() {
const specialScenes = ['trill', 'vxlan', 'nvgre', 'mpls', 'qinq', 'gre', 'geneve'];
if (this.prevCodecModule && !specialScenes.includes(this.prevCodecModule.id))
return false;
return true;
}
}
exports.EthernetII = EthernetII;