2 * Copyright (c) 2017 Red Hat, 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.netvirt.natservice.internal;
10 import java.math.BigInteger;
11 import java.util.List;
12 import java.util.concurrent.CopyOnWriteArrayList;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.genius.mdsalutil.NwConstants;
16 import org.opendaylight.netvirt.natservice.api.SnatServiceListener;
17 import org.opendaylight.netvirt.natservice.api.SnatServiceManager;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 public class SnatServiceManagerImpl implements SnatServiceManager {
25 private static final Logger LOG = LoggerFactory.getLogger(SnatServiceManagerImpl.class);
27 private final List<SnatServiceListener> snatServiceListeners = new CopyOnWriteArrayList<>();
30 public SnatServiceManagerImpl(final SnatServiceImplFactory factory) {
31 AbstractSnatService flatVlaSnatServiceImpl = factory.createFlatVlanSnatServiceImpl();
32 if (flatVlaSnatServiceImpl != null) {
33 addNatServiceListener(flatVlaSnatServiceImpl);
35 AbstractSnatService vxlanGreSnatServiceImpl = factory.createVxlanGreSnatServiceImpl();
36 if (vxlanGreSnatServiceImpl != null) {
37 addNatServiceListener(vxlanGreSnatServiceImpl);
42 public void addNatServiceListener(SnatServiceListener natServiceListner) {
43 snatServiceListeners.add(natServiceListner);
47 public void removeNatServiceListener(SnatServiceListener natServiceListner) {
48 snatServiceListeners.remove(natServiceListner);
52 public void notify(Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action) {
53 for (SnatServiceListener snatServiceListener : snatServiceListeners) {
54 boolean result = false;
56 case SNAT_ALL_SWITCH_ENBL:
57 result = snatServiceListener.handleSnatAllSwitch(router, primarySwitchId, NwConstants.ADD_FLOW);
60 case SNAT_ALL_SWITCH_DISBL:
61 result = snatServiceListener.handleSnatAllSwitch(router, primarySwitchId, NwConstants.DEL_FLOW);
64 case SNAT_ROUTER_ENBL:
65 result = snatServiceListener.handleSnat(router, primarySwitchId, dpnId, NwConstants.ADD_FLOW);
68 case SNAT_ROUTER_DISBL:
69 result = snatServiceListener.handleSnat(router, primarySwitchId, dpnId, NwConstants.DEL_FLOW);
77 LOG.debug("notify : Nat action {} invoking listener {} succeeded", action,
78 snatServiceListener.getClass().getName());
80 LOG.warn("notify : Nat action {} invoking listener {} failed",
81 action, snatServiceListener.getClass().getName());