456333f9ff957e536a8b96ebc19f0e32c79985b8
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / config / PCEPTopologyProviderUtil.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.bgpcep.pcep.topology.provider.config;
9
10 import java.nio.charset.StandardCharsets;
11 import java.util.List;
12 import org.opendaylight.controller.config.yang.pcep.topology.provider.Client;
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.controller.rfc2385.cfg.rev160324.Rfc2385Key;
16
17 public final class PCEPTopologyProviderUtil {
18     private PCEPTopologyProviderUtil() {
19         throw new UnsupportedOperationException();
20     }
21
22     public static KeyMapping contructKeys(final List<Client> clients) {
23         final KeyMapping ret = KeyMapping.getKeyMapping();
24
25         if (clients != null) {
26             clients.stream().filter(client -> client != null && client.getPassword() != null &&
27                 !client.getPassword().getValue().isEmpty())
28                 .forEach(mr -> {
29                     final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
30                     ret.put(IetfInetUtil.INSTANCE.inetAddressFor(mr.getAddress()),
31                         rfc2385KeyPassword.getValue().getBytes(StandardCharsets.US_ASCII));
32                 });
33         }
34         return ret;
35     }
36 }