def decodeToken(self, decoderContext):
     try:
         util.log_info('newroutetargettokendecoder: Decode token')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(
             decoderContext)
         util.log_debug("BLOCK:", decoderhandler.getCurrentBlock())
         tokenText = decoderhandler.getTokenText()
         util.log_debug('Token text = %s' % (tokenText))
         value = decoderhandler.getValueAtCurrentIndex()
         util.log_debug('Value = %s' % (value))
         rtpattern1 = "\\d+:\\d+"
         rtpattern2 = "\\d+"
         block = decoderhandler.getCurrentBlock()
         lines = block.toString().split("\n")
         lines = [line.strip(' ') for line in lines]
         util.log_info("Lines : ", lines)
         for line in range(0, len(lines)):
             if re.search("^import route-target$", lines[line]):
                 for i in range(line + 1, len(lines)):
                     if re.search(rtpattern1, lines[i]):
                         decoderhandler.addTokenValue(
                             '../rt-import/rt-import', lines[i])
             if re.search("^export route-target$", lines[line]):
                 for i in range(line + 1, len(lines)):
                     if re.search(rtpattern1, lines[i]):
                         decoderhandler.addTokenValue(
                             '../rt-export/rt-export', lines[i])
             if ("route-target import " + value) in lines or (
                     "route-target export " + value) in lines:
                 if re.search(rtpattern1, value) or re.search(
                         rtpattern2, value):
                     decoderhandler.addTokenValue(tokenText, value)
     except Exception:
         traceback.print_exc()
Пример #2
0
 def decodeToken(self, dc):
     try:
         util.log_info(
             'CryptoProfileMatchIpAddressTokenDecoder: Decode token')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         tokenText = decoderhandler.getTokenText()
         util.log_debug('Token text = %s' % (tokenText))
         cursor = util.TokenCursor(None, -1, dc)
         ipAddress = cursor.getNextToken()
         util.log_debug('IpAddress = %s' % (ipAddress))
         cursor.advance()
         decoderhandler.addTokenValue(
             decoderutil.DecoderUtil().makeSiblingToken(
                 tokenText, "ip-address"), ipAddress)
         value = cursor.getNextToken()
         util.log_debug('Value = %s' % (value))
         if value is None:
             return decoderhandler.getSearchTokens().size(
             ) - decoderhandler.getCurrentIndex()
         if (InetAddressUtils.isIPv4Address(value)):
             decoderhandler.addTokenValue(
                 decoderutil.DecoderUtil().makeSiblingToken(
                     tokenText, "netmask"), value)
             cursor.advance()
             value = cursor.getNextToken()
         if value is not None:
             decoderhandler.addTokenValue(
                 decoderutil.DecoderUtil().makeSiblingToken(
                     tokenText, "vrf-name"), value)
         return decoderhandler.getSearchTokensSize(
         ) - decoderhandler.getCurrentIndex()
     except Exception:
         traceback.print_exc()
    def decodeToken(self, dc):
        try:
            util.log_info('RouteMapSetActionTokenDecoder: Decode token')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            if AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                           self.COMM_LIST):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "comm-list")
                tokenText = decoderhandler.getTokenText()
                value = decoderhandler.getValueAtCurrentIndex()
                decoderhandler.addTokenValue(tokenText,
                                             value.replace(' delete', ''))
                return 1

            ret = super(RouteMapSetActionTokenDecoder, self).decodeToken(dc)
            util.log_debug('The return value: = %s' % (ret))
            if (ret <= 0):
                return ret
            if AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                           self.AS_PATH_PREPEND):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "as-path prepend")
            elif AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                             self.VRF):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "vrf")
            elif AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                             self.PREFERENCE):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "local-preference")
            elif AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                             self.IP):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "ip")
            elif AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                             self.WEIGHT):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "weight")
            elif AnutaStringUtils.startsWith(decoderhandler.getSearchTokens(),
                                             self.COMMUNITY):
                setType = decoderutil.DecoderUtil().makeSiblingToken(
                    decoderhandler.getTokenText(), "set-type")
                util.log_debug('The SetType: = %s' % (setType))
                decoderhandler.addTokenValue(setType, "community")

            return ret
        except Exception:
            traceback.print_exc()
 def decodeToken(self, dc):
     try:
         util.log_info('SlaSourceIpTokenDecoder: Decode token')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         util.log_debug("TokenText : ", decoderhandler.getTokenText())
         tokenText = decoderhandler.getTokenText()
         tokenValue = decoderhandler.getValueAtCurrentIndex()
         util.log_info('Value = %s' % (tokenValue))
         decoderhandler.addTokenValue(tokenText, tokenValue)
         ##########
         # block = decoderhandler.getCurrentBlock()
         # lines = block.toString().split("\n")
         # lines = [line.strip(' ') for line in lines]
         # for each_line in lines:
         #     words = each_line.split(" ")
         #     for word in range(0, len(words)):
         #         if words[word] == "num-packets":
         #             decoderhandler.addTokenValue("num-packets", words[word+1])
         #         elif words[word] == "interval":
         #             decoderhandler.addTokenValue("interval", words[word+1])
         #         elif words[word] == "source-port":
         #             decoderhandler.addTokenValue("source-port", words[word+1])
         ##########
     except Exception:
         traceback.print_exc()
    def decodeVariables(self, cpc, dc, context):
        try:
            util.log_info(
                'RouterEigrpRedistVariableDecoder: Decoding variable')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            block = decoderhandler.getCurrentBlock()
            tokens = Joiner.on(" ").join(block.getTokens())
            tokens = tokens.split(" ")
            print tokens
            if "redistribute" not in tokens[0]:
                util.log_debug(
                    'Does not look like a valid redistribute. redistribute = %s'
                    % (tokens))
                return
            decoderhandler.addTokenValue("protocol", tokens[1])
            if tokens[1] == 'ospf':
                decoderhandler.addTokenValue("ospf-id", tokens[2])
            elif tokens[1] == 'eigrp' or tokens[1] == 'bgp':
                decoderhandler.addTokenValue("as-number", tokens[2])
            for i in range(1, len(tokens)):
                i += 1
                if tokens[i] == 'route-map':
                    decoderhandler.addTokenValue("route-map", tokens[i + 1])

                if tokens[i] == 'metric':
                    decoderhandler.addTokenValue("bandwidth-metric",
                                                 tokens[i + 1])
                    decoderhandler.addTokenValue("delay-metric", tokens[i + 2])
                    decoderhandler.addTokenValue("reliability-metric",
                                                 tokens[i + 3])
                    decoderhandler.addTokenValue("load-metric", tokens[i + 4])
                    decoderhandler.addTokenValue("mtu", tokens[i + 5])

        except Exception:
            traceback.print_exc()
    def decodeVariables(self,cpc,dc,context):
        try:
            util.log_info('RouterOspfRedistVariableDecoder: Decoding variable')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            block = decoderhandler.getCurrentBlock()
            tokens = Joiner.on(" ").join(block.getTokens())
            tokens = tokens.split(" ")
            print tokens
            if "redistribute" not in tokens[0]:
                util.log_debug('Does not look like a valid redistribute. redistribute = %s' % (tokens))
                return
            decoderhandler.addTokenValue("protocol", tokens[1])
            if tokens[1] == 'ospf':
                decoderhandler.addTokenValue("process-id-entry", tokens[2])
            elif tokens[1] == 'eigrp':
                decoderhandler.addTokenValue("eigrp-as-number", tokens[2])
            elif tokens[1] == 'bgp':
                decoderhandler.addTokenValue("bgp-as-number", tokens[2])
            for i in range(1,len(tokens)):
                i+=1
                if tokens[i] == "metric":
                    decoderhandler.addTokenValue("value1", tokens[i+1])
                if tokens[i] == "metric-type":
                    decoderhandler.addTokenValue("value2", tokens[i+1])
                if tokens[i] == 'route-map':
                    decoderhandler.addTokenValue("route-map", tokens[i+1])
                if tokens[i] == 'subnets':
                    decoderhandler.addTokenValue("subnet", "true")
                if tokens[i] == 'tag':
                    decoderhandler.addTokenValue("tag", tokens[i+1])
                    


        except Exception:
            traceback.print_exc()
Пример #7
0
 def parseSourceCondition(self, dc, cursor):
     util.log_info('AclTokenDecoder: parseSourceCondition')
     #print 'The decodercontext = %s' %(dc)
     srcCondition = Condition(cursor)
     self.setToken(dc, "source-condition-type", srcCondition.getType())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-condition-type'
     )
     self.setToken(dc, "source-obj-name", srcCondition.getObjectGroup())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-obj-name'
     )
     self.setToken(dc, "source-ip", srcCondition.getIpAddress())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-ip')
     self.setToken(dc, "source-mask", srcCondition.getMask())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-mask')
     self.setToken(dc, "source-port-operator", srcCondition.getOperator())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-port-operator'
     )
     self.setToken(dc, "source-port", srcCondition.getValue())
     util.log_debug(
         'Done setting AclTokenDecoder: parseSourceCondition: source-port')
     return srcCondition
Пример #8
0
 def parseHost(self, cursor):
     util.log_info('AclTokenDecoder: parseHost')
     if not cursor.hasNext():
         return
     self.ipaddress = cursor.getNextToken()
     cursor.advance()
     self.parseOperator(cursor)
Пример #9
0
 def parseType(self, cursor):
     util.log_info('AclTokenDecoder: parseType')
     if not cursor.hasNext():
         return
     next = cursor.getNextToken()
     util.log_debug('The Next token in parseType = %s' % (next))
     if "host" == next:
         self.type = "host"
         cursor.advance()
         util.log_debug('AclTokenDecoder: calling parseHost')
         self.parseHost(cursor)
     elif "object-group" == next:
         self.type = "objectgroup"
         cursor.advance()
         util.log_debug('AclTokenDecoder: calling parseObjectGroup')
         self.parseObjectGroup(cursor)
     elif "any" == next:
         self.type = "any"
         cursor.advance()
         util.log_debug('AclTokenDecoder: calling parseOperator')
         self.parseOperator(cursor)
     elif self.hasCidr(cursor):
         self.type = "cidr"
         util.log_debug('AclTokenDecoder: calling parseCidr')
         self.parseCidr(cursor)
     else:
         self.type = "host"
         util.log_debug('AclTokenDecoder: calling parseHost in else')
         self.parseHost(cursor)
Пример #10
0
 def decodeToken(self, dc):
     util.log_info('CryptoIkeEncryptionTypeTokenDecoder: Decode token')
     try:
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         tokenText = decoderhandler.getTokenText()
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 1)
         util.log_debug(
             'CryptoIkeEncryptionTypeTokenDecoder Token text = %s' %
             (tokenText))
         types = {
             "AES128": ["AES128", "aes", "aes 128"],
             "AES256": ["AES256", "aes 256"],
             "AES192": ["AES192", "aes 192"],
             "DES": ["DES", "des"],
             "3DES": ["3DES", "3des"]
         }
         value_1 = decoderhandler.getValueAtCurrentIndex()
         util.log_debug("value_1 is : ", value_1)
         cursor.advance()
         value_2 = cursor.getNextToken()
         util.log_debug("Value_2 is : ", value_2)
         if value_2 is not None:
             value = "%s %s" % (value_1, value_2)
             util.log_debug("Value is : ", value)
         else:
             value = value_1
             util.log_debug("Value is : ", value)
         for k, v in types.iteritems():
             if value in v:
                 util.log_debug("Key is : ", k)
                 break
         decoderhandler.addTokenValue(tokenText, k)
         util.log_debug("Key is : ", k)
     except Exception:
         traceback.print_exc()
    def decodeToken(self, dc):
        try:
            util.log_info('RouterEigrpAddFamilyTokenDecoder: Decode token')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            token = dc.getToken()
            searchTokens = dc.getSearchTokens()
            idx = dc.getCurrentIndex()
            name = searchTokens.get(idx)

            decoderhandler.addTokenValue(token.getText(), name)
            block = decoderhandler.getCurrentBlock()

            lines = block.toString().split("\n")
            lines = [line.strip(' ') for line in lines]
            nsf_pattern = '^nsf$'
            nsf_found = False
            topology_base_pattern = '^topology base$'
            topology_base_found = False
            summary_pattern = 'summary'
            summary_found = False
            redistributed_pattern = 'redistributed'
            redistributed_found = False

            for line in lines:
                nsf_match = re.search(nsf_pattern, line)
                if nsf_match is not None:
                    decoderhandler.addTokenValue("nsf", "true")
                    nsf_found = True

                topology_base_match = re.search(topology_base_pattern, line)
                if topology_base_match is not None:
                    decoderhandler.addTokenValue("topology-base", "true")
                    topology_base_found = True

                summary_match = re.search(summary_pattern, line)
                redistributed_match = re.search(redistributed_pattern, line)
                if summary_match is not None or redistributed_match is not None:
                    element = line.split(" ")
                    for j in range(3,len(element)):
                        if element[j] == 'summary':
                            decoderhandler.addTokenValue("summary", "true")
                            summary_found = True
                        elif element[j] == 'redistributed':
                            decoderhandler.addTokenValue("redistributed", "true")
                            redistributed_found = True
                        j+=1

            if not nsf_found:
                decoderhandler.addTokenValue("nsf", "false")
            if not topology_base_found:
                decoderhandler.addTokenValue("topology-base", "false")
            if not summary_found:
                decoderhandler.addTokenValue("summary", "false")
            if not redistributed_found:
                decoderhandler.addTokenValue("redistributed", "false")

            return 1
        except Exception:
            traceback.print_exc()
 def decodeVariables(self,cpc,dc,context):
     try:
         util.log_info('IpHttpTokenDecoder: Entering Variable Token Decoder for ip http server and ip http secure-server commands.')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0)
         self.parseIpHttp(dc, cursor)
     except Exception:
         traceback.print_exc()
 def decodeVariables(self,cpc,dc,context):
     try:
         util.log_info('CiscoRouterBGPAddressFamily: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0)
         self.parseAddressFamily(dc,cursor)
     except Exception:
             traceback.print_exc()
 def unregister(self, name):
     try:
         parser.unregister_reconciliation_preprocessor(name)
         util.log_info(
             'calling unregister reconciliation config provider for cisco version: %s'
             % (name))
     except AttributeError:
         pass
Пример #15
0
 def decodeVariables(self,cpc,dc,context):
     try:
         util.log_info('TacacsServerGroupVariableDecoder: Decode token for TACACS Server Group leaf value')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0)
         self.parseAAAServerGroup(dc, cursor);   
     except Exception:
         traceback.print_exc()
 def decodeVariables(self, cpc, dc, context):
     try:
         util.log_info('SnmpViewNameVariableDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0)
         self.parseSnmpViewName(dc, cursor)
     except Exception:
         traceback.print_exc()
    def decodeToken(self, dc):
        try:
            util.log_info('RouterEigrpAfIntTokenDecoder: Decode token')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            token = dc.getToken()
            searchTokens = dc.getSearchTokens()
            idx = dc.getCurrentIndex()
            name = searchTokens.get(idx)

            decoderhandler.addTokenValue(token.getText(), name)
            block = decoderhandler.getCurrentBlock()

            lines = block.toString().split("\n")
            lines = [line.strip(' ') for line in lines]
            passive_pattern = '^passive-interface$'
            no_passive_pattern = '^no passive-interface$'
            split_horizon_pattern = '^split-horizon$'
            no_split_horizon_pattern = '^no split-horizon$'
            stub_site_pattern = '^stub-site wan-interface$'
            stub_site_found = False
            split_horizon_found = False
            no_split_horizon_found = False

            for line in lines:
                passive_match = re.search(passive_pattern, line)
                if passive_match is not None:
                    decoderhandler.addTokenValue("passive-interface", "true")

                no_passive_match = re.search(no_passive_pattern, line)
                if no_passive_match is not None:
                    decoderhandler.addTokenValue("passive-interface", "false")

                split_horizon_match = re.search(split_horizon_pattern, line)
                if split_horizon_match is not None:
                    decoderhandler.addTokenValue("split-horizon", "true")
                    split_horizon_found = True

                no_split_horizon_match = re.search(no_split_horizon_pattern, line)
                if no_split_horizon_match is not None:
                    decoderhandler.addTokenValue("split-horizon", "false")
                    no_split_horizon_found = True

                stub_site_match = re.search(stub_site_pattern, line)
                if stub_site_match is not None:
                    decoderhandler.addTokenValue("stub-site", "true")
                    stub_site_found = True

            if not stub_site_found:
                decoderhandler.addTokenValue("stub-site", "false")

            if not split_horizon_found and not no_split_horizon_found:
                decoderhandler.addTokenValue("split-horizon", "true")

            return 1
        except Exception:
            traceback.print_exc()
    def decodeVariables(self, cpc, dc, context):
        try:
	    util.log_info('ServiceTimeStampsVariableDecoder: Decoding variable')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
	    cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0)
	    parse = parseServiceTimestamps(dc, cursor)
	    parse.is_false()
	    parse.field_value()
        except Exception:
            traceback.print_exc()
 def decodeVariables(self,cpc,dc,context):
     try:
         util.log_info('ObjectGroupVariableDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         if AnutaStringUtils.startsWith(decoderhandler.getCurrentBlockTokens(), self.OBJECT_LIST):
            self.processAccessList(cpc, dc, context, decoderhandler.getCurrentBlock())
            return
         self.processNetwork(cpc, dc, context, decoderhandler.getCurrentBlock())
     except Exception:
         traceback.print_exc()
 def decodeVariables(self, cpc, dc, context):
     try:
         util.log_info('ClassMapVariableTokenDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0, None)
         self.parseName(dc,cursor)
         self.parseDescription(dc,cursor)
         self.parseotherbooleans(dc,cursor)
     except Exception:
         traceback.print_exc()
Пример #21
0
 def decodeVariables(self, cpc, dc, context):
     try:
         util.log_info('TransformSetVariableDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0,
                                   None)
         self.parseTransformset(dc, cursor)
         self.parseIpsecEncryptionType(dc, cursor)
     except Exception:
         traceback.print_exc()
 def processService(self, cpc, dc, context, block):
     util.log_debug('ObjectGroupServiceVariableDecoder: processNetwork')
     compare = ['eq', 'lt', 'gt', 'range']
     ip_protocol_list = [
         'ahp', 'eigrp', 'esp', 'gre', 'icmp', 'igmp', 'ip', 'ipinip',
         'nos', 'ospf', 'pcp', 'pim'
     ]
     decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
     lines = block.toString().split("\n")
     lines = [line.strip(' ') for line in lines]
     util.log_info('BLOCK for obj service:', block)
     for line in lines:
         words = line.split(' ')
         if words[0].isdigit():
             decoderhandler.addTokenValue("name", words[0])
             decoderhandler.addTokenValue("ip-protocol", words[0])
             return
         elif words[0] in ip_protocol_list:
             decoderhandler.addTokenValue("name", words[0])
             decoderhandler.addTokenValue("protocol", words[0])
             return
         elif words[0] == 'group-object':
             util.log_debug('ObjectGroup')
         else:
             if InetAddressUtils.isIPv4Address(
                     words[0]) or words[0] == 'host':
                 return
             decoderhandler.addTokenValue("protocol", words[0])
         if len(words) - 1 >= 1:
             if words[1] == 'source':
                 decoderhandler.addTokenValue("operation", words[1])
                 if words[2] in compare:
                     decoderhandler.addTokenValue("compare", words[2])
                     decoderhandler.addTokenValue("port", words[3])
                 if words[2] == 'range':
                     decoderhandler.addTokenValue("end-port", words[4])
                 decoderhandler.addTokenValue(
                     "name",
                     Joiner.on(" ").join(block.getTokens()))
             elif words[1] in compare:
                 decoderhandler.addTokenValue("compare", words[1])
                 decoderhandler.addTokenValue("port", words[2])
                 if words[1] == 'range':
                     decoderhandler.addTokenValue("end-port", words[3])
                 decoderhandler.addTokenValue(
                     "name",
                     Joiner.on(" ").join(block.getTokens()))
             else:
                 if words[0] == 'group-object':
                     decoderhandler.addTokenValue("group-object", words[1])
                 else:
                     decoderhandler.addTokenValue("port", words[1])
                     decoderhandler.addTokenValue(
                         "name",
                         Joiner.on(" ").join(block.getTokens()))
 def decodeToken(self, dc):
     try:
         util.log_info('EfpEncapsulationTokenDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         util.log_debug("Block is : ",decoderhandler.getCurrentBlock())
         tokenText = decoderhandler.getTokenText()
         util.log_debug("Text :",tokenText)
         tokenValue = decoderhandler.getValueAtCurrentIndex()
         util.log_debug("Value :",tokenValue)
     except Exception:
         traceback.print_exc()
Пример #24
0
 def parseDestCondition(self, dc, cursor):
     util.log_info('AclTokenDecoder: parseDestCondition')
     #print 'The decodercontext = %s' %(dc)
     destCondition = Condition(cursor)
     self.setToken(dc, "dest-condition-type", destCondition.getType())
     self.setToken(dc, "dest-obj-name", destCondition.getObjectGroup())
     self.setToken(dc, "dest-ip", destCondition.getIpAddress())
     self.setToken(dc, "dest-mask", destCondition.getMask())
     self.setToken(dc, "dest-port-operator", destCondition.getOperator())
     self.setToken(dc, "dest-port", destCondition.getValue())
     return destCondition
Пример #25
0
    def decodeToken(self, dc):
        try:
            util.log_info('PolicyMapRandomTokenDecoder: Decode token')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            token = dc.getToken()
            searchTokens = dc.getSearchTokens()
            idx = dc.getCurrentIndex()
            name = searchTokens.get(idx)

            decoderhandler.addTokenValue(token.getText(), name)
            block = decoderhandler.getCurrentBlock()

            lines = block.toString().split("\n")
            lines = [line.strip(' ') for line in lines]
            detect_pattern = '^random-detect$'
            dscp_tunnel_pattern = '^set dscp tunnel'
            police_rate_percent_pattern = '^police rate percent'
            set_dscp_pattern = '^set dscp'
            police_rate_percent_found = False
            dscp_tunnel_found = False
            set_dscp_found = False

            for line in lines:
                detect_match = re.search(detect_pattern, line)
                if detect_match is not None:
                    decoderhandler.addTokenValue("random-detect", "default")

                dscp_tunnel_match = re.search(dscp_tunnel_pattern, line)
                if dscp_tunnel_match is not None:
                    decoderhandler.addTokenValue("is-dscp-tunnel", "true")
                    dscp_tunnel_found = True

                police_rate_percent_match = re.search(
                    police_rate_percent_pattern, line)
                if police_rate_percent_match is not None:
                    police_rate_percent_found = True

                set_dscp_match = re.search(set_dscp_pattern, line)
                if set_dscp_match is not None:
                    set_dscp_found = True
                    dscp_value = line.split(' ')[-1]

            if not dscp_tunnel_found:
                decoderhandler.addTokenValue("is-dscp-tunnel", "false")

            if police_rate_percent_found:
                decoderhandler.addTokenValue("bit-rate", "")

            if set_dscp_found:
                decoderhandler.addTokenValue("dscp-value", dscp_value)

            return 1
        except Exception:
            traceback.print_exc()
Пример #26
0
 def decodeVariables(self, cpc, dc, context):
     try:
         util.log_info('ClassMapHttpUrlVariableTokenDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         cursor = util.TokenCursor(decoderhandler.getSearchTokens(), 0, None)
         self. parseMatchTypeandName(dc, cursor)
         self.parseConditionType(dc, cursor)
         self.parseMatchValue(dc, cursor)
         self.parseUrl(dc, cursor)
     except Exception:
         traceback.print_exc()
    def decodeVariables(self, cpc, dc, context):
        try:
            util.log_info('PfrClassVariableTokenDecoder: Entering.')
            decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
            block = decoderhandler.getCurrentBlock()
            util.log_info("BLOCK FOR PFR DECODER:", block)
            lines = block.toString().split("\n")
            lines = [line.strip(' ') for line in lines]

        except Exception:
            traceback.print_exc()
 def decodeToken(self, dc):
     try:
         util.log_info('TimeStampsTokenDecoder: Decode token for name and timestamp option leaf')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         tokenText = decoderhandler.getTokenText()
         currenttokenText = decoderhandler.getCurrentBlockTokens()
         value = decoderhandler.getValueAtCurrentIndex()
         decoderhandler.addTokenValue(tokenText, value)
         decoderhandler.addTokenValue('legacy-netflow', "true")
     except Exception:
         traceback.print_exc()
Пример #29
0
 def decodeToken(self, dc):
     try:
         util.log_info('EfpServiceInstanceTokenDecoder: Decoding variable')
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         util.log_debug("Block is : ", decoderhandler.getCurrentBlock())
         tokenText = decoderhandler.getTokenText()
         util.log_debug("Text :", tokenText)
         tokenValue = decoderhandler.getValueAtCurrentIndex()
         util.log_debug("Value :", tokenValue)
         decoderhandler.addTokenValue(tokenText, tokenValue)
         current_block = decoderhandler.getCurrentBlock().toString()
         block_tokens = str(current_block).split(" ")
         util.log_debug("Block_Tokens : ", block_tokens)
         command_block = []
         for cmds in block_tokens:
             command_block.append(cmds.strip("\n"))
         util.log_debug("command_block : ", command_block)
         if 'trunk' in command_block:
             decoderhandler.addTokenValue("$trunk", "true")
         else:
             decoderhandler.addTokenValue("$trunk", "false")
         if 'symmetric' in command_block:
             decoderhandler.addTokenValue("$symmetric", "true")
         else:
             decoderhandler.addTokenValue("$symmetric", "false")
         if "encapsulation" in block_tokens:
             i = command_block.index("encapsulation")
             encap_type_list = [
                 'default', 'dot1ad', 'dot1q', 'priority-tagged', 'untagged'
             ]
             encap_type = command_block[i + 1]
             if encap_type in encap_type_list:
                 decoderhandler.addTokenValue("$encapsulation-type",
                                              encap_type)
             if 'add' in command_block:
                 vlanid = command_block[i + 3]
                 decoderhandler.addTokenValue("$vlan-id", vlanid)
             else:
                 vlanid = command_block[i + 2]
                 decoderhandler.addTokenValue("$vlan-id", vlanid)
         if "description" in block_tokens:
             description_tokens = [
                 cmds.strip() for cmds in str(current_block).split("\n")
             ]
             desc_pattern = '^description'
             for i in range(len(description_tokens)):
                 if re.search(desc_pattern, description_tokens[i]):
                     desc_token = description_tokens[i].split("description")
                     desc_block = desc_token[1].strip()
                     decoderhandler.addTokenValue("$description",
                                                  desc_block)
     except Exception:
         traceback.print_exc()
Пример #30
0
 def decodeToken(self, dc):
     try:
         util.log_info('ClockTimezoneTokenDecoder: Decoding token')
         util.log_info('DC Value: %s' % dc)
         decoderhandler = tokendecoderhandler.TokenDecoderHandler(dc)
         block = decoderhandler.getCurrentBlock()
         if 'clock' not in str(block):
             decoderhandler.addTokenValue("timezone", "UTC")
             return
     except Exception:
         decoderhandler.addTokenValue("timezone", "UTC")
         traceback.print_exc()