* @return a String consisting of all the authentication keys in the database
*/
String printKeys();
+
+ /**
+ * Print keys in cache in a human friendly format.
+ *
+ * @return a String consisting of all the keys in the cache
+ */
+ String prettyPrintKeys();
}
*/
String printKeys();
+ /**
+ * Print keys in cache in a human friendly format.
+ *
+ * @return a String consisting of all the keys in the cache
+ */
+ String prettyPrintKeys();
+
/**
* Set cluster master status.
*
*/
String printKeys();
+ /**
+ * Print keys in cache in a human friendly format.
+ *
+ * @return a String consisting of all the keys in the cache
+ */
+ String prettyPrintKeys();
+
/**
* Cleans all cached mappings.Used for testing.
*/
*/
String printKeys();
+ /**
+ * Print the full authentication key database in human readable form.
+ *
+ * @return the text to be printed on the Karaf console.
+ */
+ String prettyPrintKeys();
+
/**
* Add the default key "password" for the IPv4 prefix 0.0.0.0/0.
*/
return mappingSystem.printKeys();
}
+ @Override
+ public String prettyPrintKeys() {
+ return mappingSystem.prettyPrintKeys();
+ }
+
@Override
public void close() throws Exception {
LOG.info("Mapping Service is being destroyed!");
return mappingService.printKeys();
}
+ @Override
+ public String prettyPrintKeys() {
+ return mappingService.prettyPrintKeys();
+ }
+
@Override
public void addDefaultKeyIPv4() {
Eid eid = LispAddressUtil.toEid(new Ipv4Prefix("0.0.0.0/0"), null);
return akdb.printKeys();
}
+ @Override
+ public String prettyPrintKeys() {
+ return akdb.prettyPrintKeys();
+ }
+
public void cleanCaches() {
dao.removeAll();
buildMapCaches();
package org.opendaylight.lispflowmapping.lisp.authentication;
public enum LispKeyIDEnum {
- NONE(0, null),
+ NONE(0, "_NONE_"),
SHA1(1, "HmacSHA1"),
SHA256(2, "HmacSHA256"),
UNKNOWN(-1, null);
package org.opendaylight.lispflowmapping.lisp.util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
/**
public class Stringifier {
private static final String NEW_LINE = System.lineSeparator();
+ public static String getSpacesAsString(int length) {
+ return new String(new char[length]).replace("\0", " ");
+ }
+
+ public static String getString(MappingAuthkey key) {
+ return getString(key, 0);
+ }
+
+ public static String getString(MappingAuthkey key, int indentation) {
+ final String indent = getSpacesAsString(indentation);
+
+ StringBuilder masb = new StringBuilder(indent);
+ masb.append(key.getKeyString());
+ masb.append(" ");
+ masb.append(key.getKeyType());
+ return masb.toString();
+ }
+
public static String getString(MappingRecord mapping) {
return getString(mapping, 0);
}
public static String getString(MappingRecord mapping, int indentation) {
- final String indent = new String(new char[indentation]).replace("\0", " ");
+ final String indent = getSpacesAsString(indentation);
StringBuilder mrsb = new StringBuilder(indent);
}
public static String getString(LocatorRecord locator, int indentation) {
- final String indent = new String(new char[indentation]).replace("\0", " ");
+ final String indent = getSpacesAsString(indentation);
StringBuilder lrsb = new StringBuilder(indent);
String rloc = LispAddressStringifier.getString(locator.getRloc());
- int padLen = Constants.INET6_ADDRSTRLEN + 2 - rloc.length();
+ int padLen = Math.max(2, Constants.INET6_ADDRSTRLEN + 2 - rloc.length());
lrsb.append(rloc);
- lrsb.append(new String(new char[padLen]).replace("\0", " "));
+ lrsb.append(getSpacesAsString(padLen));
lrsb.append(locator.isRouted() ? "up " : "no-route ");
lrsb.append(locator.getPriority().toString());
lrsb.append('/');
public String printKeys() {
return LispMapCacheStringifier.printKeys(dao);
}
+
+ @Override
+ public String prettyPrintKeys() {
+ return LispMapCacheStringifier.prettyPrintKeys(dao);
+ }
}
import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber;
+import org.opendaylight.lispflowmapping.lisp.authentication.LispKeyIDEnum;
import org.opendaylight.lispflowmapping.lisp.type.MappingData;
import org.opendaylight.lispflowmapping.lisp.util.Constants;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.Stringifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
public class LispMapCacheStringifier {
public static String printKeys(ILispDAO dao) {
return sb.toString();
}
+ @SuppressWarnings("unchecked")
+ public static String prettyPrintKeys(ILispDAO dao) {
+ final StringBuffer sb = new StringBuffer();
+
+ 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();
+ }
+
public static String printFMCMappings(ILispDAO dao) {
final StringBuffer sb = new StringBuffer();
sb.append("Keys\tValues\n");
package org.opendaylight.lispflowmapping.shell;
import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
*/
@Command(scope = "mappingservice", name = "keys", description = "Print LISP authentication keys")
public class LispKeys extends OsgiCommandSupport {
+ @Option(name = "-d", aliases = "--debug", description = "Debug output", required = false, multiValued = false)
+ private boolean debug;
+
private IMappingServiceShell mappingServiceShell;
/*
@Override
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
protected Object doExecute() throws Exception {
- System.out.print(mappingServiceShell.printKeys());
+ if (debug) {
+ System.out.print(mappingServiceShell.printKeys());
+ } else {
+ System.out.print(mappingServiceShell.prettyPrintKeys());
+ }
return null;
}