2 * Copyright (c) 2015 Cisco Systems, 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
8 package org.opendaylight.groupbasedpolicy.neutron.ovsdb.util;
10 import static org.opendaylight.groupbasedpolicy.util.DataStoreHelper.readFromDs;
11 import static org.opendaylight.groupbasedpolicy.util.IidFactory.endpointIid;
13 import com.google.common.base.Optional;
14 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
15 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
18 import org.opendaylight.groupbasedpolicy.util.IidFactory;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 public final class EndpointHelper {
29 private EndpointHelper() {
33 * Look up the {@link Endpoint} from the Endpoint Registry.
35 * @param epKey The {@link EndpointKey} to look up
36 * @param transaction The {@link ReadOnlyTransaction}
37 * @return The corresponding {@link Endpoint}, null if not found
39 public static Endpoint lookupEndpoint(EndpointKey epKey, ReadOnlyTransaction transaction) {
41 Optional<Endpoint> optionalEp =
42 readFromDs(LogicalDatastoreType.OPERATIONAL, endpointIid(epKey.getL2Context(), epKey.getMacAddress()),
44 if (optionalEp.isPresent()) {
45 return optionalEp.get();
51 * Updates an {@link Endpoint} location based on OVSDB Termination point notification.
52 * Note this updates the datastore directly. It does not use the Endpoint RPC, as this has
53 * unfortunate side-effects on EndpointL3 augmentations.
55 * @param endpoint the network endpoint
56 * @param nodeIdString the string representation of the inventory NodeId
57 * @param nodeConnectorIdString the string representation of the inventory NodeConnectorId
58 * @param rwTx a reference to ReadWriteTransaction object
60 public static void updateEndpointWithLocation(Endpoint endpoint, String nodeIdString, String nodeConnectorIdString,
61 ReadWriteTransaction rwTx) {
62 NodeId invNodeId = new NodeId(nodeIdString);
63 NodeConnectorId ncId = new NodeConnectorId(nodeConnectorIdString);
64 OfOverlayContext newOfOverlayCtx =
65 new OfOverlayContextBuilder().setNodeId(invNodeId).setNodeConnectorId(ncId).build();
66 rwTx.merge(LogicalDatastoreType.OPERATIONAL,
67 IidFactory.endpointIid(endpoint.getKey()).augmentation(OfOverlayContext.class), newOfOverlayCtx);
68 DataStoreHelper.submitToDs(rwTx);
71 public static void updateEndpointRemoveLocation(Endpoint endpoint, ReadWriteTransaction rwTx) {
72 EndpointBuilder epBuilder = new EndpointBuilder(endpoint);
73 Endpoint newEp = epBuilder.build();
74 epBuilder.removeAugmentation(OfOverlayContext.class);
75 rwTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.endpointIid(newEp.getL2Context(), newEp.getMacAddress()),
77 DataStoreHelper.submitToDs(rwTx);