def getRecord(self, index): checkInteger('index', index) maxIndex = len(self.records) - 1 if (index < 0 or index > maxIndex): raise Exception( 'Out of range index(%d) must be between 0 and length-1(%d)' % (index, maxIndex)) return (self.records[index])
def addDomainId(self, exporterId, obsDomainId): checkInteger('exporterId', exporterId, 0) checkInteger('obsDomainId', obsDomainId, 0) exporter = self.__exporters.get(exporterId, None) if (exporter is None): raise Exception('Exporter(%d) does not exist' % (exporterId)) session = exporter.getSession() session.getDomain(obsDomainId)
def addTemplate(self, exporterId, obsDomainId, template): checkInteger('exporterId', exporterId, 0) checkInteger('obsDomainId', obsDomainId, 0) exporter = self.__exporters.get(exporterId, None) if (exporter is None): raise Exception('Exporter(%d) does not exist' % (exporterId)) session = exporter.getSession() if (not session.hasDomain(obsDomainId)): raise Exception('Exporter(%d) does not has domain(%d)' % (exporterId, obsDomainId)) domain = session.getDomain(obsDomainId) domain.updateExporterTemplate(template)
def create(cls, templateId, fields): checkInteger('templateId', templateId, 1) checkType('fields', (list,), fields) for field in fields: checkType('field', (FieldSpecifier,), field) obj = cls() obj.templateId = templateId obj.fields = fields obj.fieldCount = len(obj.fields) return(obj)
def add(self, exporterId, serverIP, serverPort): checkInteger('exporterId', exporterId, 0) checkIPv4('serverIP', serverIP) checkPort('serverPort', serverPort) if (exporterId in self.__exporters): raise Exception('Exporter(%d) already exists' % (exporterId)) exporterConfig = copy.deepcopy(self.__configTemplate) exporterConfig.update({'serverIP': serverIP, 'serverPort': serverPort}) session = Session() exporter = Exporter(session) exporter.configure(exporterConfig) exporter.start() self.__exporters[exporterId] = exporter
def createDataSet(cls, domain, setId): checkType('domain', (ObservationDomain, ), domain) checkInteger('setId', setId) if ((setId == 0) or (setId == 1)): raise Exception('Unusable SetId(%d)' % setId) if (setId == 2): raise Exception('SetId(%d) can only be used in TemplateSets' % setId) if (setId == 3): raise Exception( 'SetId(%d) can only be used in OptionTemplateSets' % setId) if ((setId >= 4) and (setId <= 255)): raise Exception('Reserved SetId(%d)' % setId) if (not domain.hasExporterTemplate(setId)): raise Exception( 'Domain(%d) does not contain Exporter Template(%d)' % (domain.obsDomainId, setId)) obj = cls() obj.setId = setId obj.setType = 'data' return (obj)
def checkJSON(field): id_ = checkAttr('id', field) checkInteger('id', id_, 1, 2**15 - 1) pen = None if ('pen' in field): pen = checkAttr('pen', field) checkInteger('pen', pen, 1, 2**32 - 1) name = checkAttr('name', field) fieldInfo = getIANAFieldById(id_) if ( pen is None) else getPENFieldById(id_, pen) fieldName = fieldInfo[1]['name'] if (name != fieldName): raise Exception('Field name(%s) does not match id(%d)' % (name, id_)) length = None if ('length' in field): length = checkAttr('length', field) checkInteger('length', length, 1) type_ = checkAttr('type', field) getStructForType(ie_type=type_, fieldName=name, length=length) return (id_, pen, name, length, type_)
def checkConfiguration(config): checkType('config', (dict, ), config) templatesDefinitionsFile = checkAttr('definitionsFile', config) if (not os.path.isfile(templatesDefinitionsFile)): raise Exception('templatesDefinitionsFile(%s) does not exist' % templatesDefinitionsFile) templatesDefinitions = json.loads(readFile(templatesDefinitionsFile)) for strTemplateId, templateAttr in templatesDefinitions.iteritems(): checkRegex('templateId', '[0-9]+', strTemplateId) checkInteger('templateId', int(strTemplateId), 256, 65535) checkType('templateAttr', (dict, ), templateAttr) fields = checkAttr('fields', templateAttr) checkType('fields', (list, ), fields) for field in fields: checkType('field', (dict, ), field) name = checkAttr('name', field) checkRegex('name', '[a-zA-Z0-9]+', name) enterprise = checkAttr('enterprise', field) checkRegex('enterprise', '[a-zA-Z0-9]+', enterprise) pen = pen_alias.get(enterprise) length = field.get('length') checkInteger('length', length, minValue=1, maxValue=VARIABLE_LENGTH, allowNone=True) if (pen is None): raise Exception('Unknown Enterprise Alias(%s)' % enterprise) if (pen == -1): FieldSpecifier.newIANA(name, length) else: FieldSpecifier.newEnterprise(name, pen, length)
def checkConfiguration(config): checkType('config', (dict, ), config) checkIPv4('listenIP', checkAttr('listenIP', config)) checkPort('listenPort', checkAttr('listenPort', config)) checkInteger('numWorkers', checkAttr('numWorkers', config), 1)
def get(self, exporterId): checkInteger('exporterId', exporterId, 0) exporter = self.__exporters.get(exporterId, None) if (exporter is None): raise Exception('Exporter(%d) does not exist' % (exporterId)) return (exporter)
def has(self, exporterId): checkInteger('exporterId', exporterId, 0) return (exporterId in self.__exporters)
def remove(self, exporterId): checkInteger('exporterId', exporterId, 0) if (exporterId not in self.__exporters): raise Exception('Exporter(%d) does not exist' % (exporterId)) del self.__exporters[exporterId]
'tunnelSourceIPv4Address': lambda v: str(v), 'tunnelDestinationIPv4Address': lambda v: str(v), 'direction': lambda v: str(v), 'ber': lambda v: float(v), 'rxPowerMilliwatts': lambda v: float(v), 'txPowerMilliwatts': lambda v: float(v), 'rxPowerDecibelMilliwatts': lambda v: float(v), 'txPowerDecibelMilliwatts': lambda v: float(v), 'frequencyGigaHertz': lambda v: float(v), 'stlPaginationIndex': lambda v: int(v), 'stlPaginationTotal': lambda v: int(v), } __FIELD_CHECKERS = { 'timeStamp': lambda v: checkInteger('timeStamp', v, 0), 'name': lambda v: checkString('name', v), 'containerName': lambda v: checkString('containerName', v), 'observationDomainId': lambda v: checkInteger('observationDomainId', v, 0, 4294967295), 'observationPointId': lambda v: checkInteger('observationPointId', v, 0), 'flowDirection': lambda v: checkOptions('flowDirection', v, ['ingress', 'egress']), 'sourceMacAddress': lambda v: checkMACAddr('sourceMacAddress', v), 'destinationMacAddress': lambda v: checkMACAddr('destinationMacAddress', v), 'ethernetType':
def getField(self, index): checkInteger('index', index, 0, self.fieldCount) return(self.fields[index])
def newFromJSON(cls, templateId, fields): checkInteger('templateId', templateId, 1) fields_ = TemplateRecord.checkJSON(fields) return(TemplateRecord.create(templateId, fields_))