import { emBin } from "../core/formatter" ; import { getAddressSpaceSize } from "./subnet-utils" ; export type OctetNumber = 1 | 2 | 3 | 4 ; export type NetworkClass = 'a' | 'b' | 'c' | 'd' | 'e' ; export class IpAddressWithSubnetMask { maskBits : number ; ipAddress : IpAddress ; constructor ( ipAddress , maskBits ) { this . ipAddress = ipAddress ; this . maskBits = maskBits ; } getAdressSpaceSize ( ) { return getAddressSpaceSize ( this . maskBits ) ; } toString ( ) { return `${ this . ipAddress . toString ( ) }/${ this . maskBits }` ; } } export class IpAddress { firstByte : number ; secondByte : number ; thirdByte : number ; fourthByte : number ; constructor ( firstByte , secondByte , thirdByte , fourthByte ) { this . firstByte = firstByte ; this . secondByte = secondByte ; this . thirdByte = thirdByte ; this . fourthByte = fourthByte ; } toString ( ) { return `${ this . firstByte }.${ this . secondByte }.${ this . thirdByte }.${ this . fourthByte }` ; } toBinaryString ( skipDots ? ) { if ( ! skipDots ) return `${ emBin ( this . firstByte ) }.${ emBin ( this . secondByte ) }.${ emBin ( this . thirdByte ) }.${ emBin ( this . fourthByte ) }` ; else return `${ emBin ( this . firstByte ) }${ emBin ( this . secondByte ) }${ emBin ( this . thirdByte ) }${ emBin ( this . fourthByte ) }` ; } clone ( ) { return new IpAddress ( this . firstByte , this . secondByte , this . thirdByte , this . fourthByte ) ; } setOctet ( octet , value ) { switch ( octet ) { case 1 : this . firstByte = value ; break ; case 2 : this . secondByte = value ; break ; case 3 : this . thirdByte = value ; break ; case 4 : this . fourthByte = value ; break ; } } } export class SubnetCommand { cidr : IpAddressWithSubnetMask ; constructor ( cidr ) { this . cidr = cidr ; } toString ( ) { return this . cidr . toString ( ) ; } } export class VpcCommand { cidr : IpAddressWithSubnetMask ; subnetBits : number ; constructor ( cidr ) { this . cidr = cidr ; this . subnetBits = 3 ; } toString ( ) { return this . cidr . toString ( ) ; } }