Beispiel #1
0
def prepareRequestData(msgId, req, secret):
    r = Request()

    r['callflow-id'] = req['callflow-id']

    for k in ('snmp-engine-id', 'snmp-transport-domain', 'snmp-peer-address',
              'snmp-peer-port', 'snmp-bind-address', 'snmp-bind-port',
              'snmp-security-model', 'snmp-security-level',
              'snmp-security-name', 'snmp-context-engine-id',
              'snmp-context-name', 'snmp-credentials-id', 'snmp-context-id',
              'snmp-content-id', 'snmp-peer-id'):
        r[k] = req[k]

    r['snmp-pdu'] = encoder.encode(req['snmp-pdu'])

    msg = Message()
    msg['version'] = PROTOCOL_VERSION
    msg['msg-id'] = msgId
    msg['content-id'] = 'request'

    if secret:
        msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
    else:
        msg['payload'] = encoder.encode(r)

    return encoder.encode(msg)
Beispiel #2
0
def prepareAnnouncementData(trunkId, secret):
    r = Announcement()
    r['trunk-id'] = trunkId

    msg = Message()
    msg['version'] = PROTOCOL_VERSION
    msg['msg-id'] = 0
    msg['content-id'] = 'announcement'
    msg['payload'] = encoder.encode(r)
    if secret:
        msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
    else:
        msg['payload'] = encoder.encode(r)
    return encoder.encode(msg)
Beispiel #3
0
def prepareResponseData(msgId, rsp, secret):
    r = Response()
    r['error-indication'] = str(rsp.get('error-indication', ''))
    r['snmp-pdu'] = rsp['snmp-pdu'] and encoder.encode(rsp['snmp-pdu']) or ''

    msg = Message()
    msg['version'] = PROTOCOL_VERSION
    msg['msg-id'] = msgId
    msg['content-id'] = 'response'
    msg['payload'] = encoder.encode(r)
    if secret:
        msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
    else:
        msg['payload'] = encoder.encode(r)
    return encoder.encode(msg)
Beispiel #4
0
def _preparePingPongData(reqType, msgId, serial, secret):
    msg = Message()
    msg['version'] = PROTOCOL_VERSION
    msg['msg-id'] = msgId
    msg['content-id'] = reqType

    if msg['content-id'] == MSG_TYPE_PING:
        r = Ping()
    elif msg['content-id'] == MSG_TYPE_PONG:
        r = Pong()
    else:
        raise SnmpfwdError('not a ping-pong message')

    r['serial'] = serial

    msg['payload'] = encoder.encode(r)
    if secret:
        msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
    else:
        msg['payload'] = encoder.encode(r)
    return encoder.encode(msg)