2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bmp.impl.app;
10 import java.nio.charset.StandardCharsets;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.protocol.concepts.KeyMapping;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev200120.odl.bmp.monitors.bmp.monitor.config.MonitoredRouter;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key;
18 public final class KeyConstructorUtil {
19 private KeyConstructorUtil() {
23 public static KeyMapping constructKeys(final List<MonitoredRouter> mrs) {
24 final KeyMapping ret = KeyMapping.getKeyMapping();
26 mrs.stream().filter(Objects::nonNull).filter(KeyConstructorUtil::isNotNullorEmpty)
28 final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
29 ret.put(IetfInetUtil.INSTANCE.inetAddressForNoZone(mr.getAddress()),
30 rfc2385KeyPassword.getValue().getBytes(StandardCharsets.US_ASCII));
37 private static boolean isNotNullorEmpty(final MonitoredRouter mr) {
38 final Rfc2385Key password = mr.getPassword();
39 return password != null && !password.getValue().isEmpty();