2 * Copyright (c) 2013 Contextream, Inc. 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
9 package org.opendaylight.lispflowmapping.implementation.lisp;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.lispflowmapping.implementation.authentication.LispAuthenticationUtil;
15 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
16 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingEntry;
17 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceKey;
18 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceNoMaskKey;
19 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
20 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
21 import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
22 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
23 import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
24 import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
25 import org.opendaylight.lispflowmapping.type.lisp.address.IMaskable;
26 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class MapServer implements IMapServer {
32 protected static final Logger logger = LoggerFactory.getLogger(MapServer.class);
34 public MapServer(ILispDAO dao) {
38 public MapNotify handleMapRegister(MapRegister mapRegister) {
40 logger.warn("handleMapRegister called while dao is uninitialized");
43 if (!LispAuthenticationUtil.validate(mapRegister)) {
44 logger.debug("Authentication failed");
47 EidToLocatorRecord eidRecord = mapRegister.getEidToLocatorRecords().get(0);
48 List<MappingEntry<?>> rlocs = new ArrayList<ILispDAO.MappingEntry<?>>();
49 rlocs.add(new MappingEntry<Integer>("NumRLOCs", eidRecord.getLocators().size()));
51 for (LocatorRecord locatorRecord : eidRecord.getLocators()) {
52 rlocs.add(new MappingEntry<MappingServiceValue>("RLOC" + (i++), new MappingServiceValue(locatorRecord, eidRecord.getRecordTtl())));
54 if (eidRecord.getPrefix() instanceof IMaskable && eidRecord.getMaskLength() > 0 && eidRecord.getMaskLength() < ((IMaskable)eidRecord.getPrefix()).getMaxMask()) {
55 ((IMaskable)eidRecord.getPrefix()).normalize(eidRecord.getMaskLength());
56 dao.put(new MappingServiceKey(eidRecord.getPrefix(), (byte)eidRecord.getMaskLength()), rlocs.toArray(new MappingEntry[rlocs.size()]));
58 dao.put(new MappingServiceNoMaskKey(eidRecord.getPrefix()), rlocs.toArray(new MappingEntry[rlocs.size()]));
61 MapNotify mapNotify = null;
62 if (mapRegister.isWantMapNotify()) {
63 logger.trace("MapRegister wants MapNotify");
64 mapNotify = new MapNotify();
65 mapNotify.setFromMapRegister(mapRegister);
66 mapNotify.setAuthenticationData(LispAuthenticationUtil.getAuthenticationData(mapNotify));
71 public String getAuthenticationKey(LispAddress address, int maskLen) {
75 public boolean removeAuthenticationKey(LispAddress address, int maskLen) {
79 public boolean addAuthenticationKey(LispAddress address, int maskLen, String key) {