Search in sources :

Example 6 with IRowVisitor

use of org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method printMTMCMappings.

public static String printMTMCMappings(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    sb.append("Keys\tValues\n");
    final IRowVisitor innerVisitor = (new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("\n" + key + "\t");
            }
            sb.append(valueKey + "=" + value + "\t");
            lastKey = key;
        }
    });
    final IRowVisitor vniVisitor = (new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append(key + "\t");
            }
            if ((valueKey.equals(SubKeys.LCAF_SRCDST))) {
                sb.append(valueKey + "= { ");
                ((ILispDAO) value).getAll(innerVisitor);
                sb.append("}\t");
            } else {
                sb.append(valueKey + "=" + value + "\t");
            }
            lastKey = key;
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("\n" + key + "\t");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                sb.append(valueKey + "= { ");
                ((ILispDAO) value).getAll(vniVisitor);
                sb.append("}\t");
            } else {
                sb.append(valueKey + "=" + value + "\t");
            }
            lastKey = key;
        }
    });
    sb.append("\n");
    return sb.toString();
}
Also used : IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)

Example 7 with IRowVisitor

use of org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor in project lispflowmapping by opendaylight.

the class SimpleMapCache method getXtrIdMappingList.

// Returns the list of mappings stored in an xTR-ID DAO
private List<Object> getXtrIdMappingList(ILispDAO lispDAO) {
    if (lispDAO != null) {
        final List<Object> records = new ArrayList<>();
        lispDAO.getAll(new IRowVisitor() {

            public void visitRow(Object keyId, String valueKey, Object value) {
                if (valueKey.equals(SubKeys.RECORD)) {
                    records.add(value);
                }
            }
        });
        return records;
    }
    return null;
}
Also used : IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) ArrayList(java.util.ArrayList)

Example 8 with IRowVisitor

use of org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method prettyPrintMTMCMappings.

@SuppressWarnings("unchecked")
public static String prettyPrintMTMCMappings(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    final IRowVisitor mappingVisitor = (new IRowVisitor() {

        public void visitRow(Object keyId, String valueKey, Object value) {
            switch(valueKey) {
                case SubKeys.RECORD:
                    MappingData md = (MappingData) value;
                    sb.append(Stringifier.getString(md.getRecord(), 2));
                    sb.append("\n");
                    break;
                case SubKeys.SUBSCRIBERS:
                    Set<Subscriber> subscribers = (Set<Subscriber>) value;
                    sb.append(prettyPrintSubscriberSet(subscribers, 4));
                    sb.append("\n");
                    break;
                case SubKeys.LCAF_SRCDST:
                    ((ILispDAO) value).getAll(this);
                    break;
                default:
                    break;
            }
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("Instance ID " + keyId + "\n");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                ((ILispDAO) value).getAll(mappingVisitor);
            }
            lastKey = key;
        }
    });
    return sb.toString();
}
Also used : IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) Set(java.util.Set) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 9 with IRowVisitor

use of org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor in project lispflowmapping by opendaylight.

the class LispMapCacheStringifier method prettyPrintKeys.

@SuppressWarnings("unchecked")
public static String prettyPrintKeys(ILispDAO dao) {
    final StringBuilder sb = new StringBuilder();
    final IRowVisitor innerVisitor = (new IRowVisitor() {

        public void visitRow(Object keyId, String valueKey, Object value) {
            switch(valueKey) {
                case SubKeys.AUTH_KEY:
                    String eid = LispAddressStringifier.getString((Eid) keyId);
                    sb.append("     ");
                    sb.append(eid);
                    int padLen = Math.max(2, Constants.INET6_ADDRSTRLEN - eid.length());
                    sb.append(Stringifier.getSpacesAsString(padLen));
                    MappingAuthkey authKey = (MappingAuthkey) value;
                    String hmac = LispKeyIDEnum.valueOf(authKey.getKeyType().shortValue()).getAuthenticationName();
                    sb.append(hmac);
                    sb.append(Stringifier.getSpacesAsString(Math.max(2, 22 - hmac.length())));
                    sb.append(authKey.getKeyString());
                    sb.append("\n");
                    break;
                default:
                    break;
            }
        }
    });
    dao.getAll(new IRowVisitor() {

        String lastKey = "";

        public void visitRow(Object keyId, String valueKey, Object value) {
            String key = keyId.getClass().getSimpleName() + "#" + keyId;
            if (!lastKey.equals(key)) {
                sb.append("Instance ID " + keyId + "\n");
                sb.append("  -> EID                                           HMAC Algorithm        Shared Key\n");
            }
            if (valueKey.equals(SubKeys.VNI)) {
                ((ILispDAO) value).getAll(innerVisitor);
            }
            lastKey = key;
        }
    });
    return sb.toString();
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) IRowVisitor(org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)

Aggregations

IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)9 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)3 Set (java.util.Set)2 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)2 ArrayList (java.util.ArrayList)1 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)1 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)1